How can I increase the numerical precision of my calculations?

36 Ansichten (letzte 30 Tage)
Matthew Ryan Noyes
Matthew Ryan Noyes am 1 Mai 2019
Kommentiert: James Tursa am 2 Mai 2019
I'm trying to calculate the analytical derivative of a line generated by an orbital model. This line describes the position of a space craft as a function of time. In order for this line to precisely describe its motion, I had to make the time step between each point extremely small. When performing the analytical derivative, I took two adjacent positions in time, subtracted them, and divided by the time step. However, the difference in position of two adjacent points in time is smaller than the 16 digit precision MATLAB uses in calculations, so the difference was rounded to zero. The consequence of this was that the derivative of a positively sloped line was zero which is incorrect.
For example: MATLAB outputs these two answers for these two inputs:
1/1.0001 = 0.9999000099990000999900009999000099990000999900009999000099990000999900009999000099990000999900009999 (good!)
1/1.0000000000000001 = 1.0 (bad!)
How do I have MATLAB perform calculations to a precision higher than 16 digits?
For more context on my problem, I'm an optical science researcher on Breakthrough Starshot which is a program to send nano-spacecraft to Proxima Centauri. The code I'm writing is being used to study the motion of the nanocraft at extremely large distances moving at speeds that are fractions the speed of light. Higher numerical precision will be necessary to accurately determine these motions.
  1 Kommentar
James Tursa
James Tursa am 2 Mai 2019
The solution to your problem isn't to use extremely tiny step sizes on a system with limited precision. Instead, you need to use better methods to solve your problem (and maybe even then you will need higher precision). What those methods would be depends on the problem you are solving, but I don't think we know enough yet to advise you.
For instance, you talk about calculating an "analytical derivative", but then turn right around and start talking about taking position differences divided by delta times which is a numerical derivative. So what is it that you are really trying to do, and what is the larger picture of what you are trying to solve? Normally I would have expected you were starting with a force model (gravity, etc) and then integrating that into a position trajectory, but it sounds like you have the reverse ... you are starting with a position trajectory and then trying to derive velocity or acceleration from that. So I am a bit confused as to what you are doing.

Melden Sie sich an, um zu kommentieren.

Antworten (1)

John D'Errico
John D'Errico am 1 Mai 2019
NO. MATLAB does NOT output this:
1/1.0001 = 0.9999000099990000999900009999000099990000999900009999000099990000999900009999000099990000999900009999 (good!)
That is simply not true. If you use the symbolic toolbox, (or my own HPF toobox) you can get that, IF the numbers are stored in the proper class variables.
But MATLAB does not allow longer than double precision in basic computations. And the numbers 1 and 1.0001 are both doubles. So the ratio you show has a double as a result.
If you need higher than a double, then you need to use either HPF or the symbolic toolbox. In many cases however, simply good mathematical practices are sufficient. This is why we have courses in numerical analysis, as well as hundreds of texts on the subject.

Kategorien

Mehr zu Simulink finden Sie in Help Center und File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by