Discuss / Python / Readme

Readme

Topic source

雨化千风

#1 Created at ... [Delete] [Delete and Lock User]

-- coding: utf-8 --

绝对值函数

求解ax^2+bx+c=0

def quadratic(a,b,c): if a ==0 & b!=0: #一个解 return (-c/b) elif (b2 - 4ac) >= 0 & b!=0: #两个解 s = 0.1 #迭代步长 n = 0.0 #解一迭代次数 m = 0.0 #解二迭代次数 x0 = - b/(2a) #初始值 while abs(a(x0 + n*s)2 + b(x0 + ns) + c) > 0.00001: n = n + 1; while abs(a(x0 - ms)*2 + b(x0 - ms) + c) > 0.00001: m = m + 1;
return(x0 + n
s,x0 - m*s) else: #无解 return

    #return(print('无解'))

  • 1

Reply