Go Down

Topic: Large numbers / polynomial maths (Read 544 times) previous topic - next topic


Aug 25, 2015, 10:52 am Last Edit: Aug 25, 2015, 10:52 am by GoForSmoke
It's for people who never got algebra.

Or arithmetic.
Or basic numeracy skills.
Those damned bundles of pencils. When's recess?
Nick Gammon on multitasking Arduinos:
1) http://gammon.com.au/blink
2) http://gammon.com.au/serial
3) http://gammon.com.au/interrupts


Firstly many thanks for the vast number of detailed and very helpful replies - there are too many to quote in detail so ill try and reply/comment to the average of the comments.

Of greatest interest is the table idea - ive not tried this but it would be very easy to produce in excel with my equation applied and use excel to format for pasting into the code.

I shall not clutter this post asking how to do it as ill need to read up and try a few things first to get to grips with it.

As always, i try to work on the theory "nothing is impossible", combined with "somebody must have asked this question before" and the answers are generally always there!

The "loss of significance" is new to me as a term but i fully get what it means and i beleive this is whats affecting the repeatibility.

This was why i mapped the 0-1024 to a smaller/narrower range of numbers to try to get the coefficients and their sub-results within a calculable range without being too big or too small.

I pull everything out via serial and if, in excel, i flow through from 0-1024 to my mapped range and apply the formula then i get the correct and repeatable results so i know everything except the main calculation is correct.

The guts of the code which does the calc looks like this:

Code: [Select]
 if (SetMLL < mVMeasured < SetMHH)
    BiasCurve = (x3 * mVMeasured * mVMeasured * mVMeasured) + (x2 * mVMeasured * mVMeasured) + (x * mVMeasured) + c;

before and after this i have statements to govern the output when the result is below the "LL" [=LowLow] point or above the "HH" [=HighHigh] point.

I hear all that's said about avoiding unnecessary conversions and i would normally just try to work with the ADC values but they produced coefficients which were crazy.

Ill try the lookup table and report back how i get on.

Speed is not an issue, i need perhaps a 1-2sec response time so even ms is fine.

Thanks again to all.


Code: [Select]
if (SetMLL < mVMeasured < SetMHH)
If true (SetMLL is less than mVMeasured) or false (SetMLL is greater than or equal to mVMeasured) is less than SetMHH, do something. That's not really what your code looks like, is it?
The art of getting good answers lies in asking good questions.


Why even use a polynomial in the first place?

And what is your idea of a "calculable range"?



Just an update - i have used the lookup table method and its working perfectly.   i get the result required/expected every time.   The program is also more reliable and has been running for a few days without hanging.

I think i do have some of my "if" statements wrong as PaulS has alluded to but im working on these things since the guts of it is working fine.

Odometer, the polynomial had been formed in excel after experimental results were looked at.   I had thought a neat solution was to have the arduino just calculate each time however the table idea suggested by others was much more practical.

By calculable range i was meaning using alternative numbers caused me to have numbers which resulted in grossly inaccurate ranges.   Take the x^3 parameter of 15.625.   A small change in range of input data made this become a tiny number (looking back it was 0.0000000012647552) which the float maths gave inaccurate results from.  Another change pushed it to a huge number (probably around 15,625,000,000 ) in the calculation which i think was too big.    All the prescaling was to get the numbers into a "Goldilocks" range which worked reasonably well.     What has been spot on is to let Excel & many Xeon cores to do the hard work and let the Arduino work within its comfort zone!

After logging for a few days i am seeing "out of range" spikes which i need to filter out but ill post separately if i cant find a solution on that as its very different to the subject of this post.

Thanks once again for the help.

Go Up

Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

via Egeo 16
Torino, 10131