linear function with decimals

giuseppe

Member
Hello all!

So, the question is can I express the function f(x) = 0.0206x + 0.2867? I have been trying to think of a way of doing it but I do not think it is easy, or even possible with decent accuracy. The domain of x belongs to the set {0,1,2,3,....6000}. The range belongs to the set {0,1,2,3,....124}.

I need this because this equation converts frequency from the VSS wire of a 2003 Acura TL to miles per hour. I know the function is accurate as I actually computed the values in excel and "hard coded" it to the picaxe by using a painfully long select...case code block. Then I interfaced the picaxe to the VSS wire, found the frequency of the signal, used my select...case conversion table, and outputted the result to a LCD screen. I was able to read the speed from 0-99 very accurately :)

As you guys can imagine, the select...case code block was a memory hog (1730 bytes of program memory to be exact). I tried to look up on how I could multiply by a decimal, and the closest I got was winding up on the parallax website. I read there that the operator */ could be used to achieve close to floating point calculation and the X1 and X2 parts have this operator I think so I guess I could use this "trick". Admittedly, I did not fully understand how I could use the */ operator to do this.

Anyone got any good hints?
 

Armp

Senior Member
If you need more precision try:

w1 = w1/33 + w1*2 + 28 ( gives results in 1/100ths.)

Clue: 2 (1 + 1/33 ) = 2.0606
 

giuseppe

Member
Wow this is pretty close and will probably work for my needs. How did you come up with this equation?
Ah I see what you did now, you just used the slope and you dropped the y-intercept. And 10/483 is 0.0207. Seeeee, I was going to try that but I didn't think the results were good but after actually look at it (comparing the two graphs in excel) it works fine!

But yeah, even though my problem is pretty much solved, anyone know how to multiply by a decimal by the */ operator? I think it would good know.
 

marks

Senior Member
Hi giuseppe,
sometimes i find these things interesting to do lol
hope you try it !

W1=W1+38*2 :W1=W1*3/100+W1/100

I think it will be as good as your select case code that i noticed you posted
extra info does help greatly and could see you wanted something more accurate
ive added the offset you need (as i can see your a fussy bugger, like me lol)
the first try was a ruffy just based on 124 / 6000
 
Top