Machine precision in simulink

Illustration
Andy Bartlett - 2021-09-07T15:27:10+00:00
Question: Machine precision in simulink

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.

Expert Answer

Profile picture of Kshitij Singh Kshitij Singh answered . 2025-11-20

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
     


Not satisfied with the answer ?? ASK NOW

Get a Free Consultation or a Sample Assignment Review!