MATLAB ploting graph incorrectly, different from same code in Python.

I'm beggining to learn MATLAB.
I got the following code, but the graph doesn't match the data points when putting the P values manually.
%Pressure
P = 0:1/100:14;
%Parameters Pb
C = 0.55;
alpha = 28.9;
Ba = 0.44;
B = 43.7;
T = 300;
Vr = (1-3*C*alpha*(300-T))*(((P*Ba/B)+1).^-(1/Ba));
K = 2091*(Vr).^0.87;
Theta = 86*((Vr).^-((2.629*(Vr).^(1.2))));
%Resistivity
r = (K*T/(4*(Theta).^2))*(1-(1/18)*(Theta/T).^2+(1/480)*(Theta/T).^4);
r0 = (2091*T/(4*(86).^2))*(1-(1/18)*(86/T).^2+(1/480)*(86/T).^4);
plot(P,r/r0)
I wrote the same code for python and it ploted correctly
from pylab import plot, show, xlabel, ylabel, title
from numpy import linspace
#Pressure
P = linspace(0, 14, 100)
#Parameters Pb
C = 0.55
alpha = 28.9
Ba = 0.44
B = 43.7
T = 300
Vr = (1-3*C*alpha*(300-T))*(((P*Ba/B)+1)**-(1/Ba))
K = 2091*(Vr)**0.87
Theta = 86*((Vr)**-((2.629*(Vr)**(1.2))))
#Resistivity
r = (K*T/(4*(Theta)**2))*(1-(1/18)*(Theta/T)**2+(1/480)*(Theta/T)**4)
r0 = (2091*T/(4*(86)**2))*(1-(1/18)*(86/T)**2+(1/480)*(86/T)**4)
plot(P, r/r0)
xlabel('P(GPa)')
ylabel('R(P)/R(P0)')
title('Pb')
show()
What is wrong with my MATLAB code?

 采纳的回答

In your definition of r, you missed a couple spots that required array operations instead of matrix operations:
%Pressure
P = 0:1/100:14;
P0 = 0.000101325;
%Parameters Pb
C = 0.55;
alpha = 28.9;
Ba = 0.44;
B = 43.7;
T = 300;
Vr = (1-3*C*alpha*(300-T))*(((P*Ba/B)+1).^-(1/Ba));
K = 2091*(Vr).^0.87;
Theta = 86*((Vr).^-((2.629*(Vr).^(1.2))));
%Resistivity
r = (K*T./(4*(Theta).^2)).*(1-(1/18).*(Theta/T).^2+(1/480).*(Theta/T).^4);
r0 = (2091*T/(4*(86).^2))*(1-(1/18)*(86/T).^2+(1/480)*(86/T).^4);
plot(P,r/r0)

更多回答(0 个)

类别

在 帮助中心 和 File Exchange 中查找有关 Troubleshooting in Polyspace Products for Ada 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by