Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.
|
Forum Index : Microcontroller and PC projects : Should I fly to the moon using the cmm2 as flight computer?
Page 1 of 3 | |||||
Author | Message | ||||
andreas Senior Member Joined: 07/12/2020 Location: GermanyPosts: 207 |
There is a funny result when calculating trigonometric functions using the cmm2. The results are not only not zero as expected but they differ when doing the calculation either within a for..next loop or step by step: print "within For .. Next" for i = 18 to 20 print "i=";i,"cos(pi/2)*10^i";cos(pi/2)*10^i next i print "as separat statements" print "print cos(pi/2)*10^18 =",cos(pi/2)*10^18 print "print cos(pi/2)*10^19 =",cos(pi/2)*10^19 print "print cos(pi/2)*10^20 =",cos(pi/2)*10^20 print "cos(pi/2) should be 0 anyway" -andreas .. and a happy new year! Edited 2024-01-01 02:31 by andreas |
||||
Mixtel90 Guru Joined: 05/10/2019 Location: United KingdomPosts: 6792 |
I get cos(pi/2) to be 6.093216209e-17 on a PicoMite VGA running 5.0707. It's pretty small. :) Happy New Year! Mick Zilog Inside! nascom.info for Nascom & Gemini Preliminary MMBasic docs & my PCB designs |
||||
matherp Guru Joined: 11/12/2012 Location: United KingdomPosts: 9118 |
double precision math has about 16 digits of precision so all you are doing is exposing the limits of that precision by scaling the error component - nothing interesting or wrong |
||||
JohnS Guru Joined: 18/11/2011 Location: United KingdomPosts: 3802 |
Why are the results for i = 19 and an explicit 19 not the same? (And similarly for 20?) John |
||||
matherp Guru Joined: 11/12/2012 Location: United KingdomPosts: 9118 |
Because it has added 1.0 each time and 3.0 cannot be exactly represented (amongst others) |
||||
andreas Senior Member Joined: 07/12/2020 Location: GermanyPosts: 207 |
I could imagine to use a "preprocessor" which replaces expressions like 'cos(pi/2)' or 'tan(pi)' by "0" syntactically before evaluating the expression mathematically. -andreas small is beautiful! |
||||
Mixtel90 Guru Joined: 05/10/2019 Location: United KingdomPosts: 6792 |
OTOH you could simply use zero rather than expression to get it. :) Mick Zilog Inside! nascom.info for Nascom & Gemini Preliminary MMBasic docs & my PCB designs |
||||
TassyJim Guru Joined: 07/08/2011 Location: AustraliaPosts: 6098 |
The for loop is using floats because that is the default. Try adding OPTION DEFAULT integer and the results for the loop and individual are the same. Likewise, if you leave the for loop as floats and change the 18 19 and 20 to 18.0 19.0 20.0 the results are both derived from floats. Jim VK7JH MMedit MMBasic Help |
||||
lizby Guru Joined: 17/05/2016 Location: United StatesPosts: 3150 |
Good point. You can also add DIM INTEGER i and get identical results. PicoMite, Armmite F4, SensorKits, MMBasic Hardware, Games, etc. on fruitoftheshed |
||||
phil99 Guru Joined: 11/02/2018 Location: AustraliaPosts: 2135 |
They did fly to the moon with a flight computer far less capable than the CMM2. Trying to achieve 20 digit accuracy in a real world where nothing is precise is of no value. The key is repeated measurement, feedback and correction. |
||||
andreas Senior Member Joined: 07/12/2020 Location: GermanyPosts: 207 |
When I could identify it - yes! But in real world problems the arguments are variables and it is not obvious how they are calculated. there may be very large or very small values or pi/2 ;-) That means to solve a problem correctly one does not only have to know the right formula but also a save way to compute it with an calculator which has only discrete states (limited number of bits within mantissa and exponent) and may be faulty if very large or very small values occur during computation which can not be represented within the calculating machine. When there are loops, small errors may generate large errors. -andreas |
||||
Mixtel90 Guru Joined: 05/10/2019 Location: United KingdomPosts: 6792 |
I don't see how you can get round that, apart from forcing high and low limits for the variable in your program. Multiplying the error doesn't help. :( Or do everything in multiples of integers. Don't use floating point more than you absolutely have to. This used to be the standard way to avoid errors currency calculations, I believe. Edited 2024-01-01 08:49 by Mixtel90 Mick Zilog Inside! nascom.info for Nascom & Gemini Preliminary MMBasic docs & my PCB designs |
||||
andreas Senior Member Joined: 07/12/2020 Location: GermanyPosts: 207 |
Yes, one can learn from FORTH programming language that integer calculation is superb in regard of precision. example for two different ways to calculate a result: 2 * 3 * 4 * 5 * 6 720 ----------------------- = 2 (if you see it) or you calculate ----- = 2 3 * 4 * 5 * 6 360 By first calculating 3/3 = 1 and 4/4 = 1 and 5/5 = 1 and 6/6 = 1 there is only 2 left as factor different from 1 on the left side. On the right side you possibly have to compute very large numbers and then to divide them which is more error prone. -andreas |
||||
zeitfest Guru Joined: 31/07/2019 Location: AustraliaPosts: 482 |
(deleted post ) Edited 2024-01-01 09:09 by zeitfest |
||||
EDNEDN Senior Member Joined: 18/02/2023 Location: United StatesPosts: 118 |
So.... How many digits of precision do we need to accurately plot a course to the moon and establish orbit? I would think 15 digits of precision should be enough? Of course you would want to structure the calculations to not lose any precision, but certainly 15 digits of precision can get you to the moon???? Edited 2024-01-01 12:15 by EDNEDN |
||||
PhenixRising Guru Joined: 07/11/2023 Location: United KingdomPosts: 862 |
But then they "lost the technology" As one does. Maybe the CMM2 is the new solution |
||||
EDNEDN Senior Member Joined: 18/02/2023 Location: United StatesPosts: 118 |
Besides losing all the technology... They lost all of the videos and pictures. It kind of sounds like "The dog ate my homework." excuse to me. |
||||
PhenixRising Guru Joined: 07/11/2023 Location: United KingdomPosts: 862 |
"Hey did anyone grab the how-to-go-to-the-moon file-folder off-of Fred's desk? It was there just this morning" |
||||
Bryan1 Guru Joined: 22/02/2006 Location: AustraliaPosts: 1344 |
yea tell me about it afterall all I'm looking from my CMM2 is one small step then off to the moon this cnc will go |
||||
swoodgate Newbie Joined: 24/11/2011 Location: AustraliaPosts: 14 |
Check out Arbitrary-precision arithmetic libraries for solutions to this problem. Steve |
||||
Page 1 of 3 |
Print this page |