Question: Writea Matlab function for the 2nd order Runge Kutta method. Test it on the interval [-4,4]: x' = sin(x + t^2) x(-4) = 3 Plot
Writea Matlab function for the 2nd order Runge Kutta method. Test it on the interval [-4,4]: x' = sin(x + t^2) x(-4) = 3 Plot your answer. Devise a way to check the accuracy of your method. (Hint: Since you don't have an exact solution, you could compare with Matlab's ode45() function's results.) The pseudocode for the method is below: Input: f, x, a, b, h Initialize: T (nx1 vector of t's); X (nx1 solution vector); t=a n = ceiling of ((b-a)/h) for j = 1 to n K1 = h*f(t,x) K2 = h*f(t+h, x+K1) x = x + 0.5*(K1 + K2) t = a + j*h T(j) = t; X(j) = x end Output: T,X and plot (T,X)
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
