我正在编程一个旋钮,该旋钮具有一个箭头,其位置由弧的编号定义。将此数字转换为40的数学算法/函数?
我正在寻找一种方法将这个弧号码转换成代表温度的数字。
圆弧号码的最小值为1.3,最大值为1.7。
1.3需要等于40和1.7需要等于99.
这可能吗?
我正在编程一个旋钮,该旋钮具有一个箭头,其位置由弧的编号定义。将此数字转换为40的数学算法/函数?
我正在寻找一种方法将这个弧号码转换成代表温度的数字。
圆弧号码的最小值为1.3,最大值为1.7。
1.3需要等于40和1.7需要等于99.
这可能吗?
如果它是线性的,可以用下面的公式来允许任何最小值和最大值:
from_min = -1.3
from_max = 1.7
to_min = 40
to_max = 99
from = <whatever value you want to convert>
to = (from - from_min) * (to_max - to_min)/(from_max - from_min) + to_min
的* (to_max - to_min)/(from_max - from_min)
位缩放从from
范围到to
范围的范围内。在to
范围内找到正确的点后,减去from_min
并加上to_min
。
例子,第一原:
(1.3..1.7) -> (40..99)
to = (from - from_min) * (to_max - to_min)/(from_max - from_min) + to_min
= (from - 1.3) * 59 /0.4 + 40
= (from - 1.3) * 147.5 + 40 (same as Ignacio)
= from * 147.5 - 151.75 (same as Zebediah using expansion)
然后一个使用-1.3作为下界为您的意见一个提到:
(-1.3..1.7) -> (40..99)
to = (from - from_min) * (to_max - to_min)/(from_max - from_min) + to_min
= (from - -1.3) * 59 /3 + 40
= (from + 1.3) * 19.67 + 40
这个答案(和所有其他人当然日期)假设它是是的一个线性函数。根据你在问题中使用诸如“弧”和“旋钮”这样的词,这绝不是清楚的。如果线性不足,你可能需要一些三角函数(正弦,余弦等)。
(n - 1.3) * 147.5 + 40
当然,只适合一行到它。
在这种情况下,线性代数的output = 147.5*input-151.75
这两个答案都是正确的,但是这个使用较少的操作就可以得到结果。 – kiamlaluno 2010-06-24 00:51:37
如果最小数为-1.3,函数将如何改变?我忘了添加否定。 – 2010-06-24 00:53:15
好老y = ax + b。 – Dan 2010-06-24 03:15:01
简单的小表演在这里。
这两个变量是旋钮位置(x)和一些常数(p)。
两个方程然后
1.3x + p = 40
1.7x + p = 99
解决p的第一个方程x中产量方面:
p = 40 - 1.3x
如果我们把P的新定义成我们可以简化第二个公式到:
1.7x + 40 - 1.3x = 99
.4x = 59
x = 147.5
然后,你可以从任何一个方程解出p。采用第一个公式:
p = 40 -1.3*147.5 = -151.75
因此,最终的公式得到旋钮位置温度应该是
temp = 147.5*knobPosition - 151.75
这就是人们通常所说的“代数”,而不是“线性代数”。你可能会说它是线性函数的代数,有时用f(x)= mx + b的形式表示,但它不是线性代数。 – 2010-06-24 01:08:14
这实在是一个简单的代数问题,不需要线性代数。
def scale_knob(knob_input):
knob_low = -1.3
knob_high = 1.7
knob_range = knob_high - knob_low # 1.7 - -1.3 = 3.0.
out_low = 40.0
out_high = 99.0
out_range = out_high - out_low # 99.0 - 40.0 = 59.0
return (knob_input - knob_low) * (out_range/knob_range) + out_low
# scaled = (input - (-1.3)) * (59/3.0) + 40.0
因为我错过这里最简单的办法是另一种方式把它:
let delta(q) denote the rate of change of some quantity q.
然后你的相关利率
delta(output)/delta(input) = (99 - 40)/(1.7 - 1.3) = 59/0.4 = 147.5
从而
delta(output) = 147.5 * delta(input).
假设这个函数是连续(这意味着你可以随意微小的调整旋钮,而不是离散点击),我们可以整合双方给予:
output = 147.5 * input + some_constant
因为我们知道,当输入为1.3,则输出为40,我们有
40 = 147.5 * (1.3) + some_constant
因此
some_constant = 40 - 147.5 * 1.3 = -151.75
因此,你要的方程是
output = 147.5 * input - 151.75
非常感谢,我需要回到高中并再次参加代数。 :/ – 2010-06-24 01:08:14