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 Write a Python function called midpoint(f, t0, yvec0, b, n) that implements, 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

the Midpoint Method for a system of 2 equations. * Approximate the and solution to , y(t0) = y0 * The first step with step 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 size h is t1 = t0 + h and y1 = y0 and + h f(t0,y0) * Start at (t0, y0) and find the slope 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 dt

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 Finance Questions!