# -*- coding: utf-8 -*-
"""
Created on Fri Sep 22 14:18:29 2017
@author: www
"""
import matplotlib.pyplot as plt
import numpy as np
#xo为迭代的起点
def fun(a,b,c,x0):
x=[]
y=[]
if(abs(-(2*a/b))>1) :
print("不收敛")
return 0;
x1=-((a*x0*x0+c)/(b*x0))
while(abs(x1-x0)>0.0001):
x.append(x0)
y.append(x1)
x0=x1
x1=-(a*x0*x0+c)/(b*x0)
print(x0)
m=np.linspace(0.1,2,50)
m1=m
m2=-((a*m*m+c)/(b*m))
plt.plot(m,m1,'b',m,m2,'r')
plt.ylim(0,2)
plt.plot(x,y,'g')
#检验,此函数有两个根,其中一个为 1
fun(2,-8,6,0.5)