[英]Generating Point Sets for Reciprocal Function
everyone. 大家。
I am writing a function that generates the points to graph a reciprocal function. 我正在编写一个函数,生成点以绘制一个倒数函数。 Here is the code :
这是代码:
def genRecp(xValrange=3, shiftHoriz=0, shiftVert=0, vertStrech=1, horizStrech=1):
#setup variables for processing
xrangeP = xValrange
xrangeN = xrangeP - xrangeP * 2
vals = []
#start adding values to array
while xrangeN <= xrangeP:
curX = xrangeN
if curX == 0:
xrangeN += 1
continue
#generate y values
curY = vertStrech * (1 / (horizStrech * curX - shiftHoriz)) + shiftVert
newVal = [curX, curY]
#add value to array
vals.append(newVal)
#LOOOOOOP!
xrangeN +=1
return vals
The code seems fine, however, when I execute the following command : 但是,当我执行以下命令时,代码似乎很好:
genRecp()
I receive this output : [[-3, -1], [-2, -1], [-1, -1], [1, 1], [2, 0], [3, 0]]
which is clearly not an array of base points for a reciprocal function. 我收到这个输出:
[[-3, -1], [-2, -1], [-1, -1], [1, 1], [2, 0], [3, 0]]
这是显然不是一个互惠函数的基点数组。
What am I doing wrong? 我究竟做错了什么? Thank you in advance.
先感谢您。
Your default parameter values are all integers, and the line that calculates curY
uses integer division /
. 您的默认参数值都是整数,计算
curY
的行使用整数除法/
。 That rounds your calculated values to an integer. 这会将您的计算值舍入为整数。
Do something to make your values non-integers, namely floating-point, force your values to float by wrapping the numerator and denominator in the float()
typecast function. 做一些事情来使你的值非整数,即浮点,通过在
float()
类型转换函数中包装分子和分母来强制你的值浮动。 Or perhaps change the 1
constant in that line to 1.0
. 或者可能将该行中的
1
常量更改为1.0
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.