computing first 50 terms of sequence

6 ビュー (過去 30 日間)
e smith
e smith 2015 年 5 月 6 日
コメント済み: e smith 2015 年 5 月 6 日
I want to compute the first 50 terms but only display the 10th and 20th of the sequence x_k+1 = A*x_k where x_0 is [1;0]. I keep getting an error that says "In an assignment A(I) = B, the number of elements in B and I must be the same." I am confused on what I am doing wrong. This is the code I have:
x(1) = [1;0]
A = [1.52 -.7; .56 .4];
for k = 2:5
x(k) = A*(x(k-1))
end
disp(x(10))
disp(x(20))

採用された回答

Nobel Mondal
Nobel Mondal 2015 年 5 月 6 日
編集済み: Nobel Mondal 2015 年 5 月 6 日
Keeping your code intact for most of the part, this is a quick fix
x = zeros(2,50);
x(:,1) = [1;0];
A = [1.52 -.7; .56 .4];
for k = 2:50
x(:,k) = A*x(:,k-1);
end
disp(x(:,10))
disp(x(:,20))
  1 件のコメント
e smith
e smith 2015 年 5 月 6 日
Thank you

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

その他の回答 (1 件)

Chad Greene
Chad Greene 2015 年 5 月 6 日
x(1) can only have one element. You'll have to choose whether x(1)=1 or x(1)=0.
Also, you'll run into a problem because your loop runs 2:5. You'll want 2:50.

カテゴリ

Help Center および File ExchangeArgument Definitions についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by