Enter multiple values for a single variable

조회 수: 1 (최근 30일)
Shane
Shane 2025년 3월 28일
댓글: Mathieu NOE 2025년 3월 28일
Hello, I'm trying to figure out a problem as I am trying to return to MatLab after being away from it for almost 30 years. This program has come a long way for sure. Here we go:
I have multiple constants:
Pa=101.3
Pa = 101.3000
B=0.0065
B = 0.0065
Ta=288.1500
Ta = 288.1500
g=9.81
g = 9.8100
R=286.9
R = 286.9000
I used linspace to create the 15-item vector (evenly spaced) that I wanted the equation to cycle through
z = linspace(0,11000,15)
z = 1×15
1.0e+04 * 0 0.0786 0.1571 0.2357 0.3143 0.3929 0.4714 0.5500 0.6286 0.7071 0.7857 0.8643 0.9429 1.0214 1.1000
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
I tried a for loop to run the equation over the amount of numbers in z
for idx = 1:length(z)
eqn = Pa(1-(z.*B/Ta))^(g/(BR));
p=solve(eqn,z);
end
Array indices must be positive integers or logical values.
You can see my error and I don't know how to fix it. Thanks.

채택된 답변

Mathieu NOE
Mathieu NOE 2025년 3월 28일
hello and welcome back after all this time
In my eyes you are not solving an equation you just computing the numerical output from the given equation and parameters (all defined)
just remember to use the dot operator when you are delaing with arrays / vectors
so I believe the goal is to plot the out(put) vs z ?
Pa=101.3;
B=0.0065;
Ta=288.1500;
g=9.81;
R=286.9;
z = linspace(0,11000,15);
out = Pa*(1-(z.*B/Ta)).^(g/(B*R));
plot(z,out);
  댓글 수: 2
Shane
Shane 2025년 3월 28일
That works! Thanks!
Mathieu NOE
Mathieu NOE 2025년 3월 28일
as always, my pleasure !

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

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

제품


릴리스

R2024b

Community Treasure Hunt

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

Start Hunting!

Translated by