Plotting and coding problems

Hello, I'm currently creating a code in which it involves a trial and error wherein when abs(Vc-Va) is less than 0.0001 then Vc=V if not then Vc=Va. then I will plot the V (outcome from loop) vs T (from 300-500 with increment of 0.6) and Z(outcome of loop) Vs T.
I'm having a hard time setting up the plot as it shows no graphing
T = 300:0.6:500;
w = 0.224;
Tc = 304.2;
Pc = 73.83;
k = 0.37464+(1.54226*w)-((0.26992)*(w^2));
b = 0.07780*((R*Tc)/Pc);
e = 1 - sqrt(2);
s = 1 + sqrt(2);
for i = 350:0.5:500
Tr = i/Tc;
al = (1+k*(1-(Tr^(1/2))))^2;
a = 0.45724*(((R^2)*(Tc^2)*al)/Pc);
Va = (R*(i))/P;
Vc = ((R*(i))/P) + b - (a/P)*((Va-b)/((Va+e*b)*(Va+s*b)));
Ab = abs((Vc-Va)/Vc);
while (Ab>0.001)
Va = Vc;
end
V = Vc
Z = ((P*V)/(R*i))
end
x = T';
y = V;
plot(x, y),

回答(1 个)

More like this perhaps:
T = 300:0.5:500;
w = 0.224;
Tc = 304.2;
Pc = 73.83;
k = 0.37464+(1.54226*w)-((0.26992)*(w^2));
R = 1; %%% You haven't defined R and P, so I've used arbitrary values
P = 10;
b = 0.07780*((R*Tc)/Pc);
e = 1 - sqrt(2);
s = 1 + sqrt(2);
for i = 1:numel(T)
Tr = T(i)/Tc;
al = (1+k*(1-(Tr^(1/2))))^2;
a = 0.45724*(((R^2)*(Tc^2)*al)/Pc);
Va = (R*(T(i)))/P;
Vc = ((R*(T(i)))/P) + b - (a/P)*((Va-b)/((Va+e*b)*(Va+s*b)));
Ab = abs((Vc-Va)/Vc);
if (Ab<0.0001)
Vc = Va;
end
V(i) = Vc;
Z(i) = ((P*V(i))/(R*T(i)));
end
subplot(2,1,1)
plot(T, V)
xlabel('T'),ylabel('V')
subplot(2,1,2)
plot(T, Z)
xlabel('T'),ylabel('Z')

类别

帮助中心File Exchange 中查找有关 Data Type Conversion 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by