Which exponential option block: fcn vs math function, is more accurate in a Simulink model?

29 views (last 30 days)
Hi all.
I have a vector 'p' of 388 values and 2 constant values (fc and b). I want to get '(p/fc)^b'
First I applied the fcn block (u/fc)^b where u=p. Also I applied the math pow block with a gain block as figure attached. When I compare both, the second option results are greater than the fcn block. Even the difference is small I would like to know which option is more accurate or recommended and if possible the reason of that small difference.
  1 Comment
Malay Agarwal
Malay Agarwal on 30 Dec 2024 at 14:22
I think both the methods should be roughly equal and the differences you are noticing are because of how floating-point operations work. Due to how floating-point operations work, there can be small differences in the results of the same operation when the operation is done multiple times.
The following resource has more details about how floating-point numbers behave: https://docs.oracle.com/cd/E19957-01/806-3568/ncg_goldberg.html.
But I recommend comparing the output of both the methods with different external sources such as WolframAlpha to determine which method yields a more consistent result.

Sign in to comment.

Accepted Answer

Paul
Paul on 30 Dec 2024 at 14:58
In general u/fc (top path), is not exactly the same as u*(1/fc) (bottom path) in floating point.
Example:
rng(100)
u = rand;
fc = rand;
isequal(u/fc,u*(1/fc))
ans = logical
0
u/fc - u*(1/fc)
ans = -2.2204e-16
Try making the top path in the fcn u*(1/fc) or (1/fc)*u and see if that matches the bottom. Alternatively, use the Divide block to divide u by fc in the bottom path (instead of the gain) to see if that matches the top.

More Answers (0)

Products


Release

R2024a

Community Treasure Hunt

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

Start Hunting!