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

2 vues (au cours des 30 derniers jours)
민석 최
민석 최 le 7 Juin 2022
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)

Réponses (1)

David Goodmanson
David Goodmanson le 7 Juin 2022
Modifié(e) : David Goodmanson le 8 Juin 2022
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.

Catégories

En savoir plus sur Multidimensional Arrays dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by