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

10 ビュー (過去 30 日間)
Rafael Pereira Baptista
Rafael Pereira Baptista 2021 年 3 月 18 日
回答済み: the cyclist 2021 年 3 月 18 日
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?

採用された回答

the cyclist
the cyclist 2021 年 3 月 18 日
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 件)

カテゴリ

Help Center および File ExchangeNumerical Integration and Differentiation についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by