MATLAB ploting graph incorrectly, different from same code in Python.
Show older comments
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?
Accepted Answer
More Answers (0)
Categories
Find more on Numerical Integration and Differentiation in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!