Abs and angle of complex number with symbolic object

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?

 Respuesta aceptada

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 comentarios

john
john el 5 de Mzo. de 2013
Sorry, I realy don't understand, what makes code arg = @(V) feval(symengine, 'arg', V);....what means V and how can I use that code
john
john el 7 de Mzo. de 2013
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

Iniciar sesión para comentar.

Más respuestas (1)

Brian B
Brian B el 4 de Mzo. de 2013
Editada: Brian B el 4 de Mzo. de 2013
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 comentarios

You may also have to
assume(b,'real')
john
john el 4 de Mzo. de 2013
Editada: Walter Roberson el 4 de Mzo. de 2013
For code
syms a
assume(a>0)
I got error
??? Error using ==> sym.sym>notimplemented at 2653
Function 'gt' is not implemented for MuPAD symbolic objects.
Error in ==> sym.sym>sym.gt at 801
notimplemented('gt');
What version of the Symbolic Math Toolbox do you have?
ver('symbolic')
john
john el 4 de Mzo. de 2013
Hi,
Symbolic Math Toolbox Version 5.6 (R2011a)
Brian B
Brian B el 4 de Mzo. de 2013
Editada: Brian B el 4 de Mzo. de 2013
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 el 5 de Mzo. de 2013
Tanks, but It doesn't help for angle(r)

Iniciar sesión para comentar.

Etiquetas

Preguntada:

el 4 de Mzo. de 2013

Community Treasure Hunt

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

Start Hunting!

Translated by