Jump to content

Recommended Posts

Posted

Hi!!! I need some help...
I want to write a code in matlab for the backward euler method.
How can I solve the equation to determine y^(n+1)??? Are newton's method, fixed point iteration, fsolve, fzero equal???

Posted

To use Newton's method, do i have to write:

for i=1:n
y(n+1)=y(n)-(g(y(n))/dg(y(n));

where g=y(n+1)-y(n)-h*f(t(n+1),y(n+1)) ???

Posted (edited)

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

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.