mathmari Posted April 23, 2013 Posted April 23, 2013 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???
mathmari Posted April 26, 2013 Author Posted April 26, 2013 To use Newton's method, do i have to write:for i=1:ny(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)) ???
elfmotat Posted April 27, 2013 Posted April 27, 2013 (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 April 27, 2013 by elfmotat
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now