Machine precision in simulink

4 visualizzazioni (ultimi 30 giorni)
MARCO LORENZI
MARCO LORENZI il 14 Lug 2021
Modificato: dpb il 16 Lug 2021
Good morning everyone.
I am currently working on simulink model.
One of the equations is
"L = qf*(XL0+(XL1*alpha_quadrant))"
where "alpha_quadrant" is constantly zero. "XL0" and "qf" are both constants.
The result of the equation, when graphed, should be constantly -11.08, but as it can be seen in the picture the result keeps fluttering.
Is it because of the machine precision?
  3 Commenti
MARCO LORENZI
MARCO LORENZI il 15 Lug 2021
Thank you for the answer.
So i checked out and "alpha" and "XL0" are constant.
qf is constant until the 14 decimal. Can the last 2 decimal make all that noise? Would it be possible to force the calculation to stop before the 14 decimal?
dpb
dpb il 15 Lug 2021
"All that noise" is also in the 14th decimal place in the output. How can that make any real difference?
Just set
ylim([-10 -12])
on the plot so the tiny little jiggle isn't so amplified and you'd never have noticed it.

Accedi per commentare.

Risposta accettata

Andy Bartlett
Andy Bartlett il 14 Lug 2021
To determine what is happening, a good approach is to log the key signals involved.
Then use MATLAB to investigate the logged values.
I suspect you'll find that either alpha_quadrant isn't always zero or qf is not constant or XL0 is not constant.
The differences in values from what you expect might be very small so you could use some techniques like the following.
format long g % will shows higher precision than short, but can still hide some differences
a = 0.05;
b = a + eps(a);
c = a + 2*eps(a);
v = [c,a,b] % the differences will not be visible in the command window
% converting to a string with 17 digits will be enough to see differences
mat2str(v,17)
% subtracting values is another way to make the differences visible in the
% command window
dv = diff(v)
max(dv)
min(dv)
The output of this code is:
v =
0.05 0.05 0.05
ans =
'[0.050000000000000017 0.050000000000000003 0.05000000000000001]'
dv =
-1.38777878078145e-17 6.93889390390723e-18
ans =
6.93889390390723e-18
ans =
-1.38777878078145e-17
Notice that differences in v are hidden even by format long g.
  4 Commenti
MARCO LORENZI
MARCO LORENZI il 15 Lug 2021
I am really sorry to bother, but i have one last question. I am running the model to simulate aerodynamic forces on a fuselage, which basically means i need "zero" precision. By that i mean that i can calculate them with 2/3 decimals and not 12 (which is where the flutter appears).
Can i ask how can i pratically do what you just said?
dpb
dpb il 15 Lug 2021
Modificato: dpb il 16 Lug 2021
That really isn't what Andy said -- he said, in fact, the obverse -- if you want smaller jiggles on the near constant, you have to actually add more precision, not reduce it.
You can loosen tolerances to get fewer significant digits although if you go too far, solutions may,in fact, diverge from the real solution completely.
Before that point, while your simulation may run faster and will have lower absolute accuracy, it won't be by effectively "zero-ing out" more digits of precsion; the simulation will still be calculated in double precision floating point and so will have the full mantissa; what you'll get will be even more jiggles in your constant up to that level of accuracy you've specified for the solver.
There simply is no such thing as you're thinking of it as being N digits of numeric precision and everything past that identically zero -- in fact, that is in essence infinite precision because you've set a requirement on every digit from the first to as many as you want to name.
You could, I guess, insert an s-function as the output of every block that rounds the result before passing it to the next, but it's futile and pointless to do so...just use the simulation results you get. As noted above, if you were to change the scale on the plot to something realistic about the magnitude of the value itself, you would not even see the jitter and would not have even recognized it as being there.
It just doesn't matter in a practical sense.

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su General Applications in Help Center e File Exchange

Prodotti


Release

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by