tags:

views:

216

answers:

6

I’m programming a knob that has an arrow the position of which is defined from an arc number.

I’m looking to find a way to convert this arc number to a number that will represent a temperature.

The minimum the arc number will be is 1.3 and the maximum will be 1.7.

1.3 needs to equal 40 and 1.7 needs to equal 99.

Is this possible?

+3  A: 

(n - 1.3) * 147.5 + 40

Ignacio Vazquez-Abrams
+3  A: 

Sure, just fit a line to it.

In this case, output = 147.5*input-151.75

zebediah49
Both the answers are correct, but this one gets the result using less operations.
kiamlaluno
How would the function change if the minimum number was -1.3? I forgot to add the negative.
Frankie Laguna
Good old y = ax + b.
Dan
+1  A: 

Simple little show of linear algebra here.

The two variable are the knob position (x) and some constant (p).

the two equations are then

1.3x + p = 40
1.7x + p = 99

Solving the first equation for p in terms of x yields:

p = 40 - 1.3x

If we put that new definition of p into the second equation we can simplify to:

1.7x + 40 - 1.3x = 99
.4x = 59
x = 147.5

Then you can solve for p from either equation. Using the first equation:

p = 40 -1.3*147.5 = -151.75

So your final equation to get temp from knob position should be

temp = 147.5*knobPosition - 151.75
NWilkie
That's what people usually call "algebra", not "linear algebra". You might say it is the algebra of a linear function, sometimes expressed in the form f(x) = mx + b, but it is not linear algebra.
Heath Hunnicutt
+7  A: 

If it's linear, you can use the following formula to allow for any minimum and maximum:

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

The * (to_max - to_min) / (from_max - from_min) bit scales the range from the from range to the to range. Subtracting from_min before and adding to_min after locates the correct point within the to range.

Examples, first the original:

(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)

Then the one using -1.3 as the lower bound as mentioned in one of your comments:

(-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

This answer (and all the others to date of course) assume that it is a linear function. That's by no means clear based on your use of words like "arc" and "knob" in the question. You may need some trigonometry (sines, cosines and such) if it turns out linear doesn't suffice.

paxdiablo
Thanks so much, I need to go back to high school and take Algebra again. :/
Frankie Laguna
+1  A: 

This is really a simple algebra problem, no linear algebra needed.

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
Craig Trader
+1  A: 

Since I missed the easy solution here is another way to think of it:

let delta(q) denote the rate of change of some quantity q.

Then your related rates are

delta(output)/delta(input) = (99 - 40) / (1.7 - 1.3) = 59/0.4 = 147.5

thus

delta(output) = 147.5 * delta(input). 

Assuming that this function is continuous (meaning you can make arbitrarily tiny adjustments to the knob as opposed to discrete clicks) we can integrate both sides giving:

output = 147.5 * input + some_constant

Since we know that when the input is 1.3 then the output is 40 we have

40 = 147.5 * (1.3) + some_constant

Thus

some_constant = 40 - 147.5 * 1.3 = -151.75

Hence the equation you want is

output = 147.5 * input - 151.75
Rodrick Chapman