Не знаете, как это сделать?
implement the algorithms for the bisection and false-point variant discussed from the 04-Lecture-part-a notebook to approximate the 𝑟 that makes the centered-difference approximation of 𝑑𝑆/𝑑𝑟=0 (use ℎ=0.001 when calling this finite-difference function). Use an interval of (0,40] and a tolerance of 0.01 in both algorithms. Comment on the number of times 𝑆 must be evaluated to achieve the desired tolerance for each algorithm (hint: look at the total number of iterations and check how many times 𝑆 must be evaluated by the finite-different function). Compare this to the brute-force approach.
Что я уже пробовал:
def for_diff(f,x=0,h=.1): ''' Computes a forward difference approximation to the derivative of f at x using a step-size of h. >>> for_diff(lambda x : 5) 0.0 >>> for_diff(lambda x : 5*x) 5 ''' deriv=(f(x+h)-f(x))/h return deriv def back_diff(f,x=0,h=.1): deriv=(f(x)-f(x-h))/h return deriv def cent_diff(f,x=0,h=.1): deriv=(f(x+h)-f(x-h))/(2*h) return deriv