write a program to find solution of ordinary differential equation using Euler's method in c++.
write a program to find solution of ordinary differential equation using Euler's method in c++.
CODE:
#include<iostream.h>
#include<conio.h>
float f(float x,float y)
{
return (x*y);
}
void main()
{
clrscr();
int i;
float x,y,xn,h;
cout<<"Enter value of x:";
cin>>x;
cout<<"Enter value of y:";
cin>>y;
cout<<"Enter value of xn:";
cin>>xn;
cout<<"Enter size of interval:";
cin>>h;
cout<<"Euler's method:\n";
cout<<"x \t y"<<endl;
cout<<x<<" \t "<<y<<endl;
while(x<xn)
{
y=y+h*f(x,y);
x=x+h;
i++;
cout<<i<<"\t"<<x<<" \t "<<y<<endl;
}
getch();
}
OUTPUT:
Comments
Post a Comment