Question: Exercise 1. Adapt the code cell above to find, follow, and graph a root of 2exp(/)1 as travels from 2 to 16 and =2 this

Exercise 1. Adapt the code cell above to find, follow, and graph a root of

2exp(/)1

as travels from 2 to 16 and =2

this is the code used below:

# follow the root of a quadratic as we vary a coefficient

c = 1 # a fixed coefficient

def f(x,b): return x**2 - b*x - c # your function here

def df(x,b): return 2*x - b # and its derivative

B = np.linspace(2,16,20) z = 2 # starting guess tol = 0.001 # how small do you want |f(x,b)| to get

for b in B: # step through the b values iter = 0 # count the number of Newton steps on way to answer while ( abs(f(z,b)) > tol and iter < 10 ): # The Main Loop z = z - f(z,b)/df(z,b) iter = iter + 1 plt.plot(b, z, 'r.')

plt.xlabel('b') plt.ylabel('x(b)') plt.title('Newton At Work: root of $x^2-bx-c$') plt.grid('on')

 

plug thst in to pyton to understand

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