フィルターのクリア

Why does the function real return expressions containing i ?

1 回表示 (過去 30 日間)
Qingbin
Qingbin 2013 年 3 月 28 日
For the following code, CEre is derived using the real function, but it contains i in the expression.
clc;clear all;
syms s;
syms T1 T2 w tau1 tau2 real;
e1=(1-T1*s)/(1+T1*s);
e2=(1-T2*s)/(1+T2*s);
A=[0 1 0 0;
0 0 1 0;
0 0 0 1;
-29.17 -56 -36.7 -10.1];
B1=[-1.55 1 0 0;
-1 -0.3 0 0;
0 0 0.5 0;
-0.7 0 -0.34 -2.6];
B2=[0 0 0 0;
1 1.5 4 0;
0 0 0 0;
-0.33 0 0 -1.1];
B3=[0 0 0 0;
0 0 0 0;
0 0 0 0;
-0.08 -0.7 0 -1];
B4=zeros(4,4); B4(4,3)=-3;
n=size(A,1);
tau3=0.169; tau4=0.26;
cez=numden(simplify(det(w*1i*eye(n)-A-B1*e1-B2*e2-B3*(cos(tau3*w)-1i*sin(tau3*w))-B4*(cos(tau4*w)-1i*sin(tau4*w)))));
% ce=collect(cez,s);
cew=subs(cez,s,w*1i)
CEre=real(cew);
CEim=imag(cew);
After commenting off the function collect, the function real gives a result without the unity of complex i.

回答 (2 件)

Walter Roberson
Walter Roberson 2013 年 3 月 28 日
I have not tried the above code, but consider
syms w
real(w*1i)
The result may contain "i" because it is possible that w is complex itself.
In this particular case, the result could also be expressed as imag(w), but there are other cases that are more difficult to resolve, such as
real((w + 1i)^2)
  1 件のコメント
Qingbin
Qingbin 2013 年 3 月 29 日
編集済み: Walter Roberson 2013 年 3 月 29 日
syms T1 T2 w tau1 tau2 real
In the code above, it is defined that w is real. So
real(w*1i) = 0
In fact, using the code above, all the variables are real.

サインインしてコメントする。


Ahmed A. Selman
Ahmed A. Selman 2013 年 3 月 28 日
編集済み: Ahmed A. Selman 2013 年 3 月 29 日
Check the math, e.g.:
...
TheEq=w*1i*eye(n)-A-B1*e1-B2*e2- B3*(cos(tau3*w)-1i*sin(tau3*w))-B4*cos(tau4*w)-1i*sin(tau4*w);
TheDet=det(TheEq);
TheSimple=simplify(TheDet);
cez=numden(TheSimple);
...etc
Then see what do
TheSimpleEq=simplify(TheEq);
pretty(TheSimpleEq)
give.
Why do you use (1i) instead of (i) only? If it is not declared before, then (i or j) alone are assumed a unity of complex in Matlab.
  3 件のコメント
Ahmed A. Selman
Ahmed A. Selman 2013 年 3 月 29 日
If someone wrote a code, he shouldn't have to worry about accidents :)
Walter Roberson
Walter Roberson 2013 年 3 月 29 日
Be safe, program defensively. And make it easier for other people to read.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeSymbolic Math Toolbox についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by