c program for Runga-kutta method of 4th order

#include<stdio.h>
#include<math.h>
float f(float x,float y)
{
float f;

f=((1/(x+y)));
return (f);
}

int main()

{
float x0,y0,h,xn,k,k1,k2,k3,k4;
printf(“n Enter the initial value that is x0 and y0n”);
scanf(“%f%f”,&x0,&y0);

printf(“n Enter the value of hn”);
scanf(“%f”,&h);

printf(“n Enter the value of x for which we need to find the value of yn”);
scanf(“%f”,&xn);
do
{
k1=h*f(x0,y0);
k2=h*f(x0+(h/2),y0+(k1/2));
k3=h*f(x0+(h/2),y0+(k2/2));
k4=h*f(x0+h,y0+k3);
k=(k1+2*k2+2*k3+k4)/6;
y0=y0+k;
x0=x0+h;
printf(“n%f %f”,x0,y0);
}
while(x0<xn);
printf(“n value of y=%f”,y0);
}

output:
 Enter the initial value that is x0 and y0
0
1
 Enter the value of h
.1
 Enter the value of x for which we need to find the value of y
.1
0.100000 1.091389
 value of y=1.091389

Leave a Comment

Your email address will not be published. Required fields are marked *

Hire a server Expert to resolve the issue Now.

Hire a server Expert to resolve the issue Now.

Resolve this issue in just 5$ from https://serverexpert.io

 

You have Successfully Subscribed!

Open chat