0
基于此function。我试图创建两个空数组(其中一个用于x,另一个用于y),后面我将用它来绘制python。但在此之前,这是我迄今为止...python和weierstrass函数
import math
x1=-2.0
x2=2.0
arr1 = []
arr2 = []
i=0
n=10
delta=(x2-x1)/n
for i in range (0,n+1):
x=x1+delta*i
arr1.append(x)
print arr1
# I have not called the w function yet
上面的代码创建了一个10个数字的列表,目前为了保持简单。然后它将数组的元素发送到下面的函数中,并使用特定数字(无限循环)计算方程。
#This function will create the array list for y
import math
def w(x, limit):# the limit here to compare when the number is really small
suma = 0.0
sumb = 0.0
m=1
x=0
suma=suma+((1/(math.pow(2,m))*(math.sin(math.pow(2,m)*x)))
sumb=suma+((1/(math.pow(2,m+1))*(math.sin(math.pow(2,m+1)*x))) # I'm having a
#syntax error
#here
x+=0
if (abs (suma-sumb)<limit):
break:
else m+=1:
if (m<20):
break:
我会感谢任何帮助我的语法错误或任何建议。我只希望我清楚。 提前致谢
DDK,感谢或您的意见。他们真的帮助,并且你对while循环是如此的正确......我怎么假装创建一个没有for或while的循环?对我来说,我很感谢它! – mcs12
没问题!很高兴能有所帮助。 – ddk