0% found this document useful (0 votes)
2 views2 pages

Euler Method in Matlab for ODEs

This document presents the MATLAB code to implement the Euler method for solving ordinary differential equations. The user inputs the differential equation, the initial and final points, the initial condition, and the number of steps. The code calculates the intermediate points, evaluates the equation at each step, and presents the approximate solution at the final point.

Translated by

ScribdTranslations
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views2 pages

Euler Method in Matlab for ODEs

This document presents the MATLAB code to implement the Euler method for solving ordinary differential equations. The user inputs the differential equation, the initial and final points, the initial condition, and the number of steps. The code calculates the intermediate points, evaluates the equation at each step, and presents the approximate solution at the final point.

Translated by

ScribdTranslations
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Matlab program for the Euler method

SOLUTION OF DIFFERENTIAL EQUATIONS BY THE


EULER METHOD
f=input('\nEnter the differential equation in the form: dy/dx=f(x,y)\n','s');
x0=input('\nEnter the first point x0:\n');
x1=input('\nEnter the second point x1:\n');
Enter the initial condition y(x0):
n=input('\nEnter the number of steps n:\n');
h=(x1-x0)/n;
xs=x0:h:x1;
y1=y0;
it x0 x1 y1');
for i=1:n
it=i-1;
x0=xs(i);
x=x0;
x1=xs(i+1);
y=y0;
y1 = y0 + h * eval(f);
fprintf('\n%2.0f%10.6f%10.6f%10.6f\n', it, x0, x1, y1);
y0=y1;
end
The approximate point y(x1) is = %10.6f

Given the differential equation y' = √(x^2 + y^2), use the Euler method to
approximate y(2.3) taking as the number of steps n=3 if the initial condition is
y(2)=0.5
Respuesta: y(2.3) = 1.166470

You might also like