Effacer les filtres
Effacer les filtres

How can I avoid errors due to division by zero in Simulink?

485 vues (au cours des 30 derniers jours)
MathWorks Support Team
MathWorks Support Team le 13 Mar 2012
Modifié(e) : MathWorks Support Team le 15 Juil 2024 à 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?

Réponse acceptée

MathWorks Support Team
MathWorks Support Team le 15 Juil 2024 à 0:00
Modifié(e) : MathWorks Support Team le 15 Juil 2024 à 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'.
  1. 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.
  2. Use a 'MATLAB Function' block to implement a zero-avoiding condition, such as:
       
u + (u==0)*eps
        or, if the signal 'u' is real:
u + eps*(0^u)
  1 commentaire
Walter Roberson
Walter Roberson le 2 Oct 2017
At one time, MATLAB Fcn Block was called "Embedded MATLAB Block"

Connectez-vous pour commenter.

Plus de réponses (1)

madhan ravi
madhan ravi le 10 Jan 2024
Or making the result to be zero when the divisor is zero using a Switch block

Catégories

En savoir plus sur General Applications dans Help Center et File Exchange

Produits


Version

R2022b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by