I'm trying to write a function that fits a value to a model.
I have a measurement from a pressure sensor and using a calibrated model I have to convert the value into the final pressure management. Doing so involves raising the measurement to a fractional power, in this case x^2.032.
I'm writing this in Mecrisp Stellaris, a dialect of Forth.
I'm a bit stuck. I understand 2.032 = 254/125, but is there a cleaner way to write things than to simply take a huge power and a huge root?
If your language (or calculator) has square-root, then ypu can use that to compute any power. Of course if the language has a power function, it would be better (simpler, faster, more accurate) to use that.
For example to compute
we first expand 2.032 as a binary fraction (for example by looking at it in floating point in hex) as
Thus
We can compute
by starting with x and taking 5 square roots in succession. The general method is to loop over the binary expansion of 2.032, taking square roots, and accumulating into the answer when the binary digit is 1