필터 지우기
필터 지우기

plotting 2 variables as they change with respect to one another

조회 수: 4 (최근 30일)
Joshua Anderson
Joshua Anderson 2021년 4월 15일
편집: Ahmed Redissi 2021년 4월 15일
I'm trying to plot both A and M and they change simultaneously. If M changes, there is an associated A value within the given ranges. I'm having getting multiple M values to show even though multiple A values are being displayed. Any help would be greatly appreciated.
gamma = 1.4;
%M=1.53
for M= (0.1:0.01:2.19);
for A= (1:0.01:1)
A = 0.5*sqrt((1/M^2)*(2/(gamma+1)*(1+((gamma-1)/2)*M^2))^((gamma+1)/(gamma-1)))
end
end
plot(A,M)
ylabel('Area')
xlabel('Mach number')

답변 (2개)

Star Strider
Star Strider 2021년 4월 15일
편집: Star Strider 2021년 4월 15일
The solution is to subscript ‘A’.
Try this:
gamma = 1.4;
%M=1.53
Mv = (0.1:0.01:2.19);
for k1 = 1:numel(Mv)
M = Mv(k1);
A(k1) = 0.5*sqrt((1/M^2)*(2/(gamma+1)*(1+((gamma-1)/2)*M^2))^((gamma+1)/(gamma-1)));
end
figure
plot(Mv,A)
ylabel('Area')
xlabel('Mach number')
grid
However in MATLAB the explicit loop is not necessary, using element-wise operations:
M = 0.1:0.01:2.19;
A = 0.5*sqrt((1./M.^2).*(2/(gamma+1).*(1+((gamma-1)/2).*M.^2)).^((gamma+1)/(gamma-1)));
figure
plot(M,A)
ylabel('Area')
xlabel('Mach number')
grid
This produces the same result as the loop.
See Array vs. Matrix Operations for details.

Ahmed Redissi
Ahmed Redissi 2021년 4월 15일
편집: Ahmed Redissi 2021년 4월 15일
It's not clear why you are iterating over the values of A when you are not using them in the loop. Generaly, you shouldn't iterate over a variable and then change its content inside the loop unless you are incrementing or decrementing.
Does this perhaps solve your issue?
gamma = 1.4;
M = 0.1:0.01:2.19;
A = 0.5*sqrt((1./M.^2).*(2./(gamma+1).*(1+((gamma-1)/2)*M.^2)).^((gamma+1)./(gamma-1)));
plot(M,A)
ylabel('Area')
xlabel('Mach number')

카테고리

Help CenterFile Exchange에서 Gamma Functions에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by