I am currently using the onling version of Matlab which was linked to my college licence number. I am trying to run a thermodynamic but I am having trouble with running the XSteam.m function(functions>XSteam.m)provided by matlab; specfically running one of the functions.
  1. What are the 'add-on's' that matlab is referring to?
  2. Does Matlab online have some sort of limit to running the functions?
  3. Can the 'add-on' be added to the online version?
  4. Which add-on can be added to the online version on page...https://www.mathworks.com/store/link/products/student/new?
  5. Doe anybody else have an issue with running the XSteam.m code only in the Matlab ONLINE?
I attached a pdf. copy of all the coding incase anyone would like to try to run the file, I also attached images of the error message I recieved.

답변 (1개)

Walter Roberson
Walter Roberson 2020년 11월 27일

0 개 추천

The line that shows up in your image as line 3552 is really in line 3550 of XSteam.m . You are using a corrupted version of the file -- one in which at least one function statement has had a matching end statement added to it, so MATLAB thinks that it is dealing with nested functions instead of unnested functions.
In the online version, http://matlab.mathworks.com click on HOME in the upper left corner in order to show the Home toolbar. Move about 2/3 of the way to the right on that toolbar and click on Add-Ons and select Get Add-Ons from there. The Add-On Explorer will show up. Ask it to search for xsteam thermodynamic . A small number of search results will show up. Click on the title bar for X Steam, Thermodynamic properties of water and steam. by Magnus Holmgren . The page specific to that will show up. In the upper right for that page, click to install it, and agree to the license terms. The software will install and will be added to your MATLAB path. In particular, the file will be installed to the directory /MATLAB Add-Ons/Collections/X Steam, Thermodynamic properties of water and steam. ... complete with spaces and period.
If you had somehow copied XSteam to MATLAB Online yourself, then I recommend deleting the copy you uploaded.

댓글 수: 12

