Thread Subject: syntax for polar complex numbers

Subject: syntax for polar complex numbers

From: Thomas

Date: 3 Nov, 2009 16:41:03

Message: 1 of 10

Anyone know what the syntax is for a polar complex number? I don't see anything about that in the help or in previous newsgroup postings.

Let's say I have a voltage with a magnitude of 1 p.u. and an angle of 0.0045 radians, and I want to input that as a complex phasor (a complex number with the same magnitude and phase angle) so that I can do some complex number computations. How would I do that?

Obviously I can convert it to rectangular format in input it as X + Yi, but that is very inconvenient. Is there a way to input it directly as a polar complex number?

Thanks,
Tom

Subject: syntax for polar complex numbers

From: Matt

Date: 3 Nov, 2009 16:51:02

Message: 2 of 10

"Thomas " <loparna2000.removethis@yahoo.com> wrote in message <hcpmeu$h1o$1@fred.mathworks.com>...
> Anyone know what the syntax is for a polar complex number? I don't see anything about that in the help or in previous newsgroup postings.
>
> Let's say I have a voltage with a magnitude of 1 p.u. and an angle of 0.0045 radians, and I want to input that as a complex phasor (a complex number with the same magnitude and phase angle) so that I can do some complex number computations. How would I do that?
>
> Obviously I can convert it to rectangular format in input it as X + Yi, but that is very inconvenient. Is there a way to input it directly as a polar complex number?


input it to what?

Subject: syntax for polar complex numbers

From: Thomas

Date: 3 Nov, 2009 17:05:19

Message: 3 of 10

"Matt " <xys@whatever.com> wrote in message <hcpn1m$on9$1@fred.mathworks.com>...
> "Thomas " <loparna2000.removethis@yahoo.com> wrote in message <hcpmeu$h1o$1@fred.mathworks.com>...
> > Anyone know what the syntax is for a polar complex number? I don't see anything about that in the help or in previous newsgroup postings.
> >
> > Let's say I have a voltage with a magnitude of 1 p.u. and an angle of 0.0045 radians, and I want to input that as a complex phasor (a complex number with the same magnitude and phase angle) so that I can do some complex number computations. How would I do that?
> >
> > Obviously I can convert it to rectangular format in input it as X + Yi, but that is very inconvenient. Is there a way to input it directly as a polar complex number?
>
>
> input it to what?

Let's say I want to computer the division of the following complex numbers:

V = (1.01<0.002radians) (where "<" is my makeshift angle symbol)
X = 1+3i

I acutally don't want to assign variables and such and such. I know I could go through a long tortured procedure where I assign the magnitude and angle of V to different variables and use them to calculate the real and imaginary components of V. That is way over the top for what I want to do. What is the EASIEST way to accomplish this division?

I'm thinking about my HP 48g, where I would do the following:

(1.01,<0.002) enter
(1,3) enter
divide

Is there anything approaching that level of simplicity in Matlab?

Subject: syntax for polar complex numbers

From: Matt

Date: 3 Nov, 2009 17:21:03

Message: 4 of 10

"Thomas " <loparna2000.removethis@yahoo.com> wrote in message <hcpnsf$i4n$1@fred.mathworks.com>...
> "Matt " <xys@whatever.com> wrote in message <hcpn1m$on9$1@fred.mathworks.com>...
> > "Thomas " <loparna2000.removethis@yahoo.com> wrote in message <hcpmeu$h1o$1@fred.mathworks.com>...
> > > Anyone know what the syntax is for a polar complex number? I don't see anything about that in the help or in previous newsgroup postings.
> > >
> > > Let's say I have a voltage with a magnitude of 1 p.u. and an angle of 0.0045 radians, and I want to input that as a complex phasor (a complex number with the same magnitude and phase angle) so that I can do some complex number computations. How would I do that?
> > >
> > > Obviously I can convert it to rectangular format in input it as X + Yi, but that is very inconvenient. Is there a way to input it directly as a polar complex number?
> >
> >
> > input it to what?
>
> Let's say I want to computer the division of the following complex numbers:
>
> V = (1.01<0.002radians) (where "<" is my makeshift angle symbol)
> X = 1+3i
>
> I acutally don't want to assign variables and such and such. I know I could go through a long tortured procedure where I assign the magnitude and angle of V to different variables and use them to calculate the real and imaginary components of V.
-------

