Question
Write a Python function called midpoint(f, t0, yvec0, b, n) that implements the Midpoint Method for a system of 2 equations. * Approximate the solution
Write a Python function called midpoint(f, t0, yvec0, b, n) that implements the Midpoint Method for a system of 2 equations.
* Approximate the solution to , y(t0) = y0
* The first step with step size h is t1 = t0 + h and y1 = y0 + h f(t0,y0)
* Start at (t0, y0) and find the slope f(t0, y0)
* Find the halfway interval [t0, t1] by t1/2 = t0 + h/2 and y1/2 = y0 + h/2 f(t0, y0)
* Evaluate the slope at f(t1/2, y1/2)
* Take a step along [t0, t1] using the slope t1 = t0 + h and y1 = y0 + h f(t1/2, y1/2)
Next we want to use the midpoint method: If we have the system
and we want to generate the points (ti, (xi, yi))
* Treat y = (x, y) as a vector so that f(t, y) = (tx - y, x + ty)
* Let the solution to y be a list yvec = [x, y] and implement f(t, yvec) as:
def f(t, yvec):
return [t * yvec[0] - yvec [1], yvec [0] + t.* yvec[1]]
The function should return a list of t values and a list of y values. When you return the next list, it should have the form
yvec = [[x_0, y_0] , [x_1, y_1] , ... , [x_n, y_n]]
Test the code with and where x(0) = 1, y(0) = 0, x(t) = cos t, y(t) = sin t
dy dt = f(ty) dc =tx - y dt dy dt = c+ty dc = -4 -Y dt dy = 2 dt dy dt = f(ty) dc =tx - y dt dy dt = c+ty dc = -4 -Y dt dy = 2 dtStep 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