Joseph Madrigal
Joseph Madrigal 2020년 11월 27일
Got it! My bad, I was just confused on the add-on function I thought it was something else. Another issue question I have with the coding has arisen. Below is an input function to acuire thermal efficiency(nt) values. Part of the assignment is asking me to find multiple thermal effiency values(nt) based on multiple pressure 3(P3) input values. Each Pressure value yields one thermal efficiency value, however, the nt value is based on multiple addition or subtraction values of h based on each individual input P3. All the h values will be affected by P3. The end goal is to acquire a graph similar to the one attached.
%Input Data - from problem statement
P6 = 0.2; %[bar]
T3 = 400; %[C]
P4 = 20; %[bar]
T5 = 400; %[C]
P3 = [40:5:60]; %[bar]
Eta_t = 100/100; %"Turbine isentropic efficiency";
Eta_p = 100/100; %"Pump isentropic efficiency";
%State 1
P1=P6;
P2=P3;
x1=0;% "Sat'd liquid"
h1= XSteam ('hL_p',P1) ;
v1= XSteam ('vL_p', P1);
s1= XSteam ('sL_p',P1) ;
T1= XSteam ('Tsat_p',P1) ;
W_p_s=v1*(P2-P1)*1e2; % "SSSF Steady-State Steady-Flow isentropic pump work assuming constant specific volume" ë1e2: bar to kPaí
W_p=W_p_s/Eta_p ;
%State 2
h2=h1+W_p; % "SSSF First Law for the pump"
v2= XSteam ('v_ph', P2,h2) ;
s2= XSteam ('s_pT',P2,h2) ;
T2= XSteam ('T_ph',P2,h2) ; %"High Pressure Turbine analysis"
%State 3
x3=100;% "Superheated vapor"
h3= XSteam ('h_pT',P3,T3) ;
v3= XSteam ('v_pT',P3,T3) ;
s3= XSteam ('s_pT',P3,T3) ;
%Finding temperature T4 based on h3 and s3, mathematical method is interpolation
T4= XSteam ('T_ps', P4,s3) ;
%State 4
x4=100;% "Superheated vapor"
h4= XSteam ('h_pT',P4,T4) ;
v4=XSteam ('v_pT',P4,T4) ;
s4= s3 ;
%State 5
P5=P4;
x5=100;% "Superheated vapor"
h5= XSteam ('h_pT',P5,T5) ;
v5= XSteam ('v_pT',P5,T5) ;
s5= XSteam ('s_pT',P5,T5) ;
%State 6
%quality(x) at state 6
hg6= XSteam ('hV_p', P6) ;
hf6= XSteam ('hL_p', P6) ;
sg6= XSteam ('sV_p', P6) ;
sf6= XSteam ('sL_p', P6) ;
s6=s5;
x6=(s6-s1)./(sg6-sf6)
h6=(h1) + x6.*(hg6-hf6)
%Work output of high-pressure (first-stage) turbine 1
Wt1=(h3-h4)
%Work output of high-pressure (Second) turbine 2
Wt2=(h5-h6)
%Total turbine work
WtTotal=Wt1+Wt2
%Extra: Work of pump
Wp=(h2-h1)
%Net Work
Wcycle=WtTotal-Wp
%Qin
Qin= (h3-h2)+(h5-h4)
%Qout
Qout= h6-h1
%Total heat
Qtotal=Qin+Qout
%Thermal Efficiency
nt=(Wcycle)./(Qin)
plot(P3,nt), xlabel('P3 First-Stage Turbine Pressure P3 (MPa)'), ylabel('Thermal Efficiency'), title('Thermal Efficiency vs. P3'),
grid on, axis equal
Walter Roberson
Walter Roberson 2020년 11월 28일
Sorry, unfortunately I do not understand about "the nt value is based on multiple addition or subtraction values of h based on each individual input P3" and so I do not understand what is being asked for.
Joseph Madrigal
Joseph Madrigal 2020년 11월 28일
Oops my bad! The addition or subtraction comment in the above statement was redundant on my part because in the code it clearly shows that wt2(line 65), for example, came from the SUBTRACTION of h5 and h6 and Qin(line 77), as another example, is based on the ADDITION of (h3-h2) and (h5-h4) values. Sorry my explanation overcomplicated it. Feel free to let my know if something is not clear
Just as to reemphasize...
In terms of the h values being based or dependent on pressure; it means that if any of the input data in lines 2-6(which include multiple temperature-T and pressure-P inputs) were to change then the enthalpy values searched by the code from lines 15, 31,40 , 47, 53-56, respetively, will get different values of h from the water and steam property tables(or XSteam.m code in this case) dependant on whatever the inputs from lines 1-6 are.Once all the enthalpy values(h) are found then they will be used in the w and q calculations(lines 61-83) which will therefore influence the value of nt(line 86).
Currently...
The problem statement asks for a code that can graph the nt value vs P3 value(line 6). The graph(like the image attached to the above comment) has to have many different nt values with the corresponding with their P3 values which are inputted from the input values on lines 2-6. Each new set of input values(lines 2-6) will each yield nt values but the only thing changing is P3 in this cast.
I am getting the following problem with line 25(shown below). v2 is a value acquird in the same exact way as h2 is acquired so the v2 can be ignored. I think the program is taking the incremental P3(line 6) into consideration as one value instead of many different inputs and that might be why it is refering my to the range of pressure values(p) input has to be. I would like for it to take into consideration one P3 value from the incremental change one at a time which will give one nt value at a time. The error message is shown below. Lmk if that all made sense! I am sorry if its difficult to understand; I dont use Matlab often at all! Please take your time and I appreciate you taking the time to answer my questions!
Operands to the || and && operators must be convertible to logical scalar values.
Error in XSteam>region_ph (line 2869)
if p < 0.000611657 || p > 100
Error in XSteam (line 574)
Region = region_ph(p, h);
Error in Thrmoc1 (line 25)
v2= XSteam ('v_ph', P2,h2) ;
Walter Roberson
Walter Roberson 2020년 11월 28일
It looks like XSteam does not like being passed a vector.
Joseph Madrigal
Joseph Madrigal 2020년 11월 28일
편집: Joseph Madrigal 2020년 11월 28일
The add-on wont let me change any of the values and it wont work if I copy and past the add-on code. Is there a way to make changes to an add-on that I am missing so that I would be able to change some details in that code to allow it to be passed to logical scalar values like it say or is that something I can/would have to do in the input where P3=[40:2:60] in the other code that calls for the individual values based on P3?
Walter Roberson
Walter Roberson 2020년 11월 28일
I do not recommend those approaches. I recommend using arrayfun() instead.
v2 = arrayfun(@(p2) XSteam('v_ph', p2, h2), P2);
Joseph Madrigal
Joseph Madrigal 2020년 11월 28일
Incorrect dimensions for raising a matrix to a power. Check that the matrix is square and the power is a scalar. To perform elementwise matrix powers, use '.^'.
Error in XSteam>T1_ph (line 1580)
T = T + n1(i) * Pi ^ I1(i) * (eta + 1) ^ J1(i);
Error in XSteam (line 577)
Out = fromSIunit_v(v1_pT(p, T1_ph(p, h)));
Error in Thrmoc1>@(P2)XSteam('v_ph',P2,h2) (line 25)
v2= arrayfun(@(P2) XSteam('v_ph',P2,h2), P2) ;
Error in Thrmoc1 (line 25)
v2= arrayfun(@(P2) XSteam('v_ph',P2,h2), P2) ;
Walter Roberson
Walter Roberson 2020년 11월 28일
v2 = arrayfun(@(H2) XSteam('v_ph', P2, H2), h2);
Joseph Madrigal
Joseph Madrigal 2020년 11월 29일
It seems like if it keeps referring back to the coding in XSteam.m than that might be as far as it will go.
Operands to the || and && operators must be convertible to logical scalar values.
Error in XSteam>region_ph (line 2869)
if p < 0.000611657 || p > 100
Error in XSteam (line 574)
Region = region_ph(p, h);
Error in Thrmoc1>@(h2)XSteam('v_ph',P2,h2) (line 25)
v2= arrayfun(@(h2) XSteam('v_ph', P2, h2), h2) ;
Error in Thrmoc1 (line 25)
v2= arrayfun(@(h2) XSteam('v_ph', P2, h2), h2) ;
Walter Roberson
Walter Roberson 2020년 11월 29일
P3 = [40:5:60]; %[bar]
okay so P3 is a vector.
P2=P3;
so P2 must be a vector as well.
W_p_s=v1*(P2-P1)*1e2; % "SSSF Steady-State Steady-Flow isentropic pump work assuming constant specific volume" ë1e2: bar to kPaí
W_p_s uses P2 and P2 is a vector so W_p_s must be a vector as well.
W_p=W_p_s/Eta_p ;
Eta_p is a scalar, and W_p_s is a vector, so W_p is a vector.
h1= XSteam ('hL_p',P1) ;
I do not know what size XSteam returns, but you would have had problems before the point you are at now if XSteam does not return a scalar.
h2=h1+W_p; % "SSSF First Law for the pump"
W_p is a vector, and h1 is presumed to be a scalar, so h2 is a vector.
v2= XSteam ('v_ph', P2,h2) ;
P2 and h2 are both vectors, and they are the same size of vector. Are you asking to fetch v_ph for each P2 in combination with each h2, or are you asking to fetch values for corresponding pairs of inputs?
%assuming corresponding
v2 = arrayfun(@(thisP2, thish2) XSteam('v_ph', thisP2, thish2), P2, h2);
Walter Roberson
Walter Roberson 2020년 11월 29일
I had a look at the XSteam code. It would be a lot of rewriting to vectorize it by any way other than internal use of arrayfun.
Joseph Madrigal
Joseph Madrigal 2020년 11월 29일
I am asking to fetch values for corresponding pairs of inputs. And yea, thats what it was looking like at this point honestly!

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Mathematics에 대해 자세히 알아보기

질문:

2020년 11월 27일

댓글:

2020년 11월 29일

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by