- Use a 'switch' block to pass 'eps' instead of 'u' to the 'divide' denominator. The 'switch' must only be activated when the signal 'u' is zero.
- Use a 'MATLAB Function' block to implement a zero-avoiding condition, such as:
How can I avoid errors due to division by zero in Simulink?
470 次查看(过去 30 天)
显示 更早的评论
MathWorks Support Team
2012-3-13
编辑: MathWorks Support Team
2024-7-15,19:12
I am using a simple model in Simulink in which I use a division on two input values using a 'Divide' block.
During my simulation, there might be a zero value fed to the denominator of the 'Divide' block. This often causes a warning, an error message, or erroneous results.
How can I avoid these problems?
采纳的回答
MathWorks Support Team
2024-7-15,0:00
编辑:MathWorks Support Team
2024-7-15,19:12
Numerical division by zero is a common issue in programming, and its exact solution often depends on the particular application. In almost all cases, the best approach is to change the model to never feed zero to a division block.
An example of a workaround is shown below. For clarity purposes, let us call the original signal in the denominator as 'u'.
u + (u==0)*eps
or, if the signal 'u' is real:
u + eps*(0^u)
1 个评论
更多回答(1 个)
madhan ravi
2024-1-10
Or making the result to be zero when the divisor is zero using a Switch block
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 General Applications 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!