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

please inlcude matlab code The Ralston method is a second-order method that can

ID: 3865752 • Letter: P

Question

please inlcude matlab code

The Ralston method is a second-order method that can be used to solve an initial-value, first-order ordinary differential equation. The algorithm is give below: y_i + 1 = y_i + (1/3 k_1 + 2/3 k_2)h Where k_1 = f(t_i, y_i) k_2 = f(t_i + 3/4 h, y_i + 3/4 k_ h) You are asked to do the following: Develop a MATLAB function m-file to implement the algorithm. The input will be the function, the time span, and the initial value. The output of the function should include the time array and the corresponding function array. Use your function m-file to solve the following first-order ordinary differential equation from r = 0 to t = 1.5 with the initial condition y = 3 at t = 0 dy/dt = -1.2 y + 7e^-0.3t Make a plot of your solution (with symbols) and compare it to the following exact solution (solid line): dy/dt = 70/9 e^-0.3t - 43/9 e^-1.2t

Explanation / Answer

function y0 = Runge_Kutta_Ralston_4(func, y0, x0, h, number_of_steps) SQRT5 = sqrt(5); a2 = 0.40; a3 = (14.0 - 3.0 * SQRT5) / 16.0; b31 = (-2889.0 + 1428.0 * SQRT5) / 1024.0; b32 = (3785.0 - 1620.0 * SQRT5) / 1024.0; b41 = (-3365.0 + 2094.0 * SQRT5) / 6040.0; b42 = (-975.0 - 3046.0 * SQRT5) / 2552.0; b43 = (467040.0 + 203968.0 * SQRT5) / 240845.0; g1 = (263.0 + 24.0 * SQRT5) / 1812.0; g2 = (125.0 - 1000.0 * SQRT5) / 3828.0; g3 = 1024.0 * (3346.0 + 1623.0 * SQRT5) / 5924787.0; g4 = (30.0 - 4.0 * SQRT5) / 123.0; h2 = a2 * h; h3 = a3 * h; for ii = 1:number_of_steps k1 = func(x0,y0); k2 = func(x0+h2, y0 + h2 * k1); k3 = func(x0+h3, y0 + h * (b31 * k1 + b32 * k2)); x0 = x0 + h; k4 = func(x0, y0 + h * (b41 * k1 + b42 * k2 + b43 * k3)); y0 = y0 + h * ( g1 * k1 + g2 * k2 + g3 * k3 + g4 * k4 ); end end