How i implement Backward Difference Formula Method from general code ?

35 visualizaciones (últimos 30 días)
Below is the Backward Difference Formula general code. How can I adapt this code to the above question? Can you please help?
%-------------------------------------------
% Tw0 step Backward Difference Formula Method with fixed point iteration
% [T,Y]=gerifark2(f,tanim,Y1,h); tanim=[t1,tson]
%-------------------------------------------
function [T,Y]=gerifark2(f,tanim,Y1,h)
t1=tanim(1);tson=tanim(2);
eps=0.0001;
t2=t1+h;t3=t2+h;
tanim=[t1,t2];
[T,Y]=geuler(f,tanim,Y1,h);
Y2=Y(2);Y31=Y2;
while t2 < tson
fark=2*eps;
while fark > eps
Y32=4/3*Y2-1/3*Y1+2/3*h*f(t3,Y31);
fark=abs(Y32-Y31);
Y31=Y32;
end
Y3=Y32;Y1=Y2;Y2=Y3;
t1=t2;t2=t3;
T=[T;t3];Y=[Y;Y3];
t3=t3+h;
end
  3 comentarios
Torsten
Torsten el 27 de Mayo de 2022
Editada: Torsten el 27 de Mayo de 2022
You know the correct result of your differential equation.
If you plot Y against T in the calling program and compare the plot with the analytical solution, both should be approximately the same.
If yes, your code is (most probably) correct, if not, it's not.
Lateef Adewale Kareem
Lateef Adewale Kareem el 29 de Mayo de 2022
Editada: Lateef Adewale Kareem el 29 de Mayo de 2022
its hard to correct your code. you called other function (that I dont have) in your code. if I want to correct, there is no way for me to test. however I can try to solve the problem without using your code at all
I dont think I can help you on this

Iniciar sesión para comentar.

Respuestas (0)

Categorías

Más información sobre Ordinary Differential Equations en Help Center y File Exchange.

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by