How can I change this explicit method code to the implicit method code?

2 ビュー (過去 30 日間)
민석 최
민석 최 2022 年 6 月 7 日
編集済み: David Goodmanson 2022 年 6 月 8 日
f = @(t,y) -100000*y + 99999*exp(-t);
t0 = 0; y0 =0;
h = 0.01; tn = 2;
n = (tn-t0)/h;
t(1)=t0; y(1)=y0;
for i=1:n
t(i+1) = t(i) + h;
y(i+1) = y(i) + (f(t(i),y(i))*h);
end
plot(t,y)

回答 (1 件)

David Goodmanson
David Goodmanson 2022 年 6 月 7 日
編集済み: David Goodmanson 2022 年 6 月 8 日
Hi MC
I am not sure what is meant by 'implicit method', and while numerical methods are good, there is also the exact expression. The solution to
y' = -a*y + b*exp(-t) a = 100000 b = 99999
is
y = A*exp(-a*(t-t0)) + (b/(a-1))*exp(-t)
where A is determined by the initial condition y(t0) = y0
A = y0 - (b/(a-1))*exp(-t0)
In this case b/(a-1) = 1 (probably not by coincidence) so further simplification happens.

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by