Hello,
I am trying to extract data from Xsteam.I am trying to retrive data with respect to temperature. the code is as follows.
p = 10;
a = 1000;
b = 0.1;
rho_s = zeros(1,((a-1)/b));
L = length(rho_s);
for i = 1:L
T(i)= 1+b*i;
rho_s(i) =XSteam('rho_pT', p, T(i));
drho_s_dT = (rho_s(i+1)-rho_s(i))/(T(i+1)-T(i));
end
when i run this code I am getting an error as "Index exceeds the number of array elements". Can some one check and help me how can I do this.

6 件のコメント

John Marriott
John Marriott 2020 年 5 月 27 日
Hi
on this line - drho_s_dT = (rho_s(i+1)-rho_s(i))/(T(i+1)-T(i)); you are trying to take the ith+1 element of rho_s without having created it first. E.g on the first iteration you are trying to subtract the first value in rho_s from the value generated in the second iteration of the loop but this hasnt been created yet
perhaps instead you could use
for i = 1:length(rho_s)
T(i)= 1+b*i;
rho_s(i) =XSteam('rho_pT', p, T(i));
if i >=2
drho_s_dT(i) = (rho_s(i)-rho_s(i-1))/(T(i)-T(i-1));
end
end
also i added a loop index to the variable drho_s_dT becasue it didnt make sense doing pressumably you want to save each time its performing this calculation or else what is the point?
Rik
Rik 2020 年 5 月 27 日
Do you mean the XSteam function published here?
vishnuvardhan naidu tanga
vishnuvardhan naidu tanga 2020 年 5 月 27 日
編集済み: Rik 2020 年 5 月 27 日
@Rik yes the Xsteam data mention there
@John Marriott Thank you so much for the clarification I will have a look into it.
vishnuvardhan naidu tanga
vishnuvardhan naidu tanga 2020 年 5 月 27 日
I have run the code. It works but after 3729 the column turns to NaN. can you please help me in that.
John Marriott
John Marriott 2020 年 5 月 27 日
Ok - the columns of which variable outputs NaN?- it doesnt return NaN when I run it - are you using the XSteam function posted by Rik?
vishnuvardhan naidu tanga
vishnuvardhan naidu tanga 2020 年 5 月 27 日
編集済み: vishnuvardhan naidu tanga 2020 年 5 月 27 日
yes and I have changed the code a little. I have consider only temperature instead of pressure.
a = 1000;
b = 0.1;
rho_s = zeros(1,((a-1)/b));
L = length(rho_s);
for i = 1:L
T(i)= 1+b*i;
rho_s(i) =XSteam('rhoV_T', T(i));
if i >=2
drho_s_dT(i) = (rho_s(i)-rho_s(i-1))/(T(i)-T(i-1));
end
end

サインインしてコメントする。

 採用された回答

Ameer Hamza
Ameer Hamza 2020 年 5 月 27 日

0 投票

It seems that you are trying to find a derivative of rho_s w.r.t. T, you can use gradient() function
p = 10;
a = 1000;
b = 0.1;
rho_s = zeros(1,((a-1)/b));
L = length(rho_s);
T = zeros(1, L);
for i = 1:L
T(i)= 1+b*i;
rho_s(i) =XSteam('rho_pT', p, T(i));
end
drho_s_dT = gradient(rho_s, T);

2 件のコメント

vishnuvardhan naidu tanga
vishnuvardhan naidu tanga 2020 年 5 月 27 日
編集済み: vishnuvardhan naidu tanga 2020 年 5 月 27 日
Thank you for the suggestion it works. But when i consider interms of temperature only again from 3729 the column turns to NaN. is there any suggestion for that. the code is
a = 1000;
b = 0.1;
rho_s = zeros(1,((a-1)/b));
L = length(rho_s);
for i = 1:L
T(i)= 1+b*i;
rho_s(i) = XSteam('rhoV_T', T(i));
end
drho_s_dT = gradient(rho_s, T);
Ameer Hamza
Ameer Hamza 2020 年 5 月 27 日
This is probably caused by the thermodynamical equation implemented in XSteam() and not a MATLAB specific issue. You will need to understand the equations and the implementation of this function to see what might be going wrong. Also, you aren't passing variable 'p' in your code, which might be causing the issue.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeMatrix Indexing についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by