Solution found by matlab is too big to use
1 回表示 (過去 30 日間)
古いコメントを表示
I'm working on a project for my thermodynamics class, and between me and my partner we've found a set of code that works for 4/5 of the equations of state necessary for the report we need to write, but for the peng-robinson equation the same code refuses to work, and gives the error message of "Unable to perform assignment because the size of the left side is 1-by-1 and the size of the right side is 2-by-1."
I know the result I'm looking for is close, I'm just not sure where in the code I can make the 2-by-1 into a 1-by-1.
clear R V v T Tr Tc t P Pc a b w k al i eqn sol
R = 83.14;
P = 200;
T = (300:1000);
Pc = 45.99;
Tc = 190.6;
a = .45724*((R^2*Tc^2)/Pc);
b = .07780*((R*Tc)/Pc);
w = .012;
k = .37464+(1.54226*w)-(.26992*w^2);
i = 1;
V = zeros(1,701);
for t = (300:1000)
syms v
assume (v,'real');
assume (v,'positive');
al = (1+k*(1-(t/Tc).^(1/2))).^2;
eqn = ((R*t)/(v-b))-((a*al)/((v^2)+(2*b*v)-b^2))-P == 0;
sol = double(vpasolve(eqn,v,[1,1e6]));
V(1,i) = sol;
i = i+1;
end
plot(T, V)
回答 (1 件)
Chunru
2021 年 11 月 17 日
There are two solution of the equation. You need to select one. The modified code choose the 1st solution. You can always to test which solution meet your additioal requirement.
R = 83.14;
P = 200;
T = (300:1000);
Pc = 45.99;
Tc = 190.6;
a = .45724*((R^2*Tc^2)/Pc);
b = .07780*((R*Tc)/Pc);
w = .012;
k = .37464+(1.54226*w)-(.26992*w^2);
i = 1;
V = zeros(1,701);
for t = (300:1000)
syms v
assume (v,'real');
assume (v,'positive');
al = (1+k*(1-(t/Tc).^(1/2))).^2;
eqn = ((R*t)/(v-b))-((a*al)/((v^2)+(2*b*v)-b^2))-P == 0;
sol = double(vpasolve(eqn,v,[1,1e6]));
V(1,i) = sol(1); % choose 1st solution
i = i+1;
end
plot(T, V)
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Thermodynamics and Heat Transfer についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!