Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Problem 1: Fourth-order Runge-Kutta method The fourth-order Runge-Kutta (RK4) me

ID: 3755929 • Letter: P

Question

Problem 1: Fourth-order Runge-Kutta method The fourth-order Runge-Kutta (RK4) method is a more sophisticated scheme for approximating the slope between successive time steps when numerically solving a differential equation. It can be summarized as: k, = g(f,t,J where fi is short-hand for f(t), etc. a. Write an R script that will solve the differential equation below from t [0, 5] using the RK4 method with a step size (Ar) of 0.1 and initial condition f(O) 0:s -ei sinst) + Sei cos (50) df dt Plot your numerical solution and the exact solution over that time interval. Reminder: The exact solution to this differential equation is: f(t) - ežsin(5t) b. Repeat step (a) but with a step size of 0.01. For both cases, calculate the percentage errors between the RK4 method and exact solutions at t- (1,2, 3, 4, 5). You reduced the time step by one order of magnitude. By how many orders of magnitude did the error decrease? c.

Explanation / Answer

function [ x, y ] = rk2 ( f_ode, xRange, yInitial, numSteps ) % [ x, y ] = rk2 ( f_ode, xRange, yInitial, numSteps ) % comments including the signature, meanings of variables, % math methods, your name and the date x(1,1) = xRange(1); h = ( xRange(2) - xRange(1) ) / numSteps; y(:,1) = yInitial; for k = 1 : numSteps xa = ??? ; ya = ??? ; x(1,k+1) = x(1,k) + h; y(:,k+1) = y(:,k) + h * f_ode( ??? ); end function [ x, y ] = forward_euler ( f_ode, xRange, yInitial, numSteps ) % [ x, y ] = forward_euler ( f_ode, xRange, yInitial, numSteps ) uses % Euler's explicit method to solve a system of first-order ODEs % dy/dx=f_ode(x,y). % f = function handle for a function with signature % fValue = f_ode(x,y) % where fValue is a column vector % xRange = [x1,x2] where the solution is sought on x1