我正在編程一個旋鈕,該旋鈕具有一個箭頭,其位置由弧的編號定義。將此數字轉換爲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