精选优质文档-倾情为你奉上from math import logfrom math import sin,cosimport random#Q1def bifection(f,a,b,error,n):f stands for the function we want to approximate to, while a and b are theleft and right number of the interval where the f effects in, and n means for thetime we have tried to make a approximationbifection(f,0,1,10*-6,20)FA = f(a)for i in range(n):p = a + (b-a)/2FP = f(p)if FP = 0 or (b - a)/2 0:a = pelse:b = p