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.
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; }
1) Explain the runge-kutta method 2) Produce an example that estimates a differential equation with this...
2. a. Show that the fourth order Runge Kutta method, when applied to the differential equation y' - Ay, can be written in the form i.e. show that w+1 Q(hA)w, where (10) b. Show that the backward Euler method, when applied to the differential equation y'- Xy, can be written in the form (12) wi. i.e. show that w+1-Q(hA)w; where (13) 2. a. Show that the fourth order Runge Kutta method, when applied to the differential equation y' - Ay,...
2. The explicit Euler and 4th order Runge-Kutta schemes for solving the following ordinary differential equation do f(6 dt are given by Atf() and 1 At (ki k2 k ka + ( ) k2=f( + At- k2 ka f At 2 respectively (a) Perform stability analysis on the model problem do _ dt for BOTH the explicit Euler and 4th order Runge-Kutta schemes and show that the respective stability regions are given by (Euler) AAt 4 (AAt)2 2 (AAt)3 (AAt)4...
Problem: Write a computer program to implement the Fourth Order Runge-Kutta method to solve the differential equation x=x2 (1) cos(x(1))-4fx(t), x(0)=-0.5 Use h-0.01. Evaluate and print a table of the solution over the interval [O, 1 x(t) 0
Solve the ordinary differential equation below over the interval 0 sts 2s using two different methods: the Euler method and the second-order Runge-Kutta method (midpoint version). Begin by writing the state space representation of the equation. Use a time step of 1 s, and place a box around the values of x and x at t- 2 s obtained using each method. Show your work. 20d's +5dr +20x = 0 dt d x(0) = 1, x'(0) = 1 Solve the...
(3) Consider the expressions (a) Write down the Runge-Kutta method for the numerical solution to a differential equation Oy (b) Show that if f is independent of y, i.e. f(x, y) g(x) for some g, then the Runge-Kutta method on the interval n n + h] becomes Simpson's Rule for the numerical approximation of the integral g(x) dr. In this case, what is the global error, in terms of O(hk) for some k>0? (3) Consider the expressions (a) Write down...
Question 12 (3 marks) Special Attempt 2 A system of two first order differential equations can be written as 0 dr A second order explicit Runge-Kutta scheme for the system of two first order equations is 1hg(n,un,vn), un+1 Consider the following second order differential equation d2 0cy-6, with v(1)-1 and y'()-o Use the Runge-kutta scheme to find an approximate solution of the second order differential equation, at x = 1.2, if the step size h Maintain at least eight decimal...
MATLAB HELP 3. Consider the equation y′ = y2 − 3x, where y(0) = 1. USE THE EULER AND RUNGE-KUTTA APPROXIMATION SCRIPTS PROVIDED IN THE PICTURES a. Use a Euler approximation with a step size of 0.25 to approximate y(2). b. Use a Runge-Kutta approximation with a step size of 0.25 to approximate y(2). c. Graph both approximation functions in the same window as a slope field for the differential equation. d. Find a formula for the actual solution (not...
In Exercise, use the Runge-Kutta method with the given number n of steps to approximate the solution to the initial-value problem specified. Your answer should include a table of approximate values of the dependent variable. It should also include a sketch of the graph of the approximate solution. Compare the graphs that you get from the Runge-Kutta method to those that come from Euler's method and improved Euler's method. If your computer has a built-in routine for the numerical solution...
Both parts please! 1 Runge-Kutta Method The discretization of the spatial derivatives of a PDE often results in a system of ODEs of the fornm du Runge-Kutta methods are the most commonly used schemes for numerically integrating in time the ODE system. We will numerically implement the "standard" third-order Runge-Kutta method. To advance the solution u from time t to t + Δ1, three sub-steps, are taken. If the solution at time t is un the following three steps are...
Solve Example 6.2 on page 111 of textbook, using (1) the 4th order Runge Kutta method and (2) Simulink method, respectively. Please submit your MATLAB code m file and slx file You can use the results from the code attached below (from the textbook by ODE45 solver) as a reference Example 6.2 ode45 ex.m % This program solves a system of 3 differential equations % by using ode45 function % y1 (0)=0, y2 (0)=1.0, y3 (0)=1.0 clear; clc initial [0.0...