필터 지우기
필터 지우기

Abs and angle of complex number with symbolic object

조회 수: 3 (최근 30일)
john
john 2013년 3월 4일
Hi,
If r=sym('a')*exp(j*sym('b')) is a symbolic object, and
1. if I write abs(r), I get abs(a).....I need get only "a" without abs
2. if I write angle(r), I get error
??? Undefined function or method 'atan2' for input arguments of type 'sym'.
Error in ==> angle at 14 p = atan2(imag(h), real(h));
Can you help me please? How can I solve this?

채택된 답변

Walter Roberson
Walter Roberson 2013년 3월 5일
There is no "complex argument" function for symbolic variables exposed at the MATLAB level. You can, though, define
arg = @(V) feval(symengine, 'arg', V);
  댓글 수: 3
john
john 2013년 3월 7일
Did you mean this code
r=sym('a')*exp(j*sym('b'));
arg = @(r) feval(symengine, 'arg', r);
number=arg(r);
????
But I got again error
??? Undefined function or method 'atan2' for input arguments of type 'sym'.
Error in ==> angle at 14 p = atan2(imag(h), real(h));
Btw, what is better to use, atan or atan2 in form "P = 2 * atan( (sqrt(X.^2 + Y.^2) - X) ./ Y )";
Thank you

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

추가 답변 (1개)

Brian B
Brian B 2013년 3월 4일
편집: Brian B 2013년 3월 4일
Well, for part 1 you have to assume a is a non-negative real:
syms a
assume(a>0)
Then
>> abs(a)
ans =
a
I have not tried the second part, but you can imagine dividing by the magnitude and taking a log....
  댓글 수: 6
Brian B
Brian B 2013년 3월 4일
편집: Brian B 2013년 3월 4일
Try
a = sym('a','positive')
b = sym('b','real')
That works for me in R2011b, including computing the magnitude of r. I don't see a good way to get the argument, though.
john
john 2013년 3월 5일
Tanks, but It doesn't help for angle(r)

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by