Array indices must be positive integers or logical values.

1 回表示 (過去 30 日間)
BioZ
BioZ 2020 年 6 月 3 日
コメント済み: BioZ 2020 年 6 月 4 日
Hello everyone, I am new to Matlab and just learning at the moment.
I am trying to calculate a polynomial and then graph it, but I gent an error "Array indices must be positive integers or logical values." on line 23
would appreciate any help
Thank you!
clear
Cd0=0.01
K=0.02
W = 80000
S = 50
q=0.6
dH = 0.1
Hm = 12
H = 0:dH:Hm;
Pol1 = zeros(4,2);
Pol4 = zeros(4,2);
Pol = K*W^2
q = zeros(1,length(H));
q(1) = 1;
for n=2:length(H)
q(n) = (20-dH(n-1))/(20+dH(n-1));
Pol4(n) = Cd0(0.5*1.225*q(n)*50)^2;
Pol1(n) = ((-1.225*q(n))^2*0.5*50);
r =roots([Pol4(n) 0 0 Pol1(n) Pol])
end
  1 件のコメント
madhan ravi
madhan ravi 2020 年 6 月 3 日
There are lots of bugs , answers below points only one of the mistakes.

サインインしてコメントする。

採用された回答

Bjorn Gustavsson
Bjorn Gustavsson 2020 年 6 月 3 日
Most likely you want to multiply Cd0 with the expression in the parenthesis, you try to index the variable with the value of (0.5*1.225*q(n)*50); Try:
Pol4(n) = Cd0*(0.5*1.225*q(n)*50)^2;
HTH

その他の回答 (1 件)

Hank
Hank 2020 年 6 月 3 日
編集済み: Hank 2020 年 6 月 3 日
In the line:
Pol4(n) = Cd0(0.5*1.225*q(n)*50)^2;
what you wrote says to index Cd0 at 0.5*1.225*q(n)*50, which is probably not an integer. I think you want to multiply by Cd0 like this
Pol4(n) = Cd0 * (0.5*1.225*q(n)*50)^2;
You're also going to have trouble indexing the scalar value like you are: dH(n-1). Maybe you mean H(n-1)?
  2 件のコメント
Hank
Hank 2020 年 6 月 3 日
As I'm continuing to attempt to fix and run the code. More problems are popping up and I'm left wondering what you're trying to simulate here?
BioZ
BioZ 2020 年 6 月 4 日
During a cruise speed, aircrafts can have so called min a max available cruise speed. It's easy to solve for jet engine as it is just a quadratic but for prop engines it is a x^4 polynomial, therefore best to solve it via computational method. It should produce 2 real numbers and 2 imaginary values and when we reach abosolute ceiling 4 imaginary values should appear. My code was intended to solve that until 4 imaginary numbers or max alt specified was reached. then plot it against altitude I fixed the code already, but thank you very much for help! :)

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeMatrix Indexing についてさらに検索

製品


リリース

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by