for loop to calculate the value of a recurrence relation

4 ビュー (過去 30 日間)
chafah zachary
chafah zachary 2014 年 3 月 7 日
コメント済み: Roger Stafford 2014 年 3 月 8 日
A recurrence relation can be used to model feedback in a system. Given the following recurrence relation, the x vector, and the initial value of y at t=1, write MATLAB code to calculate the y-values corresponding to first 9 x-values. Store the result in the vector y.
the recurrence relation is as seen below
this is my attempt
x = [0 0.39 0.78 1.17 1.57 1.96 2.35 2.74 3.14]; y(1) = 2;
for x=1:0.39:9 t=2:9
y=0.2*x(t)+0.8*y(t-1) end
where am I wrong?
  1 件のコメント
Roger Stafford
Roger Stafford 2014 年 3 月 8 日
That won't work either, Chafah. As I said, you need
for t = 2:9
not
for x=1:0.39:9

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

採用された回答

Roger Stafford
Roger Stafford 2014 年 3 月 7 日
You haven't indexed your for-loop correctly. It should read:
y(1) = 2;
for t = 2:9
y(t) = 0.2*x(t)+0.8*y(t-1);
end

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by