フィルターのクリア

roots in Simulink

11 ビュー (過去 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 Center および File ExchangeString についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by