Solution found by matlab is too big to use

2 views (last 30 days)
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)

Answers (1)

Chunru
Chunru on 17 Nov 2021
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)

Categories

Find more on Thermodynamics and Heat Transfer in Help Center and File Exchange

Products


Release

R2021b

Community Treasure Hunt

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

Start Hunting!