Changing equation with loop

2 Ansichten (letzte 30 Tage)
daniel Picasso
daniel Picasso am 22 Feb. 2020
Beantwortet: darova am 22 Feb. 2020
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

Antworten (1)

darova
darova am 22 Feb. 2020
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)

Kategorien

Mehr zu Programming finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by