Plotting a multivariable function

3 vues (au cours des 30 derniers jours)
Sazcl
Sazcl le 30 Oct 2022
Hi, I have a multivariable function as you can see down below. The function works perfect but I have a problem. I need to plot v_cal - v_true when a_ft is equal to 28000. However, when I tried to run the function, MATLAB asks me for v_cal and a_ft values. When I input these values, it plots the v_cal-v_true graph as a constant function. How can I fix this? Thanks in advance.
function v_true=CaltoTrue(a_ft,v_cal)
a=a_ft*0.3048;
b=-0.0065;
R=287.05287;
gr_0=9.80665;
p0=101325;
T0=288.15;
pr=p0*((T0+b*a)/T0)^(-gr_0/(b*R));
T=T0+b*a;
ad=pr/(R*T);
k=1.4;
nu=(k-1)/k;
ad_0=1.225;
v_true=(((((1+(nu*ad_0*(v_cal)^2)/(2*p0))^(1/nu)-1)*p0/pr+1)^nu-1)*(2*pr)/(nu*ad))^(1/2);
if a_ft==28000
v_cal=0:500;
fplot(v_true)
xlabel('V_Cal')
ylabel('V_True')
end
end

Réponse acceptée

KALYAN ACHARJYA
KALYAN ACHARJYA le 30 Oct 2022
Modifié(e) : KALYAN ACHARJYA le 30 Oct 2022
a_ft=28000;
v_cal=0:500;
CaltoTrue(a_ft,v_cal)
ans = 1×501
0 1.5762 3.1524 4.7285 6.3046 7.8806 9.4565 11.0323 12.6079 14.1833 15.7586 17.3336 18.9084 20.4830 22.0573 23.6312 25.2049 26.7782 28.3512 29.9238 31.4960 33.0678 34.6391 36.2100 37.7804 39.3503 40.9197 42.4885 44.0568 45.6245
function v_true=CaltoTrue(a_ft,v_cal)
a=a_ft*0.3048;
b=-0.0065;
R=287.05287;
gr_0=9.80665;
p0=101325;
T0=288.15;
pr=p0*((T0+b*a)/T0)^(-gr_0/(b*R));
T=T0+b*a;
ad=pr/(R*T);
k=1.4;
nu=(k-1)/k;
ad_0=1.225;
temp=nu*ad_0.*(v_cal).^2;
temp2=(1+temp/(2*p0)).^(1/nu)-1;
v_true=(((temp2.*p0/pr+1).^(nu)-1).*(2*pr)/(nu*ad)).^(1/2);
plot(v_true)
grid on;
xlabel('V_Cal')
ylabel('V_True')
end
#Not costant, there is a slight variation, please check the equation, it is more about digging those equations rather than matlab code.
  2 commentaires
Sazcl
Sazcl le 30 Oct 2022
a_ft=28000;
v_cal=0:500;
CaltoTrue(a_ft,v_cal)
ans = 1×501
0 1.5762 3.1524 4.7285 6.3046 7.8806 9.4565 11.0323 12.6079 14.1833 15.7586 17.3336 18.9084 20.4830 22.0573 23.6312 25.2049 26.7782 28.3512 29.9238 31.4960 33.0678 34.6391 36.2100 37.7804 39.3503 40.9197 42.4885 44.0568 45.6245
function v_true=CaltoTrue(a_ft,v_cal)
a=a_ft*0.3048;
b=-0.0065;
R=287.05287;
gr_0=9.80665;
p0=101325;
T0=288.15;
pr=p0*((T0+b*a)/T0)^(-gr_0/(b*R));
T=T0+b*a;
ad=pr/(R*T);
k=1.4;
nu=(k-1)/k;
ad_0=1.225;
temp=nu*ad_0.*(v_cal).^2;
temp2=(1+temp/(2*p0)).^(1/nu)-1;
v_true=(((temp2.*p0/pr+1).^(nu)-1).*(2*pr)/(nu*ad)).^(1/2);
plot(v_true)
grid on;
xlabel('V_Cal')
ylabel('V_True')
end
Thanks a lot, but I don't understand where exactly you wrote the first three lines of code. When I place it above the function, I get this error: Local function name must be different from the script name.
KALYAN ACHARJYA
KALYAN ACHARJYA le 30 Oct 2022
Modifié(e) : KALYAN ACHARJYA le 30 Oct 2022
#Your Comment: Edited: TTo run the code here itself (Tap Green Tringular Button-Online) or try it on Matlab Platform (System-Offline)

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur 2-D and 3-D Plots dans Help Center et File Exchange

Produits


Version

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by