根据2个数字之间的距离计算乘数

Calculating multiplier based on distance between 2 numbers

我不确定如何正确表达问题,但我会尝试。

我正在尝试找到一个公式来提供基于 2 个整数之间的差值的乘数。

例子

我也需要这个来处理负距离。

我上面使用的所有乘数都是示例。

我正在尝试在 Python 中实现它,因此 python 中的任何类型的示例都是理想的。

感谢 Pedro、John Moeller 和 ayhan 我有这个:

from math import sqrt

def multiplier(x, y):
    dist = y - x
    return 1 + dist/sqrt(5+dist**2)

这给出了输出:

Distance: -5 = 0.09
Distance: -4 = 0.13
Distance: -3 = 0.20
Distance: -2 = 0.33
Distance: -1 = 0.59
Distance: 0 = 1.00
Distance: 1 = 1.41
Distance: 2 = 1.67
Distance: 3 = 1.80
Distance: 4 = 1.87
Distance: 5 = 1.91

差不多了,谢谢!

试一试:1 + x/sqrt(1+x^2)。 这给出了类似于图表中的趋势,但它的 y 限制为 0 和 2,并且 x=0 根据需要给出 y=1。

http://m.wolframalpha.com/input/?i=1+%2B+x%2Fsqrt%281%2Bx%5E2%29&x=0&y=0

在Python中:

import math 
def multiplier(x, y):
    dist = x - y
    return 1 + dist/math.sqrt(1+dist**2)