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

조회 수: 2 (최근 30일)
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 CenterFile Exchange에서 Numerical Integration and Differentiation에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by