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

Euler Methods in MATLAB Code

This document describes an Euler method for numerical integration of differential equations. The method takes a function, initial value, endpoints, and number of steps as inputs. It calculates the step size, initializes the solution, then iteratively calculates the slope and updates the solution moving in steps from the initial to final points. At each step it prints the x and y values. The function being integrated in the example is 2x-y.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views2 pages

Euler Methods in MATLAB Code

This document describes an Euler method for numerical integration of differential equations. The method takes a function, initial value, endpoints, and number of steps as inputs. It calculates the step size, initializes the solution, then iteratively calculates the slope and updates the solution moving in steps from the initial to final points. At each step it prints the x and y values. The function being integrated in the example is 2x-y.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Chapter 6: Euler

methods

m-file:

function opseuler
(f,a,b,y0,n)
h=(b-a)/n
y=y0
fprintf('\n')
display('x y')
for i=1:n
x=a+(i-1)*h;
k=feval(f,x,y);
x=x+h;
y=y+h*k
fprintf('%6.2f
%12.6f \n',x,y)
end
function f=feu(x,y)
f=2*x-y;

You might also like