def iteration_lagrange(x0, q0, m, epsilon, f): def maj_test(xn,xnm1): return f(xn)!=0 and abs(xn-xnm1)>epsilon n=0 test=f(x0)!=0 X=[x0] xnm1=x0 xn=float(x0-f(x0))/q0 qn=q0 print(xn,q0) while n<=m and test: qn=float((f(xn)-f(xnm1)))/(xn-xnm1) xnm1=xn xn=xnm1-f(xnm1)/qn X+=[xn] test=maj_test(xn,xnm1) n+=1 return (n,X) //////////////////////////////////////////////////////////////////////////// print(iteration_lagrange(pi/4,1,200,0.0000001,f))