© 2024 Jasper van Baten, AmsterCHEM

Matlab script

The calculations performed by the unit operations are defined by Matlab script. You can enter the script by editing the unit operation, and select Script on the Matlab tab.

The Matlab script is run in a fresh Matlab environment, in which useful global variables and functions are predefined. The script should:

DOs and DON'Ts

Do

Don't

Testing

To test your Matlab input, make sure the ports are connected. Then, while writing the script, click the Test button for feedback.

Editing

You can edit the script in the text box provided on the Script tab, or you can click the Edit button. The Edit button will open the external editor. The Matlab Unit Operation dialog will block until this editor has been closed.

The default editor is medit.exe in the Matlab program folder (or notepad.exe if medit.exe cannot be found). You can select a different text editor by holding down Ctrl while clicking on the Edit button.

Example

Example script for a simple adiabatic mixer with two feeds and one product:

f1=getFeedProp(1,'flow')
f2=getFeedProp(2,'flow')
h1=getFeedProp(1,'enthalpy')
h2=getFeedProp(2,'enthalpy')
p1=getFeedProp(1,'pressure')
p2=getFeedProp(2,'pressure')
p=min(p1,p2)
f=f1+f2
h=(h1*f1+h2*f2)/f
totF=sum(f)
setProduct(1,totF,f/totF,'pressure',p,'enthalpy',h)

(This particular script does not take into account that the total flow may be zero; it will fail in this case).

INDEX
Acknowledgements
Additional files
Boolean parameters
Calculation
compNames
Dimensionality
Disclaimer
DOs and DONTs
Error trapping
Example
Feeds
Files
Formulas
Function reference
getAggregationState
getAggregationStateName
getCompoundConstant
getEquilibrium
getEquilibriumProperty
getFeedEquilibrium
getFeedProp
getNumberOfFeeds
getNumberOfProducts
getParameter
getPDependentProperty
getPropertyUnitOfMeasure
getSinglePhaseProperty
getTDependentProperty
getTwoPhaseProperty
getUnitOperationName
Global variables
Integer parameters
License
Loading models
logMessage
M files
Model files
nComp
nPhase
Parameters
phaseAggregationStates
phaseNames
Products
Real parameters
Reports
Requirements
Saving models
setParameter
setProduct
setReport
String parameters
SUM files
Welcome
CONTENT
 Welcome
 Feed and product ports
 Parameters
 Reports
 Matlab Calculation Script
 Additional files
 Global variables
 Function reference
 Saving and loading models
 Persistence in AspenPlus
 License and disclaimer