Runge Kutta method of 4th order to solve f(x,y)=log(x+y)?
//runge kutta method of 4th order;
#include<stdio.h>
#include<math.h>
float fun(float x,float y)
{
return log(x+y);
}
int main()
{
float k1,k2,k3,k4,x0=0.0,y0=1,y1,h;
int i;
printf("\n Enter the value at which y(x) is required :");
scanf("%f",&y1);
h=(y1-x0)/10.0;
for(i=0;i<10;i++)
{
k1=h*fun(x0,y0);
k2=h*fun(x0+(h/2),y0+(k1/2));
k3=h*fun(x0+(h/2),y0+(k2/2));
k4=h*fun(x0+h,y0+k3);
y1=y0+(1.0/6.0)*(k1+2*k2+2*k3+k4);
printf("\n #Iteration :%f %f\n",x0,y1);
x0=x0+h;
y0=y1;
}
printf("\n Answer :%f\n",y1);
return 0;
}
//runge kutta method of 4th order;
#include<stdio.h>
#include<math.h>
float fun(float x,float y)
{
return log(x+y);
}
int main()
{
float k1,k2,k3,k4,x0=0.0,y0=1,y1,h;
int i;
printf("\n Enter the value at which y(x) is required :");
scanf("%f",&y1);
h=(y1-x0)/10.0;
for(i=0;i<10;i++)
{
k1=h*fun(x0,y0);
k2=h*fun(x0+(h/2),y0+(k1/2));
k3=h*fun(x0+(h/2),y0+(k2/2));
k4=h*fun(x0+h,y0+k3);
y1=y0+(1.0/6.0)*(k1+2*k2+2*k3+k4);
printf("\n #Iteration :%f %f\n",x0,y1);
x0=x0+h;
y0=y1;
}
printf("\n Answer :%f\n",y1);
return 0;
}
OUTPUT