我需要在指定的时间间隔内绘制一个函数。函数为f1,如下代码所示,区间为[-7,-3];[-1, 1]; [3, 7],步长为 0.01。当我执行程序时,没有绘制任何内容。有任何想法吗?
import turtle
from math import sqrt
wn = turtle.Screen()
wn.bgcolor("white")
wn.title("Plotting")
mypen = turtle.Turtle()
mypen.shape("classic")
mypen.color("black")
mypen.speed(10)
while True:
try:
def f1(x):
return 2 * sqrt((-abs(abs(x)-1)) * abs(3 - abs(x))/((abs(x)-1)*(3-abs(x)))) * \
(1 + abs(abs(x)-3)/(abs(x)-3))*sqrt(1-(x/7)**2)+(5+0.97*(abs(x-0.5)+abs(x+0.5))-\
3*(abs(x-0.75)+abs(x+0.75)))*(1+abs(1-abs(x))/(1-abs(x)))
mypen.penup()
step=.01
startf11=-7
stopf11=-3
startf12=-1
stopf12=1
startf13=3
stopf13=7
def f11 (startf11,stopf11,step):
rc=[]
y = f1(startf11)
while y<=stopf11:
rc.append(startf11)
#y+=step
mypen.setpos(f1(startf11)*25,y*25)
mypen.dot()
def f12 (startf12,stopf12,step):
rc=[]
y = f1(startf12)
while y<=stopf12:
rc.append(startf12)
#y+=step
mypen.setpos(f1(startf12)*25, y*25)
mypen.dot()
def f13 (startf13,stopf13,step):
rc=[]
y = f1(startf13)
while y<=stopf13:
rc.append(startf13)
#y+=step
mypen.setpos(f1(startf13)*25, y*25)
mypen.dot()
f11(startf11,stopf11,step)
f12(startf12,stopf12,step)
f13(startf13,stopf13,step)
except ZeroDivisionError:
continue