'''Complex Numbers from the book'''from math import sqrt, degrees,atan2, sin, cos,radiansdef cAdd(a,b):return [a[0]+b[0],a[1]+b[1]]def cMult(u,v):'''Returns the product of two complex numbers'''return [u[0]*v[0]-u[1]*v[1],u[1]*v[0]+u[0]*v[1]]def theta(z):'''Calculates the angle of rotation of a complex number'''return degrees(atan2(z[1],z[0]))def magnitude(z):return sqrt(z[0]**2 + z[1]**2)def power(z,n):r = magnitude(z)angle = (1/3)*radians(theta(z)+360)return [r**n*cos(n*angle),r**n*sin(n*angle)]def synthDiv(divisor,dividend):'''divides a polynomial by a constant and returns a lower-degree polynomial. Enter divisor as a constant: (x - 3) is 3Enter dividend as a list of coefficients:x**2 – 5*x + 6 becomes [1,-5,6]'''quotient = [] #empty list for coefficients of quotientrow2 = [0] #start the second rowfor i in range(len(dividend)):quotient.append(dividend[i]+row2[i]) #add the ith columnrow2.append(divisor*quotient[i]) #put the new number in row 2print(quotient)def quad(a,b,c):'''Returns the solutions of an equationof the form a*x**2 + b*x + c = 0'''x1 = (-b + sqrt(b**2 - 4*a*c))/(2*a)x2 = (-b - sqrt(b**2 - 4*a*c))/(2*a)return x1,x2def f(x):return x**3 - 15*x - 4def average(a,b):return (a + b) / 2def guess():lower = -3upper = -4for i in range(20):midpt = average(lower,upper)if f(midpt) == 0:return midptelif f(midpt) < 0:upper = midptelse:lower = midptreturn midptdef arange(start,stop,step):'''Returns a list of numbers fromstart to stop by step'''output = []x = startwhile x < stop:output.append(x)x += stepreturn output
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。