简体   繁体   中英

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.

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 / . 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. Or perhaps change the 1 constant in that line to 1.0 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM