Question: Write a function called odeRK4 which takes input parameters f, t and yo where: f is a function representing the right side of a

Write a function called odeRK4 which takes input parameters f, t and 

Write a function called odeRK4 which takes input parameters f, t and yo where: f is a function representing the right side of a differential equation y' = f(t, y) t is a NumPy array of 1 values ye is the initial condition y(to) = yo The function odeRK4 returns a NumPy array of y values given by the numerical method h = 1n+1 - In k = f(In, yn) k2= f(In+h/2, yn + kh/2) k3 = f(n+h/2, yn + kh/2) k4= f(In+h, yn + k3h) Yn+1 = yn+ (k1/6+ k2/3 + k3/3+ k4/6)h : # YOUR CODE HERE The function odeRK4 should give a good approximation of the solution of any first order system such as y = y cos(1), y(0) = 1. t = np.linspace(0,5*np.pi,50) flambda t,y: y*np.cos(t) y0 = 1 y = odeRK4(f,t,y0) t_exact = np.linspace (0,5 np. pi, 200) y_exact np.exp(np.sin(t_exact)) plt.plot(t,y, 'r.',t_exact,y_exact, 'b'), plt. legend (['RK4', 'Exact']) plt.show() Activa Go to Se

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!