For Loop plot range of numbers

조회 수: 5 (최근 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에서 Time Series Events에 대해 자세히 알아보기

제품


릴리스

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by