This is a program to slove differential equation using fourth order Runge-Kutta method. The question is dy/dx=x(adsbygoogle = window.adsbygoogle || []).push({}); ^{2}+y^{2}

when y(0)=0, h=0.2

find y(0.4) (Ans= 0.021360)

#include<stdio.h>

#include<conio.h>

float f(float x, float y)

{

return (x*x+y*y);

}

void main()

{

float x1,y1,x2,y2,h=0.2,m1,m2,m3,m4;

clrscr();

printf("Enter the initial values of x and y\n");

scanf("%f%f",&x1,&y1);

while(1)

{

m1=f(x1,y1);

m2=f(x1+h/2,y1+(m1*h)/2);

m3=f(x1+h/2,y1+(m2*h)/2);

m4=f(x1+h,y1+m3*h);

y2=y1+(h/6)*(m1+(2*m2)+(2*m3)+m4);

x2=x1+h;

if(x2==0.4)

break;

else

{

x1=x2;

y1=y2;

}

}

printf("The value of y at x= 0.4 is %f\n",y2);

getch();

}

However this program is not working and giving the message Abnormal value: Floating point overflow. Can anyone please find out the error in this?

Thanks

**Physics Forums | Science Articles, Homework Help, Discussion**

Dismiss Notice

Join Physics Forums Today!

The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

# Floating point error

**Physics Forums | Science Articles, Homework Help, Discussion**