simulink add block wrong output
1 view (last 30 days)
Show older comments
Hello, this is my simulink model
and I cannot understand why my add block output wrong answer
How can I fix it?
0 Comments
Answers (2)
Nikhilesh
on 23 Jan 2023
This looks like an issue of Variable solver. Please have a look at the following discussion
0 Comments
Paul
on 23 Jan 2023
Edited: Paul
on 23 Jan 2023
Hi 기범
I think the issue here is mixing together different fixed point data types. Using R2021b
Here's the model, with the data types show on the signal line (Debug -> Information Overlays -> Ports -> Base Data Types)
We see that the inputs to the sum block are all different fixed point data types, which then are added by the sum block to result in some other fixed point type, and the bit pattern of that apparently results in the display of -4.
The fix is to either get the sum block to promote all of the inputs to a common data type that yields the expected result, or change the model so that all of the inputs to the sum block are the same data type that can correctly represent the result. For an example of the former, I added a Data Type Conversion Block to the top line to force a conversion to double. Apparently the sum block the promotes the other three inputs to double using their values before adding and we get the expected answer
Note the output of the sum block is now double. We could also put the DTC block on all four inputs to the sum block, or modify one or more of the four gain block to force their outputs to double via the Ouput data type on the Signal Attributes tab. Or, you can force the Output data type on the Signal Attributes tab of the sum block to double (there are other valid options if you want something other than double); that seems to work as well.
0 Comments
See Also
Categories
Find more on Sources in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!