![Numerical Methods Sumit Kar, Numerical Methods, C, Timus Rak](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjgEEuiVQujzDYGlv1PMDzDKYb5ozvCbIjo_Mt3FOu_A8h6GVex9UkCglRQEuc0wTKxbm_OgzCSMsAl0xTsTrdYwnZVmL3fFis99MAlE7B7SZTE3u-l8-Yoy14a7zhjLCMXS_y2grkLeaBz/s1600/c-programming-tutorial.jpg)
/*
Runga-Kutta Method
COmpute:: f(0.2)=?
When f(x,y)=x+y^2; y(0)=1 h=0.1
*/
#include<conio.h>
#include<stdio.h>
void main()
{
float x,y,h,xf,k1,k2,k3,k4,n;
int i;
float f(float,float);
printf("\nEnter x0 & y0");
scanf("%f%f",&x,&y);
printf("\nEnter x & h");
scanf("%f%f",&xf,&h);
n=(xf-x)/h;
for(i=0;i<=(int)n;i++)
{
k1=h*f(x,y);
k2=h*f(x+h/2,y+k1/2);
k3=h*f(x+h/2,y+k2/2);
k4=h*f(x+h,y+k3);
y=y+(k1+2*(k2+k3)+k4)/6;
x=x+h;
}
printf("\nResult %f",y);
getch();
}
float f(float x,float y)
{
return x+y*y;
}
0 Comments