For Loop plot range of numbers

4 Ansichten (letzte 30 Tage)
Hailey
Hailey am 28 Nov. 2019
Kommentiert: Star Strider am 28 Nov. 2019
Hello,
I'm trying to plot this equation:
Then use gamma as 1.4, 1.3, and 1.2.
And have n_n (eta_n) as a varied range of numbers: [ 1.00 0.975 0.975 0.950 0.925]
But with the code I kept trying to manipulate, I keep getting just one plot, and it's the wrong plot as well. Please, any advise will help.
the graph is supposed to be including all the eta_n. Each of them. Then the varied gammas are seperate. So, I should end up with three graphs, one for each gamma value, each having four curves (eta_n)
The graph is supposed to look like something like this: (if gamma = 1.3)
Capture.PNG
%gamma
g1 = 1.4;
g2 = 1.3;
g3 = 1.2;
%eta_n
n = [1.00 0.975 0.975 0.950 0.925];
%pt2/p_inf
p = 100;
%Me
M = linspace(1,10,15);
%Ae/A* for g = 1.4
for N = 1:numel(n)
A_1(n) = ((1./M).*((2/(g1+1)).*(1+((g1-1)./2).*M.^2).^((1/2).*((g1+1)./(g1-1))))).*((1+(1-(1./(n))).*((g1-1)./2).*M.^2).^(-g1/(g1-1)));
hold on
loglog(A_1(n),M);
xlabel('A_e/A*');
ylabel('M_e');
grid on
legend('eta_n=1.00','eta_n=0.975','eta_n=0.950','eta_n=0.925');
end

Antworten (2)

Star Strider
Star Strider am 28 Nov. 2019
I cannot follow what you are doing.
At the very least, the ‘A_1’ assignment needs to be:
A_1(N,:) = ((1./M).*((2/(g1+1)).*(1+((g1-1)./2).*M.^2).^((1/2).*((g1+1)./(g1-1))))).*((1+(1-(1./(n(N)))).*((g1-1)./2).*M.^2).^(-g1/(g1-1)));
so the entire code becomes:
%gamma
g1 = 1.4;
g2 = 1.3;
g3 = 1.2;
gv = [g1, g2, g3]; % Optional, If You Want To Cycle Through Them Later
%eta_n
n = [1.00 0.975 0.975 0.950 0.925];
%pt2/p_inf
p = 100;
%Me
M = linspace(1,10,15);
%Ae/A* for g = 1.4
for N = 1:numel(n)
A_1(N,:) = ((1./M).*((2/(g1+1)).*(1+((g1-1)./2).*M.^2).^((1/2).*((g1+1)./(g1-1))))).*((1+(1-(1./(n(N)))).*((g1-1)./2).*M.^2).^(-g1/(g1-1)));
hold on
loglog(A_1(N,:),M);
xlabel('A_e/A*');
ylabel('M_e');
grid on
legend('eta_n=1.00','eta_n=0.975','eta_n=0.950','eta_n=0.925');
end
That produces one Warning about the legend entries, and otherwise runs without error.
  3 Kommentare
Hailey
Hailey am 28 Nov. 2019
Look at my question edit, and maybe that could help?
Star Strider
Star Strider am 28 Nov. 2019
I cannot detect any errors in your code (or my edit of it).
There is obviously something ‘over the horizon’ that we can’t see.
I will delete my Answer later, since it does not appear to be one.

Melden Sie sich an, um zu kommentieren.


Andrei Bobrov
Andrei Bobrov am 28 Nov. 2019
g = reshape(1.4:-.1:1.2,1,1,[]);
n = [1.00, 0.975, 0.975, 0.950, 0.925];
M = linspace(1,10,15)';
g1 = g + 1;
g_1 = g - 1;
A = 1./M.*(2./g1.*(1+g_1./2.*M.^2)).^(.5*g1./g_1).*(1+(1-1./n).*g_1/2.*M.^2).^(-g./g_1);
  1 Kommentar
Hailey
Hailey am 28 Nov. 2019
Hi Andrei,
Where would I submit this edit in my current code? Woud it go before the for loop? Thanks in advance.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Time Series Events finden Sie in Help Center und File Exchange

Produkte


Version

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by