Question

1) Explain the runge-kutta method 2) Produce an example that estimates a differential equation with this...

1) Explain the runge-kutta method

2) Produce an example that estimates a differential equation with this technique and the necessary code to run your iterations.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

The runge-kutta method / Runge kutta method of fourth order :-

It is the general method , the most widely known member of the Runge–Kutta family is generally referred to as "RK4", the "classic Runge–Kutta method" or simply as "the Runge–Kutta method".

Procedure:-

let the given differential equation be dy/dx = f(x,y) with the initial conditions ,

X = X0, y = y0 .

To find the value of y = y0 + k, say at x = x0 + h , we calculate,

K1 = hf (x0,y0)

K2 = hf (x0 + h/2 , y0 + k1/2)

K3 = hf (x0 + h/2 , y0 + k2/2)

K4= hf (x0 + h, y0 + k3)

Lastlty,

K = 1/6 [K1 + 2 K2 + 2 K3 + K4]

Required value: y = y0 + k

For example:

{Question} Solve dy/dx with initial conditions y(1)=2 and find y at x=1.2,1.4 by Runge –kutta method of fourth order.

Solution:-

K1 = hf (x0,y0) = 0.2(1*2) = 0.4

K2 = hf (x0 + h/2 , y0 + k1/2) = 0.2 [(1+0.1)(2+0.2)] = 0.484

K3 = hf (x0 + h/2 , y0 + k2/2) = 0.2[(1+0.1)(2+2.242)] = 0.49324

K4= hf (x0 + h, y0 + k3) = 0.2 [(1+0.2)(2+0.49324)] = 0.598378

=>K = 1/6[k1 + 2k2 + 2k3 + k4]

    K = 1/6[0.4+2*0.484+2*0.4932+0.492143]

=>y=y0+k = 2+0.492143

At x=1.2, y=2.492143

b) x0 = 1.2

y0 = 2.492143

h=0.2

f(x,y) = xy  

hence, f(x,y) = xy  .

2) //Eulers Method to solve a differential equation in c++ #include<iostream> #include<iomanip> #include<cmath> using namespace std; double df(double x, double y) //function for defining dy/dx { double a=x+y; //dy/dx=x+y return a; } int main() { int n; double x0,y0,x,y,h; //for initial values, width, etc. cout.precision(5); //for precision cout.setf(ios::fixed); cout<<"\nEnter the initial values of x and y respectively:\n"; //Initial values cin>>x0>>y0; cout<<"\nFor what value of x do you want to find the value of y\n"; cin>>x; cout<<"\nEnter the width of the sub-interval:\n"; //input width cin>>h; cout<<"x"<<setw(19)<<"y"<<setw(19)<<"dy/dx"<<setw(16)<<"y_new\n"; cout<<"----------------------------------------------------------\n"; while(fabs(x-x0)>0.0000001) //I couldn't just write "while(x0<x)" as they both are floating point nos. It is dangerous to compare two floating point nos. as they are not the same in binary as they are in decimal. For instance, a computer cannot exactly represent 0.1 or 0.7 in binary just like decimal can't represent 1/3 exactly without recurring digits. { y=y0+(h*df(x0,y0)); //calculate new y, which is y0+h*dy/dx cout<<x0<<setw(16)<<y0<<setw(16)<<df(x0,y0)<<setw(16)<<y<<endl; y0=y; //pass this new y as y0 in the next iteration. x0=x0+h; //calculate new x. } cout<<x0<<setw(16)<<y<<endl; cout<<"The approximate value of y at x=0 is "<<y<<endl; //print the solution. return 0; }
Add a comment
Know the answer?
Add Answer to:
1) Explain the runge-kutta method 2) Produce an example that estimates a differential equation with this...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT