MATLAB: Roots in Simulink

MATLABsimulink

hy, I'm having some differences between matlab and simulink when using function roots():
"p=[1 xc b z]; xc= 0.005117782794100; b= 4.267869584093415e-008; z= -1.778279410038923e-019; roots(p);"
in matlab the result is: -0.005109429866868 -0.000008352931399 0.000000000004167
and in simulink(i put the code in a embeded matlab function): -0.005109429866875 -0.000008352927225 -0.000000000000000 I have to use the positive root but simulink does not have one. Am I doing something wrong? Does Simulink use diferent compiler? Thank you

Best Answer

Hi Cosmin,
I took a look at the implementation of roots for the Embedded MATLAB Function block (<matlabroot>\toolbox\eml\lib\matlab\polyfun\roots.m). It's stated there:
% Limitations:
% Output is always variable size.
% Output is always complex.
% Roots may not be in the same order as MATLAB.
% Roots of poorly conditioned polynomials may not match MATLAB.
The last sentence is what makes you the headache (and yes, your polynomial is badly conditioned!). If you take a look at the plot you will see, that the curve hardly touches the x-axis.
I have a suggestion though: the value -z/b is a (very) good approximation of the root you are looking for ...?
Titus