本文整理汇总了Python中function.Function.computeRange方法的典型用法代码示例。如果您正苦于以下问题:Python Function.computeRange方法的具体用法?Python Function.computeRange怎么用?Python Function.computeRange使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类function.Function
的用法示例。
在下文中一共展示了Function.computeRange方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main
# 需要导入模块: from function import Function [as 别名]
# 或者: from function.Function import computeRange [as 别名]
def main():
Maths.generateMathExpressions()
print("Available operators:")
for o in Maths.Expressions:
print(Maths.Expressions[o].getAbbreviation())
print("-------------------------")
f = Function("cos(3*x)+6/4*(x+3)", False)
print("RPN String", f.getRpnString())
for x in range (2, 11):
f.compute(x)
print("-------------------------")
f = Function("56*((6+2)/(8-x)*2^3", False)
print("RPN String", f.getRpnString()) #should give 56 6 2 + 8 7 - / 2 3 ^ * *
mainwindow = MainWindow("Function Drawer", 992, 512)
fx = f.computeRange(0, 10)
max_y = max(fx.values())
min_y = min(fx.values())
print(min_y, max_y)
mainwindow.setCoords(-1, min_y, 11, max_y)
for x in range(0, 11):
print(fx[x])
p = Point(x, fx[x])
p.draw(mainwindow)
input("Press a key to quit")
示例2: __init__
# 需要导入模块: from function import Function [as 别名]
# 或者: from function.Function import computeRange [as 别名]
class GraphWidget:
def __init__(self, pt_left_bot, pt_right_top, win):
self.function = Function("0")
self.p1 = pt_left_bot
self.p2 = pt_right_top
self.graph_area = Rectangle(self.p1, self.p2)
self.win = win
self.accuracy = 0.1
self.objects_drawn = []
def getFunction(self):
return self.func
def setFunction(self, func):
self.function = func
def draw(self, xa, xb):
self.cleanGraph()
#Compute function and draw it
x_min = min(xa, xb)
x_max = max(xa, xb)
#Compute all the values for f functon, accuracy give the step for computation
fx = self.function.computeRange(x_min, x_max, self.accuracy)
y_max = max(fx.values())
y_min = min(fx.values())
print(y_max, y_min)
self.win.setCoords(x_min-(1/10)*x_max, y_min-(1/10)*y_max, x_max+(1/10)*x_max, y_max+(4/10)*y_max)
x = x_min
end = x_max
prevfx = fx[x]
k = 0
while x < (end+self.accuracy):
#p = Point(x, fx)
#p.draw(mainwindow)
u = fx[x]
if k > 0:
self.drawLine(x-self.accuracy, prevfx, x, u)
prevfx = u
x += self.accuracy
k += 1
self.drawAxis(x_min, x_max, y_min, y_max)
def drawLine(self, x1, y1, x2, y2):
l = Line(Point(x1, y1), Point(x2, y2))
self.objects_drawn.append(l)
drawer = DrawerThread()
l.setOutline("blue")
drawer.run(l, self.win)
return
def drawAxis(self, x_min, x_max, y_min, y_max):
#Draw axes
#draw x axs first
#we first consider we will draw it where y=0
x_axis = Line(Point(x_min, 0), Point(x_max, 0))
if y_max < 0:
#if all the x values are under 0
#then we draw the on the top
x_axis = Line(Point(x_min, y_max), Point(x_max, y_max))
elif y_min > 0:
#if all the x values are over 0
#then we draw it at the bottom
x_axis = Line(Point(x_min, y_min), Point(x_max, y_min))
drawer = DrawerThread()
drawer.run(x_axis, self.win)
self.objects_drawn.append(x_axis)
#we consider we will draw where x=0
y_axis = Line(Point(0, y_min), Point(0, y_max))
if x_max < 0:
#if all the y values are under 0
#then we draw the on right
y_axis = Line(Point(x_max, y_min), Point(x_max, y_max))
elif x_min > 0:
#if all the y values are over 0
#then we draw it at the bottom
y_axis = Line(Point(x_min, y_min), Point(x_min, y_max))
drawer = DrawerThread()
drawer.run(y_axis, self.win)
self.objects_drawn.append(y_axis)
#draw x labels
y_ax = x_axis.getP1().getY()
x_step = x_max*(0.1)
x_size = y_max*.01
#from 0 to x_max
x = 0
togo = x_max+0.1
while x < togo:
sign = Line(Point(x, y_ax-x_size), Point(x, y_ax+x_size))
drawer = DrawerThread()
drawer.run(sign, self.win)
self.objects_drawn.append(sign)
if x != 0:
text = str(int(x))
#.........这里部分代码省略.........