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 - The Fusion of Science and Community**

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

Loading...

Similar Threads for Floating point error | Date |
---|---|

Testing floating point numbers for equality | Jan 12, 2018 |

Floating point numbers | Mar 9, 2016 |

What type of floating point representation is this? | Jul 1, 2015 |

Floating point numbers. | Sep 20, 2013 |

Fortran 90 (floating point error) | Apr 8, 2013 |

**Physics Forums - The Fusion of Science and Community**