I don't know why you consider this a long tortured procedure. MATLAB has functions pol2cart() and cart2pol() that essentially perform these transformations for you. If you want to carry V from your example around as a single variable, you could do so as

V=1.01+i*0.002

but remember to convert it using the following 2-line function whenever you want to do arithmetic

function X=phasor2cart(V)

  [r,c]=pol2cart(V(2),V(1));
   X=r+c*i;

Subject: syntax for polar complex numbers

From: Matt

Date: 3 Nov, 2009 17:25:19

Message: 5 of 10

"Matt " <xys@whatever.com> wrote in message <hcpopv$gg2$1@fred.mathworks.com>...

>
> function X=phasor2cart(V)
>
> [r,c]=pol2cart(V(2),V(1));


should be

[r,c]=pol2cart(imag(V),real(V));

Subject: syntax for polar complex numbers

From: Thomas

Date: 3 Nov, 2009 17:44:02

Message: 6 of 10

"Matt " <xys@whatever.com> wrote in message <hcpopv$gg2$1@fred.mathworks.com>...
> "Thomas " <loparna2000.removethis@yahoo.com> wrote in message <hcpnsf$i4n$1@fred.mathworks.com>...
> > "Matt " <xys@whatever.com> wrote in message <hcpn1m$on9$1@fred.mathworks.com>...
> > > "Thomas " <loparna2000.removethis@yahoo.com> wrote in message <hcpmeu$h1o$1@fred.mathworks.com>...
> > > > Anyone know what the syntax is for a polar complex number? I don't see anything about that in the help or in previous newsgroup postings.
> > > >
> > > > Let's say I have a voltage with a magnitude of 1 p.u. and an angle of 0.0045 radians, and I want to input that as a complex phasor (a complex number with the same magnitude and phase angle) so that I can do some complex number computations. How would I do that?
> > > >
> > > > Obviously I can convert it to rectangular format in input it as X + Yi, but that is very inconvenient. Is there a way to input it directly as a polar complex number?
> > >
> > >
> > > input it to what?
> >
> > Let's say I want to computer the division of the following complex numbers:
> >
> > V = (1.01<0.002radians) (where "<" is my makeshift angle symbol)
> > X = 1+3i
> >
> > I acutally don't want to assign variables and such and such. I know I could go through a long tortured procedure where I assign the magnitude and angle of V to different variables and use them to calculate the real and imaginary components of V.
> -------
>
> I don't know why you consider this a long tortured procedure. MATLAB has functions pol2cart() and cart2pol() that essentially perform these transformations for you. If you want to carry V from your example around as a single variable, you could do so as
>
> V=1.01+i*0.002
>
> but remember to convert it using the following 2-line function whenever you want to do arithmetic
>
> function X=phasor2cart(V)
>
> [r,c]=pol2cart(V(2),V(1));
> X=r+c*i;

I guess it's a matter of opinion. I have a lot of these to do. Would like to know simplest way. Using cart2pol, easiest way would be the following:

[vre,vim] = cart2pol(0.465,1.01);
(vre+i*vim)/(1+3i)

You cannot, as you suggest, simply enter V=1.01+i*0.002. (Actually, that happens to work in this special case, since the phase angle is so small that abs(V) = Re(V) and angle(V) = Im(V), but it wouldn't work in general.)

I just thought that, given Matlab's power to do complex computations, they might have some more convenient way for specifying polar complex numbers in computations, or assigning polar complex numbers to variables.

Subject: syntax for polar complex numbers

From: Thomas

Date: 3 Nov, 2009 17:52:02

Message: 7 of 10

"Thomas " <loparna2000.removethis@yahoo.com> wrote in message <hcpq52$b9b$1@fred.mathworks.com>...
> "Matt " <xys@whatever.com> wrote in message <hcpopv$gg2$1@fred.mathworks.com>...
> > "Thomas " <loparna2000.removethis@yahoo.com> wrote in message <hcpnsf$i4n$1@fred.mathworks.com>...
> > > "Matt " <xys@whatever.com> wrote in message <hcpn1m$on9$1@fred.mathworks.com>...
> > > > "Thomas " <loparna2000.removethis@yahoo.com> wrote in message <hcpmeu$h1o$1@fred.mathworks.com>...
> > > > > Anyone know what the syntax is for a polar complex number? I don't see anything about that in the help or in previous newsgroup postings.
> > > > >
> > > > > Let's say I have a voltage with a magnitude of 1 p.u. and an angle of 0.0045 radians, and I want to input that as a complex phasor (a complex number with the same magnitude and phase angle) so that I can do some complex number computations. How would I do that?
> > > > >
> > > > > Obviously I can convert it to rectangular format in input it as X + Yi, but that is very inconvenient. Is there a way to input it directly as a polar complex number?
> > > >
> > > >
> > > > input it to what?
> > >
> > > Let's say I want to computer the division of the following complex numbers:
> > >
> > > V = (1.01<0.002radians) (where "<" is my makeshift angle symbol)
> > > X = 1+3i
> > >
> > > I acutally don't want to assign variables and such and such. I know I could go through a long tortured procedure where I assign the magnitude and angle of V to different variables and use them to calculate the real and imaginary components of V.
> > -------
> >
> > I don't know why you consider this a long tortured procedure. MATLAB has functions pol2cart() and cart2pol() that essentially perform these transformations for you. If you want to carry V from your example around as a single variable, you could do so as
> >
> > V=1.01+i*0.002
> >
> > but remember to convert it using the following 2-line function whenever you want to do arithmetic
> >
> > function X=phasor2cart(V)
> >
> > [r,c]=pol2cart(V(2),V(1));
> > X=r+c*i;
>
> I guess it's a matter of opinion. I have a lot of these to do. Would like to know simplest way. Using cart2pol, easiest way would be the following:
>
> [vre,vim] = cart2pol(0.465,1.01);
> (vre+i*vim)/(1+3i)
>
> You cannot, as you suggest, simply enter V=1.01+i*0.002. (Actually, that happens to work in this special case, since the phase angle is so small that abs(V) = Re(V) and angle(V) = Im(V), but it wouldn't work in general.)
>
> I just thought that, given Matlab's power to do complex computations, they might have some more convenient way for specifying polar complex numbers in computations, or assigning polar complex numbers to variables.

Sorry, I meant to use pol2cart in my example, not cart2pol. It would be:

[vre,vim] = pol2cart0.465,1.01);
(vre+i*vim)/(1+3i)

Subject: syntax for polar complex numbers

From: John D'Errico

Date: 3 Nov, 2009 18:10:03

Message: 8 of 10

"Thomas " <loparna2000.removethis@yahoo.com> wrote in message <hcpnsf$i4n$1@fred.mathworks.com>...
> "Matt " <xys@whatever.com> wrote in message <hcpn1m$on9$1@fred.mathworks.com>...
> > "Thomas " <loparna2000.removethis@yahoo.com> wrote in message <hcpmeu$h1o$1@fred.mathworks.com>...
> > > Anyone know what the syntax is for a polar complex number? I don't see anything about that in the help or in previous newsgroup postings.
> > >
> > > Let's say I have a voltage with a magnitude of 1 p.u. and an angle of 0.0045 radians, and I want to input that as a complex phasor (a complex number with the same magnitude and phase angle) so that I can do some complex number computations. How would I do that?
> > >
> > > Obviously I can convert it to rectangular format in input it as X + Yi, but that is very inconvenient. Is there a way to input it directly as a polar complex number?
> >
> >
> > input it to what?
>
> Let's say I want to computer the division of the following complex numbers:
>
> V = (1.01<0.002radians) (where "<" is my makeshift angle symbol)
> X = 1+3i
>
> I acutally don't want to assign variables and such and such. I know I could go through a long tortured procedure where I assign the magnitude and angle of V to different variables and use them to calculate the real and imaginary components of V. That is way over the top for what I want to do. What is the EASIEST way to accomplish this division?
>
> I'm thinking about my HP 48g, where I would do the following:
>
> (1.01,<0.002) enter
> (1,3) enter
> divide
>
> Is there anything approaching that level of simplicity in Matlab?

Nothing stops you from writing it. But, no. There is
no such tool.

John

Subject: syntax for polar complex numbers

From: Matt

Date: 3 Nov, 2009 18:24:02

Message: 9 of 10

"Thomas " <loparna2000.removethis@yahoo.com> wrote in message <hcpq52$b9b$1@fred.mathworks.com>...

> I guess it's a matter of opinion. I have a lot of these to do. Would like to know simplest way. Using cart2pol, easiest way would be the following:
>
> [vre,vim] = cart2pol(0.465,1.01);
> (vre+i*vim)/(1+3i)
======================

Not if you write a function, as I suggested, that gives you X=(vre+i*vim) as its output. If you did, this would reduce to one line,

result = myfunction(0.465,1.01) / (1+3i);





> You cannot, as you suggest, simply enter V=1.01+i*0.002.
=====

Yes you can, but as I was careful to point out, you cannot do any computations with it: it is merely a way of carrying around the phasor data as a single object. To do computations, you would have to invoke a conversion function phasor2cart() first, but note that if you do, the above syntax would simplify still further to

result = phasor2cart(V) / (1+3i);

Subject: syntax for polar complex numbers

From: Matt

Date: 3 Nov, 2009 18:47:02

Message: 10 of 10

Another solution would be to use classdef to write your own Phasor data type.
I've created a prototype for you at the bottom of this post, which should be put in a file called Phasor.m

Using the function Phasor() you can create a data type which is in all ways like MATLAB's usual complex variables, but which displays its contents in phasor form, e.g.

>> V=Phasor(1.01,.002) %From your earlier example
 
[Mag Angle]:
 
    1.0100 0.0020

But the important thing is that you can also do arithmetic on it with complex numbers in whatever form you want, as in the following examples:

>> V/1+3i %phasor/cartesian

ans =

   1.0100 + 3.0020i

>> V/V %phasor/phasor

ans =

     1

If you want the results displayed or saved in phasor form, you can use the Phasor() function once again:

>> result=Phasor(V/1+3i),
 
[Mag Angle]:
 
    3.1674 1.2463




%%%%The code below must go in a file Phasor.m

classdef Phasor < double
   
    methods
       
        function obj=Phasor(varargin)
            
            switch nargin
                
                case 2
                  [Mag,Angle]=deal(varargin{:});
                  [r,c]=pol2cart(Mag,Angle);
                  data=r+c*i;
                case 1
                  data=varargin{1};
            end
            obj=obj@double(data);
            
        end
        
        function display(obj)
            
            [Angle,Mag]=cart2pol(real(obj), imag(obj));
            disp ' '
            disp('[Mag Angle]:')
            disp ' '
            disp([Mag(:),Angle(:)]);
            
   
        end
        
    end
    
end

Tags for this Thread

Everyone's Tags:

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Tag Activity for This Thread
Tag Applied By Date/Time
oop Matt J 4 Nov, 2009 10:52:33
polar Thomas 3 Nov, 2009 11:44:05
complex Thomas 3 Nov, 2009 11:44:05
rssFeed for this Thread

Contact us at files@mathworks.com