フィルターのクリア

i want to write matlab code for x(i+1) = x(i) + 0.05*2*x(i), i=0:0.05:1, x(0) =2

7 ビュー (過去 30 日間)
Ali Asghar
Ali Asghar 2018 年 10 月 6 日
コメント済み: Stephen23 2018 年 10 月 7 日
i want to write matlab code for
x(i+1) = x(i) + 0.05*2*x(i), i=0:0.05:1, x(0) =2
how can i do it in matlab?
  2 件のコメント
Stephen23
Stephen23 2018 年 10 月 6 日
編集済み: Stephen23 2018 年 10 月 6 日
This will not work:
x(i+1) = x(i) + 0.05*2*x(i), i=0:0.05:1
The vector i contains fraction values and it is shown as an index into x. Indices must be integer or logical, so using a fractional value will throw an error.
What have you tried so far? Please show us your code attempt.
Ali Asghar
Ali Asghar 2018 年 10 月 6 日
編集済み: Stephen23 2018 年 10 月 6 日
Thank for reply. I just started this work and having problem in inner loop in writing formula.
I wrote this code till yet.
clc, clear all, close all
T = 0.05;
for i=0:1:19;
for j = 1:1:20
x(i,j) = ???
end
end

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

回答 (2 件)

Stephen23
Stephen23 2018 年 10 月 6 日
Perhaps one of these does what you want:
>> i = 0:0.05:1;
>> x = cumsum(2+0.05*2*i)
x =
2.0000 4.0050 6.0150 8.0300 10.0500 12.0750 14.1050 16.1400 18.1800 20.2250 22.2750 24.3300 26.3900 28.4550 30.5250 32.6000 34.6800 36.7650 38.8550 40.9500 43.0500
>> x = 2+cumsum(0.05*2*i)
x =
2.0000 2.0050 2.0150 2.0300 2.0500 2.0750 2.1050 2.1400 2.1800 2.2250 2.2750 2.3300 2.3900 2.4550 2.5250 2.6000 2.6800 2.7650 2.8550 2.9500 3.0500
  3 件のコメント
Stephen23
Stephen23 2018 年 10 月 6 日
編集済み: Stephen23 2018 年 10 月 6 日
>> 2*1.1.^(0:10)
ans =
2.0000 2.2000 2.4200 2.6620 2.9282 3.2210 3.5431 3.8974 4.2872 4.7159 5.1875
Please remember to accept my answer if this helps you.
Ali Asghar
Ali Asghar 2018 年 10 月 6 日
Thank you soo much

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


ARAVIND
ARAVIND 2018 年 10 月 6 日
編集済み: ARAVIND 2018 年 10 月 6 日
ii = [0:0.05:1]; X = zeros(1,numel(ii)); X(1) = 2; for cnt = 1:numel(ii) X(cnt) = X(cnt)+ 0.05*2*ii(cnt); end
  2 件のコメント
ARAVIND
ARAVIND 2018 年 10 月 7 日
Hello Stephen, Thank you for your simpler answer. Can you explain the your code. I want to modify your code for different value(0.06 instead of 0.05).
Kind Regards, Aravind
Stephen23
Stephen23 2018 年 10 月 7 日
x0 = 2;
fr = 0.06;
x0*(1+2*fr).^(0:10)

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

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by