Modify a C code to find the solution of the differential equation below by using
ID: 3823057 • Letter: M
Question
Modify a C code to find the solution of the differential equation below by using Euler's method. The range of x is 2 to 3. and the step size is 0.1. dx/dy = x^2 - 3x with y = 3 at x = 2. List all the y values within the range of x = 2 to x = 3. Modify a C code to find the solution of the differential equation below by using forth-order Runge-Kutta method. The range of x is 2 to 4 and the step size is 0.1. dx/dy = mx^2 - * y -1 with y = 1.5 at x = 2. List all the y values within the range of x = 2 to x = 4.Explanation / Answer
#include<stdio.h>
//define your function dx/dy
float fun(float x,float y)
{
float n;
n=(x*x)-(3*x);
return n;
}
main()
{
//declare all the variables
float x1,y1,x,y,h,t,temp;
printf(" Enter x0,y0,h,xn: ");
//read the x0,y0,h,xn
scanf("%f%f%f%f",&x1,&y1,&h,&t);
x=x1; //set initial value of x;
y=y1; //set initial value of y;
printf(" x y ");
//iterate a loop from x=2 to x=3
while(x<=t)
{
temp=h*fun(x,y);
y=y+temp;
x=x+h;
if(x<=t)
printf("%0.3f %0.3f ",x,y);
}
}
/* Please let me know in comment section, if any problem exist . Thanks */
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.