#include<stdio.h>
#include<conio.h>
#include<math.h>
#include<stdlib.h>
float fun(float x,float y)
{
return(x*y);
}
void main()
{
float y,x,h,e,k1,k2,k3,k4,k5,k;
int n,i;
clrscr();
printf("\n enter the value of x0:");
scanf("%f",&x);
printf("\n enter the value of y0:");
scanf("%f",&y);
printf("\n enter step length h: ");
scanf("%f",&h);
printf("\n enter the vlaue of x at which y is needed :");
scanf("%f",&e);
n=(e-x)/h;
for(i=1;i<=n;i++)
{
k1=h*fun(x,y);
k2=h*fun(x+h/4,y+k1/4);
k3=h*fun(x+(3*h)/8,y+(3*k1)/32+(9*k2)/32);
k4=h*fun(x+(12*h)/13,y+(1932*k1/21971)+(7200*k2/2197)+(7296*k3/2197));
k5=h*fun(x+h,y+(439*k1/216)-8*k2+(3600*k3/513)-(845*k4/4104));
k=((25*k1/216)+(1048*k3/2565)+(2197*k4/4104)-k5/5);
y=y+k;
x=x+h;
printf("the value of y at x=%f is %f ",x,y);
}
getch();
}
#include<conio.h>
#include<math.h>
#include<stdlib.h>
float fun(float x,float y)
{
return(x*y);
}
void main()
{
float y,x,h,e,k1,k2,k3,k4,k5,k;
int n,i;
clrscr();
printf("\n enter the value of x0:");
scanf("%f",&x);
printf("\n enter the value of y0:");
scanf("%f",&y);
printf("\n enter step length h: ");
scanf("%f",&h);
printf("\n enter the vlaue of x at which y is needed :");
scanf("%f",&e);
n=(e-x)/h;
for(i=1;i<=n;i++)
{
k1=h*fun(x,y);
k2=h*fun(x+h/4,y+k1/4);
k3=h*fun(x+(3*h)/8,y+(3*k1)/32+(9*k2)/32);
k4=h*fun(x+(12*h)/13,y+(1932*k1/21971)+(7200*k2/2197)+(7296*k3/2197));
k5=h*fun(x+h,y+(439*k1/216)-8*k2+(3600*k3/513)-(845*k4/4104));
k=((25*k1/216)+(1048*k3/2565)+(2197*k4/4104)-k5/5);
y=y+k;
x=x+h;
printf("the value of y at x=%f is %f ",x,y);
}
getch();
}
No comments:
Post a Comment