Info

この質問は閉じられています。 編集または回答するには再度開いてください。

Using array as a for loop

1 回表示 (過去 30 日間)
Harel Harel Shattenstein
Harel Harel Shattenstein 2016 年 3 月 13 日
閉鎖済み: MATLAB Answer Bot 2021 年 8 月 20 日
I need to solve the polynomial x^4+nx^3-1 for n=-1,0,1 (without using for loop)
What I did is:
n=(-1:1:1);
co_poly=[1 n 0 0 -1];
roots(co_poly)
but it just put the array n inside the coefficients array.

回答 (1 件)

Geoff Hayes
Geoff Hayes 2016 年 3 月 13 日
Harel - why don't you just iterate over each n and calculate the roots for that particular n? For example,
for n=-1:1:1
co_poly=[1 n 0 0 -1];
roots(co_poly)
end
  2 件のコメント
Harel Harel Shattenstein
Harel Harel Shattenstein 2016 年 3 月 13 日
I forgot, I should not use for
Geoff Hayes
Geoff Hayes 2016 年 3 月 13 日
Why can't you use for? Does the assignment prevent you from using that?

この質問は閉じられています。

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by