# 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.

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
u+(u==0)*eps
This is demonstrated in the attached model 'example_no_divide_by_zeroFcn'

Beriah samia on 4 Feb 2014
how to use a switch block and what is "EPS"
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
Walter Roberson on 2 Oct 2017
At one time, MATLAB Fcn Block was called "Embedded MATLAB Block"

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:
u(1)+(u(1)==0)*eps
Using Fcn block is better because it works without any additional compiler requirement.

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.