MATLAB: Most efficient Quadratic Implementation in Simulink

compileefficiencyoptimalquadraticsimulink

Hi,
A general question that comes up occasionally at work is; What is the best way to implement a simple equation in Simulink?
For example, if I need to implement a quadratic equation, am I best doing this using a number of gains, product and add blocks separately, using a dedicated block like the polynomial, or using a fcn (or even Matlab fcn) block?
I generally make the decision based on other factors such as clarity and ease of use, but is there an optimal solution for fastest simulations, or do they compile down to be identical anyway?
Regards, Tom

Best Answer

You can see a number of the optimizations that are performed in the Configuration Parameters -> Optimizations tab.
For modeling anything I would avoid using a MATLAB Fcn block as this will limit your ability to utilize things that involve code generation (this includes accelerator/rapid accelerator).
Unfortunately I do not believe there is an easy answer for the general questions posed. It really depends on what you are modeling, what your goals are and the effects of Simulink optimizations such as block reduction.