Calculate an expression in MAtlab

1 回表示 (過去 30 日間)
John Amitage
John Amitage 2019 年 5 月 8 日
コメント済み: Star Strider 2019 年 5 月 8 日
(Sorry i don't know a better title)
I have (n=0,1,2,3,....)
How can I calculate the below expression with matlab codes ?
Thank you

採用された回答

Star Strider
Star Strider 2019 年 5 月 8 日
It depends on what ‘T’ and ‘c’ are.
If they are scalars, this would likely work:
T = rand;
c = rand;
x(1) = rand;
N = 10;
for k = 1:N
x(k+1) = x(k)*T+c;
end
  2 件のコメント
John Amitage
John Amitage 2019 年 5 月 8 日
Is there any way I can type x(0) instead of x(1) ?
T = 1;
c = 2;
X(0)= 3;
N = 10;
for k = 1:N
X(k) = X(k-1)*T+c;
end
If I correct the codes like this, an error appears :"Array indices must be positive integers or logical values."
Star Strider
Star Strider 2019 年 5 月 8 日
Is there any way I can type x(0) instead of x(1) ?
Not in MATLAB. In MATLAB, indices must be integers greater than 1.
However you can choose to display them the way you want:
for k = 1:numel(x)
fprintf('x(%d) = %.4f\n', k-1, x(k))
end
producing:
x(0) = 0.6905
x(1) = 1.0766
x(2) = 1.2961
...

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

その他の回答 (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