For Loop plot range of numbers

4 visualizaciones (últimos 30 días)
Hailey
Hailey el 28 de Nov. de 2019
Comentada: Star Strider el 28 de Nov. de 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

Respuestas (2)

Star Strider
Star Strider el 28 de Nov. de 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 comentarios
Hailey
Hailey el 28 de Nov. de 2019
Look at my question edit, and maybe that could help?
Star Strider
Star Strider el 28 de Nov. de 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.

Iniciar sesión para comentar.


Andrei Bobrov
Andrei Bobrov el 28 de Nov. de 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 comentario
Hailey
Hailey el 28 de Nov. de 2019
Hi Andrei,
Where would I submit this edit in my current code? Woud it go before the for loop? Thanks in advance.

Iniciar sesión para comentar.

Categorías

Más información sobre Time Series Events en Help Center y File Exchange.

Productos


Versión

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by