MATLAB Answers

Is it possible to avoid division by zero errors in a Simulink model, such that the results from a simulation are stable when using Simulink 7.7 (R2011a) ?

540 views (last 30 days)
I am using a simple model in Simulink in which I use a Divide operation on two input values and further plot them. In course of simulation, there might be a ZERO value fed to the denominator of the DIVIDE block, forcing a division by zero warning/error message. This makes the simulation unstable.

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 13 Mar 2012
In order to "solve" the divide by zero issue, there is only one good way.It is to make a model which does not feed 0 to a division block.
The workarounds are to:
1. Use a SWITCH block to pass EPS instead of 0 in the forward path to the DIVIDE block will also eliminate a divide by zero case.
2. Use a MATLAB Fcn block to implement
This is demonstrated in the attached model 'example_no_divide_by_zeroFcn'


Kevin Goh
Kevin Goh on 4 Aug 2014
Hi Beria samia, i found that MATLAB Fcn block is not supported by my Simulink coder, so I have to resort to solution #1.
So I first key in 'eps(0)' in the MATLAB command prompt to get the approximated floating point value of 0, the I used that value for a constant block, which is switched over when the devisor is 0. It works.
cheers, Kevin

Sign in to comment.

More Answers (2)

Ajith Tom George
Ajith Tom George on 2 Oct 2017
Instead of using a Matlab function block, the "Fcn" block, which is also available in the list of User-defined functions, would be better. Inside it implement the same logic:
Using Fcn block is better because it works without any additional compiler requirement.


Sign in to comment.

Shivaprasad G V
Shivaprasad G V on 6 Mar 2019
this would be helpful to avoid the 0/0 or n/0 situation. this below block prevents the formation of indeterminent form. hope this will be helpful. thank you. zero.PNG


Sign in to comment.

Sign in to answer this question.


No tags entered yet.