For Loop plot range of numbers
1 回表示 (過去 30 日間)
古いコメントを表示
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)
%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
0 件のコメント
回答 (2 件)
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 件のコメント
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
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);
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!