www.x-eng.com, Steam and water properties for Matlab based on the "International Association for Properties of Water and Steam Industrial Formulation 1997 (IAPWS IF-97). A full implementation of the IF-97 standard that provides very accurate steam and water properties in ranges from 0-1000 bar and 0-2000°C. Provided thermodynamic properties are:
Specific internal energy
Specific isobaric heat capacity
Specific isochoric heat capacity
Speed of sound
All properties can be calculated with the inputs, p and T known, p and h known, h and s known and some with pressure and density known. X Steam are a full implementation of the IF-97 formulation including all regions and all backward functions for good calculation speed. The code are speed optimized with pressure and enthalpy as inputs for dynamic simulations.
XSteam('h_pt',1,20) return the enthalpy of water at 1 bar and 20 degC. 84.0118 kJ/kg
XSteam('rho_ph',1,3000) return the density of steam at 1 bar and 3000 kJ/kg. 0.4056 kg/m3
XSteam('w_pt',1,20) returns the speed of sound at 1 bar and 20 deg C. 1483.4 m/s
XSteam('tSat_p',1) returns the saturation temperature at 1 bar. 99.6059 deg C
The X Steam Tables are the perfect tool both for replacing paper tables and for advanced calculations. The X Steam tables are open source and free of charge.
The X Steam tables are also available as MS Excel scripts, OOo Sripts, Dynamic Link Libary .DLL. Please visit www.x-eng.com.
New version 2.5
Magnus Holmgren (2020). X Steam, Thermodynamic properties of water and steam. (https://www.mathworks.com/matlabcentral/fileexchange/9817-x-steam-thermodynamic-properties-of-water-and-steam), MATLAB Central File Exchange. Retrieved .
Firstly: I share the opinion of most people here: amazing code, very useful for chemical engineers. I am very grateful for having the opportunity to use it.
Secondly: I tried calculating the enthalpy as a function of pressure and entropy, but the results do not match my expectations.
I expect the enthalpy to go to a certain, almost constant value as I'm lowering the pressure at constant entropy, which p-h diagrams suggest, but instead the enthalpy decreases exponentially when going to lower pressures. I believe this isn't the right behaviour
The code is great, however for the XSteamUS package, the thermal conductivity does not convert correctly at high pressures i.e. 1000-2250 psia. Any chance there can be a fix for this? Thanks!
This code is really brilliant, If it could incorporate thermal expansion coefficient, it would be a complete package!
While executing the code, none of the functions are working.
Is there any modification to be done?
It would be good to go from Temp and entropy straight to Enthalpy
This code is extremely useful for getting desired thermodynamic properties of water and steam. However, it is important to understand the limitations of the code in order to use it correctly. These limitations include understanding the units used and the parameter ranges available in the code. The code does not have enough commentary to make these important limitations clear. Currently, if an input parameter is outside the allowable range, ‘NaN’ is the output. Giving a reasoning for the error would allow users have a smoother process when using the code.If there were error messages explaining why certain inputs cannot be taken, the code would be more user friendly. Having units shown in each output would also enhance user-friendliness. The lack of commentary explaining how the code works and was developed is also noticed. Including commentary would give more insight into why certain things were used to find desired outputs. The code could also be more helpful by giving an understanding of how certain properties change as a function of another property. To do this, plots could be implemented. For these reasons, the rating is a 4 out of 5 stars.
This code is so valuable in finding thermodynamic properties of water without having to sift through loads of tables, and I would like to thank the author for creating this code! Very useful for Chemical Engineers! The different functions allow us to find thermodynamic properties using various inputs such as temperature, pressure, enthalpy, and entropy. There are two significant improvements that could be made to make XSteam more user friendly. First, it would be useful to have the units of our inputs and outputs of each specific function without having to scroll all the way to the top or the bottom. Second, it would be nice to see where our calculated value lies compared to a variety of different inputs, so possibly integrating an overall plot would create a much more exciting interface for the user.
This code is a achievement for the detail and comprehensiveness that went into constructing it in a way that provides so many options for inputs and outputs. There are some minor issues with the code with regards to user friendliness. The outputs for the code do not display the units of the desired property, this could be remedied by adding display functions with the corresponding units for each case. Also in section 2.1 the function for T1_prho uses the bisection method to calculate the output when more accurate methods such as fsolve could be implemented. Overall, the code functions well but takes some practice to learn the correct formatting and nomenclature.
This code is so valuable in finding thermodynamic properties of water without having to sift through loads of tables and I would like to thank the author for creating this code! The different functions allow us to find thermodynamic properties using various inputs such as temperature, pressure, enthalpy, entropy, etc . There are two significant improvements that could be made in order to make XSteam more user friendly. First is to include lines of code that display the units of the output in XSteam. Even though the file exchange includes a PDF with the output units, it would be more user friendly to include the units with the given values. Second is that under the section 1.14 Kappa, there is no actual code to find Kappa and simply represents a blank section.
First, I would like to thank the author for their significant contribution.
Secondly, I would like to point out that the calculation for Thermal Conductivity (tc) is incorrect for the English system units (XSteamUS.m). I believe this is due to a premature conversion from metric. The specific volume is converted from metric to English, then the final output is converted from metric to English. Consequently, the "fromSIunit_tc" code utilizes an English based density; instead of the necessary metric. The fix is to comment out the "v = toSIunit_v(v);" lines in the 1.16 Thermal Conductivity section. Please review this to verify.
This Error happened when I want to run the code
Undefined function 'call' for input arguments of type 'char'.
Error in Untitled (line 2)
who knows why?
Please let me know my mistake
Viscosity function does not work in 2-phase region. I am trying to calculate vapor viscosity at 29 kPa and getting NaN.
We rated the code ⅗ deducting points mainly because of user-friendliness. There was a lack of explanation over the code development and there was not a sufficient number of comments to explain what the code did. Also, the output did not include units, so whichever value you wanted to find, you would have to look up the units using a separate document given in the zip file. There should have been an explanation at the start of the code about what mixtures this code is valid or not valid for. Overall, the code is workable, but the follow through was a little rough.
Very well done function, however I have noticed several small issues. At certain temperatures and pressures, the function will return nonphysical values (or more often, NaN). For example, running XSteam("h_pT", 900, 900) returns NaN despite said values being within the given working range of the function. This is most likely an issue with the IAPWS formulation (checking other online calculators at the same conditions return similarly nonphysical results), however it would be nice to have a built-in check for nonphysical results that raises an error if a problematic pair of values is given.
Thanks for a great job. But it is more convenient if you can convert it into the complete form of the SI system, where Pressure measured in Pascal (Pa) and Temperature is in Kelvin (K).
interesting program, but i found it a bit limited because of the number of input arguments for each function
Is there any one can help me to get the liquid Viscosity? it seems only calculate steam Viscosity!
hi everyone, I have a problem using Xsteam for function call. X steam works fine when I use in matlab.m alone. But when I insert the matlab.m in simulink using user define matlab function, it fail to use function call of Xsteam to calculate.
X Steam, Thermodynamic properties of water and steam is an extremely useful function which allows one to compute many helpful thermodynamic quantities as a functions of specified parameters like pressure, enthalpy, entropy, and volume fractions. The code is robust and can return values from a wide range of initial inputs making this code useful in a many engineering design and analysis problems. This code has some minor user friendliness issues because it doesn't specify units or when the underlying equations are valid in each regions (It just returns NAN). There is insufficient commenting in the source code, so it was difficult to understand some of the developments. There are inconsistencies in the tolerance for the basic parameter calculation with while loops resulting in errors that are difficult to quantify. Errors are tabulated in an attached document, but there is not an overall significance level given. The code could be clearer and structured more logically to help users, but overall it is a good tool to calculate thermodynamic properties of water and steam.
Is there any Fluid-Gas table available? I am not dealing with pure water, and my system contains, sometime air, sometime steam and sometimes both. I would like to know if it is possible to have a Fluid-gas table?
When I run the program it says
>> XSteam(fun, In1, In2)
Undefined function or variable 'fun'.
What can be the problem?
I am new here but wishing to enjoy your service. However i am getting different value compare to what i have on hard copies of steam table or what have been stated above.
1) XSteam('TSat_p',1) =101.6943 instead of 99.6 as we all know?
2) XSteam('rho_ph',1,3000) =4.3661e-04 instead of 0.4056 kg/m3
3)XSteam('h_pt',1,20) = the answer is NaN......
What Could be the reasons? Please help
Please, can this program be extended for calculating thermodynamic properties of ice VII (from 2 to 20GPa) beyond 1000 bar?
The Code works perfectly when I send the Pressure and Temperature as Variables inside a Matlab function.
But when the same function is run by my Simulink Model, I get the Error saying "Expected a scalar. Non-scalars are not supported in IF or WHILE statements, or with logical operators. Instead, use ALL to convert matrix logicals to their scalar equivalents."
Could anyone please help me with this? Even though the Values of Pressure and Temperature are Scalar, I get this error.
My previous problem was solved. Turns out there is a difference in copy pasting an extracted folder and an extracted file into Documents/MATLAB
Great piece of code, extremely useful, can I have question? Can I get speed of sound for liquid-vapor mixture?
The function returns NaN.
Thank you :-)
i find the answer
>>just download the zipfile here and copy its files to matlab folder in documents or any path matlab use on computer
i can write it on matlab directly like
This is extremely helpful. Thank you :)
Good but it doesn't work foe temperatures above 800 C!
Mon. April 11, 2016
When I try to run xsteam.m in r2016a I get the following error about fun
Not enough input arguments.
Error in XSteam (line 221)
welcome help in fixing this error.
fun is undefined word!!
??? Input argument "fun" is undefined.
thank you for this code!
is it possible to use vectors as in1&in2? if I do this, I will get a error message:
'Operands to the || and && operators must be convertible to logical scalar values.'
Is there any way to calculate or determine the Isentropic Expansion Exponent?
I need the density of steam in the T interval 1273 K-1873 K and P 0.1-300 MPa. XSteam provides desnity for T up to 2000 C but for P<100 bar. Any suggestion?
If you are looking for an alternative to XSteam, please consider - http://www.mathworks.com/matlabcentral/fileexchange/35710-iapws-if97-functional-form-with-no-slip - it is vectorized, more current, and documented here: http://mikofski.github.io/IAPWS_IF97/
I wanna know the function Xsteam use as input value SI values, because in the pdf theres is a table with the units but i dont know if they are units of the input or the outputs.
is showing as NaN. Please let me know the reason.
Not only density but all other properties are being shown as NaN
Thank you Magnus for this. I would like to use this with Simulink, however, I'm not able to.. The code I'm using is as follows but I'm getting errors:
function h10 = fcn(t10)
Would appreciate if anyone can help.
You might be able to increase speed for long loops by calling XSteam using arrayfun (http://www.mathworks.com/help/matlab/ref/arrayfun.html) or use IAPWS_IF97 (http://www.mathworks.com/matlabcentral/fileexchange/35710-iapwsif97-functional-form-with-no-slip)
@Daniel Vecchio - you might try NIST Chem WebBook (http://webbook.nist.gov/chemistry/fluid/), EES from the University of Wisconsin (http://fchart.com/ees/), TRNSYS also from Wisconsin (http://sel.me.wisc.edu/trnsys/) or Aspen (http://www.aspentech.com/products/aspen-properties.aspx). Good luck and post your findings to help others.
Hello, Excellent material!.
I'm looking for a similar tool to get the properties of refrigerants.
Do you know if there is something availbale?
To get the help for both XSteam and XSteamUS, you need to open the source and delete the first three lines, or at least the blank lines. MATLAB will only return help using the first connected block of comments, but both XSteam and XSteamUS have a blank line after `%h_prho behöver T_prho för samtliga regioner!!!!` hence that is the only line returned as "help".
Excellent resource, but would be better if vectorized and if it had thermodynamic derivatives for computational modeling.
Open the source, look at lines 23-41, the units for each file are there
%*** Nomenclature ******************************************************************************************
% First the wanted property then a _ then the wanted input properties.
% Example. T_ph is temperature as a function of pressure and enthalpy.
% For a list of valid functions se bellow or XSteam for MS Excel.
% T Temperature (deg C)
% p Pressure (bar)
% h Enthalpy (kJ/kg)
% v Specific volume (m3/kg)
% rho Density
% s Specific entropy
% u Specific internal energy
% Cp Specific isobaric heat capacity
% Cv Specific isochoric heat capacity
% w Speed of sound
% my Viscosity
% tc Thermal Conductivity
% st Surface Tension
% x Vapour fraction
% vx Vapour Volume Fraction
using 'help XSteam' or 'help XSteamUS' does not output the units used:
>> help XSteamUS
h_prho behöver T_prho för samtliga regioner!!!!
>> help XSteam
h_prho behöver T_prho för samtliga regioner!!!!
I found the SI units in the pdf but how do I find out what the imperial units are?
@AntoineTambue "XSteamUS" uses Imperial units, whereas "XSteam" (w/o "US") uses SI or metric units. Type `help XSteam` or `help XSteamUS` to see the units used.
I know this is an oldie but goodie, and I greatly appreciate Magnus Holmgren's work. Therefore I humbly submit IAPWS_IF97.m (http://www.mathworks.com/matlabcentral/fileexchange/35710) which is inspired by XSteam, but completely reworked using IAPWS original to be vectorized and to include derivatives w.r.t. enthalpy and pressure. If you have comments on IAPWS_IF97.m, I would love to hear them. Thanks for your consideration.
Hello, There are two functions XSteam and XSteamUS. What is the difference between the two functions? I have tested the two functions and they give me different answers.
the best tool ever used !
Very good tool!
Excellent to have it condensed in a single .m file.
Excellent work! You have made my life immeasurably easier with this great tool!
A remark Concerning my previous comment:
The code calculates tcL and tcV as it should.
Only the documentation is vice versa.
In 19.7.2006 "X Steam for Matlab.pdf" and in 4.5.2007 "XSteam.m" comment lines 139-142:
%tcL_p Saturated vapour thermal conductivity
%tcV_p Saturated liquid thermal conductivity
%tcL_T Saturated vapour thermal conductivity
%tcV_T Saturated liquid thermal conductivity
%tcL_p Saturated liquid thermal conductivity
%tcV_p Saturated vapour thermal conductivity
%tcL_T Saturated liquid thermal conductivity
%tcV_T Saturated vapour thermal conductivity
, I guess?
Thank you for this thorough implementation with excellent help!
Exactly what I needed, many thanks
I appreciated and used your excell worksheet many years ago (vers. 2.6).
there is a new version, and from where can I get it?
Hello, the program is great, but I need to compute steam and ice values under 0ºC. Can anybody help me PLEASE?
How to use XSteam in Simulink?
Thank you Magnus Holmgren for you outstanding work! Using your work as a inspiration, I completely re-coded all of the IAPWS IF97 (except region 5) and including some of the most recent documentation including thermodynamic derivatives which I needed for some non-linear 2-phase modeling. I have finally posted it here:
It is vectorized and fully tested, according to the test points in IF97 and accompanying documents and the numerous simulations I have performed using it. I hope you find it as useful as I have.
Very awesome, I was working on something similar myself, when i stumbled upon this. Talk about a time saver, I do have one question, in line 2496 Should the program read High_Bound = 2563.59200e+5 instead of High_Bound = 2563.592004+5?? Just curious.
OMG. This program saves me so much time on each thermodynamics homework. Thanks so much!
Solid and precise, thank you.
Awesome...This is exactly what I was looking for.
So many thank for your information?
Thanks a lot!
very good!! thank you very much!
very good!! thank you very much!
Exactly what I needed, many thanks
Just what I need
Comment to review bellow. Temperature lines does off course break at the saturation line on ph diagrams. (However h_pt is not valid for mixtures of steam and water since temperature do not vary with enthalpy in that region. Answer becomes NaN. Temperature can?t be the saturation temp of p since then h is undefined.) I think you mixed up the numbers a little to.
XSteamUS('pSat_t',700) = 3.0928896229137e+03 psia
XSteamUS('hV_t',700) = 9.9063684424454e+02 btu/lb
XSteamUS('hV_p',3.0928896229137e+03) = 9.9063684424454e+02 btu/lb
Very happy to find steam properties as good as this. Saved me from having to create my own again. Only problem is the temperature lines not breaking at the saturation line on ph diagrams (in english units)at higher pressures; sat line at 3097 psia gives 989.2 BTU/Lb versus 981.5 BTU/Lb for 3097 psia and 700F.
On line 1428 ==> err=check();
This is an extraordinary and excellent effort. In particular the ablity to obtain properties as functions P and h, h and s.
However it is not clear how the author has stated that properties can be found upto 2000 degree celcius if they are based on IF 97. These to my knowledge are applicable upto 800 degree celcius only. Students would still require a compact printed steam table that they can carry to a test or examination.An excellent new one called "Engineering Steam Tables"by Ashok Malhotra is now available for the purpose at Amazon.com. (type the title in their search box to locae it)
I NEED HELP.................
Very useful. Author must have had a lot of spare time, 150kb of code isn't a few hours job.
I like this program
very nice piece of work! Well done.
Great program and excellent structure.
Excellent work. Thank you.
Water data that really will save me a lot of work writing tables for interpolation into my program. A really great program!
I have two minor improvements:
- I would like the different functions as separate m files rather than commands.
- I agree with the previous reviewers that it would nice if the functions where vectorized.
However that?s minor problems, the program does what it?s supposed to and it?s simple to use and well structured. The program is worth a five star.
1 star just to balance the author giving himself a 5 star rating. Thanks for the advice Urs!
it's ok - BUT (and this is a big BUT) - in the future, do NOT give your OWN submission(s) a rating of 5/5; some people might get really offended and nasty with this inappropriate behavior
I finally succeded in adding my file and I appriciate all the positive ratings the first day.
I'll consider to vectorize the functions.
The X Steam for MS Excel and the "spiffy figure" is also open source and can be downloaded from www.x-eng.com but I will add them to the ZIP file the next time I update it.
Simple and gives exact accurate results.
If you were to call this inside a long loop, the lack of vectorization might slow things down. However, thats the only reason why I might choose to downrate this at all. The documentation is far above average, so its still a 5 in my book.
really nice result of a project
- extraordinary help (including PDF, to boot)
it would be even nicer
- if it was vectorized
- if the spiffy figure could be reproduced easily (see above)
- if the ...XSteam macros for MS Excel... (as mentioned in the help section) came with the package
but this is just ranting a bit
New version with minor fixes
New release with minor updates.
Update of unit error for function T_ps for mixture of steam and water.
* English Units implemented!!!
Inspired: Ideal Rankine Cycle GUI, IAPWS_IF97, Methane Solubility, Ideal Rankine cycle, Ideal Regenerative Rankine Cycle, Ideal Reheat Rankine Cycle, Ideal Reheat Regenerative Rankine Cycle, Ideal Reheat Regenerative Rankine Cycle with one OPEN, one CLOSED FWH, Ideal Regenerative Rankine Cycle with one OPEN, one CLOSED FWH, Chen correlation wall temperature calculation, Water and Steam Refractive Index, Diagrams of Thermodynamic State of Water, XSteamW - a vectorizing wrapper for XSteam, Medium Model