0% found this document useful (0 votes)
187 views1 page

Matlab Code Euler

This Matlab code uses the Euler method to numerically solve differential equations. It takes in a function, left and right endpoints, initial condition, and number of steps. It returns a vector of x-values and y-values by calculating y-values at each step using the previous y-value and step size. The code breaks the interval into steps, calculates the y-value at each x-point using the Euler method formula, and returns the x and y vectors.

Uploaded by

coolboy_usama
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)
187 views1 page

Matlab Code Euler

This Matlab code uses the Euler method to numerically solve differential equations. It takes in a function, left and right endpoints, initial condition, and number of steps. It returns a vector of x-values and y-values by calculating y-values at each step using the previous y-value and step size. The code breaks the interval into steps, calculates the y-value at each x-point using the Euler method formula, and returns the x and y vectors.

Uploaded by

coolboy_usama
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
You are on page 1/ 1

Matlab Code for Euler Method

function E=euler(f,a,b,ya,M)
%Input - f is the function entered as a string 'f'
% - a and b are the left and right endpoints
% - ya is the initial condition y(a)
% - M is the number of steps
%Output - E=[' !'" #here is the $ector of abscissas and
% ! is the $ector of ordinates
h=(b-a)%M&
='eros(()M*()&
!='eros(()M*()&
=a+h+b&
!(()=ya&
for ,=(+M
!(,*()=!(,)*h-fe$al(f)(,))!(,))&
end
E=[' !'"&
!!=euler(f)a)b)ya)M)
plot(yy(+)()) yy(+).))

You might also like