Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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 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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started