EULER METHOD:Explanation,algorithm,flowchart
EULER METHOD
Euler’s method is considered to be one of the oldest and simplest methods to find the numerical solution of ordinary differential equation or the initial value problems. Here, a short and simple algorithm and flowchart for Euler’s method has been presented, which can be used to write program for the method in any high level programming language.
Through Euler’s method, you can find a clear expression for y in terms of a finite number of elementary functions represented with x. The initial values of y and x are known, and for these an ordinary differential equation is considered.
Euler’s Method Algorithm:
- Start
- Define function
- Get the values of x0, y0, h and xn
*Here x0 and y0 are the initial conditions
h is the interval
xn is the required value - n = (xn – x0)/h + 1
- Start loop from i=1 to n
- y = y0 + h*f(x0,y0)
x = x + h - Print values of y0 and x0
- Check if x < xn
If yes, assign x0 = x and y0 = y
If no, goto 9. - End loop i
- Stop
FLOWCHART OF EULER'S METHOD:
#include<stdio.h>
float fun(float x,float y)
{
float f;
f=x+y;
return f;
}
main()
{
float a,b,x,y,h,t,k;
printf("\nEnter x0,y0,h,xn: ");
scanf("%f%f%f%f",&a,&b,&h,&t);
x=a;
y=b;
printf("\n x\t y\n");
while(x<=t)
{
k=h*fun(x,y);
y=y+k;
x=x+h;
printf("%0.3f\t%0.3f\n",x,y);
}
}
Comments
Post a Comment