For Loop plot range of numbers

1 次查看(过去 30 天)
Hailey
Hailey 2019-11-28
评论: Star Strider 2019-11-28
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

回答(2 个)

Star Strider
Star Strider 2019-11-28
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 个评论
Hailey
Hailey 2019-11-28
Look at my question edit, and maybe that could help?
Star Strider
Star Strider 2019-11-28
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.

请先登录,再进行评论。


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

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Mathematics 的更多信息

产品


版本

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by