4. The Adams-Bashforth Method The Euler, Heun, and Runge-Kutta methods are all e
ID: 3750702 • Letter: 4
Question
4. The Adams-Bashforth Method The Euler, Heun, and Runge-Kutta methods are all examples of one-step methods. They compute un+1 from yn. A two step method two points to compute the next iteration, i.., Un+ example, consider the two-step Adams-Bashforth method 2 is computed from yn+1 and yn. For where h is the step size. Since IVPs for first order ODEs specify only one initial value, it is common to use Euler's method to compute yn from yo, and compute all successive yn values with the two-step method. (a) (10 points) Implement the two-step Adams-Bashforth method in python. Your function should take in five parameters to, yo, y1, h, n, and return a list of ordered pairs (Hint: Modify the code for Euler's method to fit this method.). Attach your code to the back of the lab. (b) (5 points) On the same plot, use Euler's method and your implementation of the two-step Adams-Bashforth method to plot solutions curves to the following ODE on the region -3Explanation / Answer
#python 2.7.6
import numpy as np
from matplotlib import pyplot as plt
x0 = 0
y0 = 1
xf = 10
n = 101
deltax = ( xfx0 ) / (n1)
x = np.linspace( x0 , xf , n )
y=np.zeros([n])
y [ 0 ] = y0
f o r i i n range ( 1 , n ) :
y [ i ] = d el t a x (y [ i 1] + np . s i n ( x [ i 1] ) ) + y [ i 1]
f o r i i n range ( n ) :
p r i n t ( x [ i ] , y [ i ] )
p l t . pl o t ( x , y , ’ o ’ )
p l t . x l a b e l (” Value of x ” )
p l t . y l a b e l (” Value of y ” )
p l t . t i t l e (” Approximate S ol u ti o n with Forward Euler ’ s Method ” )
p l t . show ( )
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.