How can I change this explicit method code to the implicit method code?
3 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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)
0 comentarios
Respuestas (1)
David Goodmanson
el 7 de Jun. de 2022
Editada: David Goodmanson
el 8 de Jun. de 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.
0 comentarios
Ver también
Categorías
Más información sobre Multidimensional Arrays en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!