write a program to find solution of ordinary differential equation using Taylor series method in c++.

write a program to find solution of ordinary differential equation using Taylor series method in c++.


CODE:
#include<iostream.h>
#include<conio.h>

float f(float y, float y1, float y2, float y3, float h)
{
return(y+h*y1+y2*(pow(h,2)/2)+y3*(pow(h,3)/6));
}

void main()
{
clrscr();
foat x,y,y1,xn,y2,y3,h,y4;
int i = 1;
cout>>"enter vlue of initial x & y: ";
cin>>x>>y;
cout<<"enter size of interval: ";
cin>>h;
cout<<"enter xn value: ";
cin>>xn;
cout>>"\n taylor's series :\n";
cout<<"\n\tx\ty\n";
while(x<xn)
{
y1=x+y;
y2=1+y1;
y3.y2;
float t = f(y,y1,y2,y3,h);
x=x+h;
y=t;
i++;
cout<<i<<"\t"<<x<<"\t"<<t<<endl;
}
getch();
}

OUTPUT:

Enter Value of initial X & Y: 1
2
Enter Size of intervals: 3
Enter XN Value:4
Taylor's Series:3
 4
4.3330

Comments

Popular Posts