Write a C program to solve the following differential equation using
Runge-Kutta method. Step size h=0.3
10 dy/dx+ 3y^3 = x(x + 1),y(0.3) = 5
Find y(x) for different values of x
Answers
Answered by
2
#include<stdio.h>
#include<math.h>
float f(float x,float y);
int main()
{
float x0,y0,m1,m2,m3,m4,m,y,x,h,xn;
printf("Enter x0,y0,xn,h:");
scanf("%f %f %f %f",&x0,&y0,&xn,&h);
x=x0;
y=y0;
printf("\n\nX\t\tY\n");
while(x<xn)
{
m1=f(x0,y0);
m2=f((x0+h/2.0),(y0+m1*h/2.0));
m3=f((x0+h/2.0),(y0+m2*h/2.0));
m4=f((x0+h),(y0+m3*h));
m=((m1+2*m2+2*m3+m4)/6);
y=y+m*h;
x=x+h;
printf("%f\t%f\n",x,y);
}
}
float f(float x,float y)
{
float m;
m=(x-y)/(x+y);
return m;
}
Answered by
0
Explanation:
Test Case 1 -
0.9
y=1.7772
Test Case 2
1.2
y=1.4681
Similar questions
English,
2 months ago
English,
2 months ago
English,
6 months ago
English,
6 months ago
Biology,
11 months ago
India Languages,
11 months ago
India Languages,
11 months ago