Jump to content

Backward Euler Method


mathmari

Recommended Posts

For the backward Euler's method, you could use something like the following:

 

clc;
clear;

ti=0;
tf=10;
n=5000;
h=(tf-ti)/n;
t(1)=ti;
y(1)=1;

for i=1:n
dydt=sin(t(i));
t(i+1)=t(i)+h;
y(i+1)=y(i)+h*dydt;
end;

plot(t,y)

 

 

I used dy/dt=sin(t) as an example function. To make it go backwards, all you have to do is make tf<ti, so that h becomes negative.

Edited by elfmotat
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.