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

Euler

Uploaded by

vbiswal19
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)
8 views2 pages

Euler

Uploaded by

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

AIM: To solve differential equation using Euler method.

THEORY:
Euler method is one of the simplest method to solve the ordinary differential equations. Consider a
first order differential equation,
ⅆy
= y '=f ( x , y )
ⅆx
The taylor series expansion for y(x) is given as:
y(x0+h) = y(x0) + h y’(x0) + ………..
Let x1=x0+h and neglecting the second and higher order terms in taylor series expansion we get,
y(x1) = y(x0) + h f (x0, y0)
Similarly, at x2 = x1+h ,y(x2) is given as:
y(x2) = y(x1) + h f (x1, y1)
Similarly, all other points can be calculated. In general, it is given as:
y(xn)= y(xn-1) + h f (xn-1, yn-1)
The above method to solve differential equation is known as Euler method. Here, to find values of y n
at any xn we require initial conditions x0 and y0, therefore this method is also known as initial value
method.
Euler method is very simple method to solve but it’s accuracy is not too good. In many cases the
results are unacceptably poor. This happens so because we have taken the terms only upto the first
order derivative in taylor series expansion of y(x). The curvature of the function is not taken into
consideration in this scheme by neglecting the higher order terms of taylor series expansion. Other
schemes such as higher order Runge Kutta method can be used for increased accuracy.

PROGRAM:
#include<iostream>
#define f(x,y) y-x/y+x

using namespace std;

int main()
{
float x0, y0, xn, h, yn, slope;
int i, n;

cout<<"Enter Initial Condition"<< endl;


cout<<"x0 = ";
cin>> x0;
cout<<"y0 = ";
cin >> y0;
cout<<"Enter calculation point xn = ";
cin>>xn;
cout<<"Enter number of steps: ";
cin>> n;

/* Calculating step size (h) */


h = (xn-x0)/n;

for(i=0; i < n; i++)


{
slope = f(x0, y0);
yn = y0 + h * slope;
y0 = yn;
x0 = x0+h;
}

cout<<"\nValue of y at x = "<< xn<< " is " << yn;

return 0;
}

OUTPUT:

Enter Initial Condition


x0 = 0
y0 = 1
Enter calculation point xn = 5
Enter number of steps: 6
Value of y at x = 5 is 62.0049

You might also like