Plot doesn't show anything
Mostrar comentarios más antiguos
Hello everyone, I am trying to make the following code work where I want to plot the variables fi and P together for each T value. I think I am doing something wrong regarding the "for" loop but I can't seem to solve it. I would appreciate your help.
clear,clc,clf,
R = 83.1446;
b = 29;
i = 200:10:900
for T = i + 273.15;
d = (-8374 + (19.437*T) - (8.148*0.001*T.^2))*10^6;
c = (290.78 - (0.30276*T) + (1.4774*0.0001*T.^2))*10^6;
e = (76600 - (133.9*T) + (0.1071*T.^2))*10^6;
for i =20:1:100;
v=i;
y = b./(4*v);
a = c + d./v + e./(v.^2);
P = (R*T.*(1 + y + y.^2 - y.^3))./(v.*(1-y).^3)- a./(sqrt(T)*v.*(v+b));
Z = (1+y+y.^2-y.^3)./((1-y).^3) - a./(R*T^1.5.*(v+b));
lnf =(8*y-9*y.^2+3*y.^3)./((1-y).^3)- log(Z)- c./(R*T^1.5.*(v+b))-d./(R*T^1.5.*v.*(v+b))
f=exp(lnf);
fi = f.*P
plot(P,fi)
drawnow
hold on
end
end
hold off
2 comentarios
Geoff Hayes
el 16 de Mzo. de 2020
Dimitris - when I run your code, I do see the axes being updated with "something" (though I don't know if it is correct or not). I do wonder about your loops though. You assign i to be an array
i = 200:10:900
which you iterate over (?) in the outer loop as
for T = i + 273.15;
Is this what you want? And then in your inner for loop, you re-use i as the step variable
for i =20:1:100;
v = i;
I recommend that you use another variable so as not to conflict with the array that you've already created.
Dimitris Moutzouris
el 16 de Mzo. de 2020
Respuesta aceptada
Más respuestas (1)
Mario Malic
el 16 de Mzo. de 2020
Editada: Mario Malic
el 16 de Mzo. de 2020
clear,clc,clf,
R = 83.1446;
b = 29;
i = 200:10:900
for T = i + 273.15;
d = (-8374 + (19.437*T) - (8.148*0.001*T.^2))*10^6;
c = (290.78 - (0.30276*T) + (1.4774*0.0001*T.^2))*10^6;
e = (76600 - (133.9*T) + (0.1071*T.^2))*10^6;
for i =20:1:100;
v=i;
y = b./(4*v);
a = c + d./v + e./(v.^2);
P = (R*T.*(1 + y + y.^2 - y.^3))./(v.*(1-y).^3)- a./(sqrt(T)*v.*(v+b));
Z = (1+y+y.^2-y.^3)./((1-y).^3) - a./(R*T^1.5.*(v+b));
lnf =(8*y-9*y.^2+3*y.^3)./((1-y).^3)- log(Z)- c./(R*T^1.5.*(v+b))-d./(R*T^1.5.*v.*(v+b))
f=exp(lnf);
fi = f.*P
y_curve(i) = fi; % Obtains values for range of i from 20 to 100 and saves it as array
x_curve(i) = P; % same
end
hold on
plot(x_curve,y_curve)
end
I hope this is what you wanted to get. In your code, you were ploting for each point. So if you want to have curves on your plot like this code provides, improve it (since those two lines are unnecessary) and use it. Otherwise, change your plot line like shown below.
plot(P,fi, '*')
2 comentarios
Dimitris Moutzouris
el 16 de Mzo. de 2020
Mario Malic
el 16 de Mzo. de 2020
plot(P,fi, '*')
This one provided what you wanted, but with valuable insights about loops from Cris, that answer is certainly better than mine.
Categorías
Más información sobre Loops and Conditional Statements en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!