フィルターのクリア

Error: Unable to perform assignment because the left and right sides have a different number of elements. (Line 16)

1 回表示 (過去 30 日間)
h=0.1;
y=1;
t=0;
Tend=4;
i=1;
while(t(i)<Tend)
t(i+1)=t(i)+h;
slope=(5*exp(-2*t)-3*exp(-4*t))/2;
y(i+1)=y(1)+slope*h;
end
Can anyone help me figure out whats causing the error in my code? I am trying to numerically approximate a function value from 0 to 4 seconds with a 0.1 secnd time step.

回答 (1 件)

KSSV
KSSV 2018 年 9 月 7 日
編集済み: KSSV 2018 年 9 月 7 日
You should proceed something like this:
h=0.1;
Tend=4;
t = 0:h:Tend ;
y = zeros(length(t),1) ;
y(1) = 1 ;
for i = 1:length(t)-1
slope=(5*exp(-2*t(i))-3*exp(-4*t(i)))/2;
y(i+1)=y(i)+slope*h;
end
plot(t,y)

カテゴリ

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

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by