Changing equation with loop

2 次查看(过去 30 天)
daniel Picasso
daniel Picasso 2020-2-22
回答: darova 2020-2-22
Pretty much, I need to plot x Vs. Pratio
But I need to use
Me to equal 1 when Me>=1
and for anything else
need Me = sqrt(2./(gamma-1).*((nPratio.^((gamma-1)./gamma))-1));
then plot X in terms of both Me as they change
Im really bad a MATLAB so sorry if this does not make sense
P0 = 500000;
Pb = linspace(0,500000,100);
R = 287;
gamma = 1.4;
z = -((gamma+1)/(2*(gamma-1)));
Pratio = Pb/P0;
nPratio = 1./Pratio;
Me = sqrt(2./(gamma-1).*((nPratio.^((gamma-1)./gamma))-1));
for x = (P0.*sqrt(gamma/R).*Me.*(1+((gamma-1)/2).*Me.^2).^z)
if Me >=1
x = P0.*sqrt(gamma/R).*(1+((gamma-1)/2)).^z;
else
x = (P0.*sqrt(gamma/R).*Me.*(1+((gamma-1)/2).*Me.^2).^z);
end
figure(1)
plot(Pratio,x1)
xlabel('Pb/P0');ylabel('Msqrt(To)/Ae')
end

回答(1 个)

darova
darova 2020-2-22
Use this
Me = sqrt(2./(gamma-1).*((nPratio.^((gamma-1)./gamma))-1));
ind = Me < 1;
x = (P0.*sqrt(gamma/R).*Me.*(1+((gamma-1)/2).*Me.^2).^z)
x(ind) = P0.*sqrt(gamma/R).*(1+((gamma-1)/2)).^z;
figure(1)
plot(x,Pratio)

类别

Help CenterFile Exchange 中查找有关 2-D and 3-D Plots 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by