#include<iostream.h>
float f(float a,float b)
{
float c;
c=0.5*(1+a)*b*b;
return c;
}
void main()
{
float x[20],y[20],h,del1,del2,del3,del4;
int i,n;
cout<<"\nEnter x(0),y(0),h,n=";
cin>>x[0]>>y[0]>>h>>n;
cout<<"\nx\ty\t\n";
for(i=0;i<=n-1;i++)
{
x[i+1]=x[i]+h;
del1=h*f(x[i],y[i]);
del2=h*f(x[i]+h/2,y[i]+del1/2);
del3=h*f(x[i]+h/2,y[i]+del2/2);
del4=h*f(x[i]+h,y[i]+del3);
y[i+1]=y[i]+(del1+2*del2+2*del3+del4)/6;
cout<<endl<<x[i+1]<<"\t"<<y[i+1];
}
}
float f(float a,float b)
{
float c;
c=0.5*(1+a)*b*b;
return c;
}
void main()
{
float x[20],y[20],h,del1,del2,del3,del4;
int i,n;
cout<<"\nEnter x(0),y(0),h,n=";
cin>>x[0]>>y[0]>>h>>n;
cout<<"\nx\ty\t\n";
for(i=0;i<=n-1;i++)
{
x[i+1]=x[i]+h;
del1=h*f(x[i],y[i]);
del2=h*f(x[i]+h/2,y[i]+del1/2);
del3=h*f(x[i]+h/2,y[i]+del2/2);
del4=h*f(x[i]+h,y[i]+del3);
y[i+1]=y[i]+(del1+2*del2+2*del3+del4)/6;
cout<<endl<<x[i+1]<<"\t"<<y[i+1];
}
}
No comments:
Post a Comment