Monday, 7 November 2011

Euler's Method

%% Write a MATLAB program to find y for x =0.1 given that dy/dx =

%% (y-x)/(y+x)taking h=0.02 using Euler's Method.



% Given

x0 = 0;

y0 = 1;

h = 0.02;

x =0.1;

x1 =x0;

y1=y0;

i=0;

fprintf (
' x%1.0f = %2.2f, y%1.0f = %2.4f \n',i,x1,i,y1);

while x1<x

y1= y1+h*(y1-x1)/(y1+x1);

x1=x1+h;

i=i+1;

fprintf (
' x%1.0f = %2.2f, y%1.0f = %2.4f \n',i,x1,i,y1);

end

No comments:

Post a Comment