- 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?
조회 수: 531 (최근 30일)
이전 댓글 표시
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
2023년 2월 13일
편집: MathWorks Support Team
2023년 2월 13일
이 답변에 Will
님이 플래그를 지정함
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 never feed zero to a division block.
Two possible workarounds are as follows. 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)
The second workaround is demonstrated in the attached model 'example_no_divide_by_zeroFcn'.
댓글 수: 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에서 Simulink Functions에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!