Guy and Seth on Simulink

Detecting Divide by Zero Errors 3

Posted by Guy Rouleau,

Wouldn't it be great if you could analyze a Simulink model and certify that it will never encounter design errors like divisions by zero and overflows? Since MATLAB R2011a, this is possible!

This week, my friend Nishaat Vasi introduces this new feature of Simulink Design Verifier

Detecting Design Errors with Simulink Design Verifier

Nishaat Vasi, guest blogger and divide by zero detector Imagine driving a new prototype of a car on a test track at 100mph when a division by zero error in the embedded design causes an unwarranted transmission shift to first gear. Even a car enthusiast would not want to be the test-track driver in such a scenario! Such errors in design logic and math operations can be easily detected in your Simulink models without requiring extensive tests or simulation runs.

Consider a small section of a controller model that has an input bus which I defined in the MATLAB workspace:

Controller example model

This model simulates fine for my set of inputs in the InBus declaration, but I wanted to be sure that it will not cause any dynamic execution errors. I used the new Detecting Design Errors option of the Simulink Design Verifier as follows:

Detect Design Errors

The tool highlights the analysis results on the model making it much easier to debug potential issues:

Summary of design detection

For each block with an error (red), Simulink Design Verifier calculates signal-range boundaries and generates a test vector that reproduces the error in simulation. Using this test case made it easy for me to identify what set of inputs cause an error and engineer a defensive mechanism to avoid this scenario. As you may notice, green highlighting indicates that the block does not produce a design violation. Design errors detected include dead logic, integer overflow, division by zero, and violations of design properties and assertions. This information can then be used to either improve the design and its requirements or guide the simulation for debugging and validation.

To learn more about the technology, you can visit How does Simulink Design Verifier identify design errors? or check out the Product Overview video:

Overview Video of Simulink Design Verifier

This new R2011a feature could save you huge amounts of time, effort, and money in debugging design errors – even before running a simulation!

Now it's your turn

What do you think of the Design Error Detection feature? Did you encounter such design error in the past? Leave us a comment here.

3 CommentsOldest to Newest

What is the standard approach to eliminating a divide by zero error? I am getting it at the first time step, yet setting an initial condition does not eliminate it.

@KE, I am not sure if there is one “standard” option. I guess this depends on your application. For example, I have seen:

- Use one of the technique described here to use an alternate algorithm when the value to be divided is close or equal to 0.

- If you are getting this at the first time step, maybe it would be possible to use different initial conditions? (not the IC block, but initial conditions in Delays and Integrators)

Add A Comment

What is 4 + 9?

Preview: hide

These postings are the author's and don't necessarily represent the opinions of MathWorks.