roots in Simulink

조회 수: 4 (최근 30일)
Cosmin Darab
Cosmin Darab 2012년 1월 9일
답변: Muhammet Öztürk 2017년 5월 4일
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

채택된 답변

Titus Edelhofer
Titus Edelhofer 2012년 1월 9일
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
  댓글 수: 1
Cosmin Darab
Cosmin Darab 2012년 1월 10일
Thank you Titus
I can use the aprox -z/b, that was a lifesavier :)

댓글을 달려면 로그인하십시오.

추가 답변 (2개)

Titus Edelhofer
Titus Edelhofer 2012년 1월 9일
Hi Cosmin,
up to roundoff error both solutions are fine. If you take the second solution and compute the polynomial within MATLAB:
r2=[-0.005109429866875 -0.000008352927225 -0.000000000000000];
p2=conv(conv([1 -r2(1)], [1, -r2(2)]), [1 -r2(3)])
% what's the difference to p?
p-p2
ans =
1.0e-017 *
0 0 -0.168584041049737 0.017782794100389
So: both solutions are equally "good"...
Titus
  댓글 수: 2
Cosmin Darab
Cosmin Darab 2012년 1월 9일
I don't get it should I use conv function in simulink?
because it's not working
Cosmin Darab
Cosmin Darab 2012년 1월 9일
i get what you are saying but I need a positive root because I use it afterthat in a logarithmic expresion

댓글을 달려면 로그인하십시오.


Muhammet Öztürk
Muhammet Öztürk 2017년 5월 4일
I have got a similar question; I have a code polynomial as
Ka=1.8e-5; Kw=1e-14; sigma=0.0120; ksi=0.0482; %sigma=0.0608; %ksi=0.0406;
Poli=[1 Ka+ksi Ka*(ksi-sigma)-Kw -Kw*Ka]; Hcal = roots(Poli)
Matlab gives the results as correct Hcal =
-0.0482
-0.0000
0.0000
But in simulink function block I take the answer Hcal = -0.0482 + 0.0000i -0.0000 + 0.0000i -0.0000 + 0.0000i
İn simulink I can not take the correct answer. How can I solve this problem.

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by