# Is it possible that we can use “+” to add two vectors in polar form?

For example, $a=(2,\pi/4)$, $b=(3,\pi/3)$, if we want to get the result of $a+b$, using + operator will not do, because mathematica will ignore the polar form, and regard a and b two two-dimension vectors in Cartesian coordinates. Polar vectors are used in phasor diagram.

• So, create a special object, call it Phasor[r, θ], and then define a way to add two Phasor[] objects: Phasor /: Phasor[r1_, θ1_] + Phasor[r2_, θ2_] := (* stuff *)Abs[] and Arg[] will be useful, of course. – J. M.'s discontentment Jun 20 '15 at 9:35
• Norm[] and Abs[] are equivalent for complex number argument. – J. M.'s discontentment Jun 20 '15 at 9:54
• Oh yes...so I guess my problem has been solved.Thanks:D – Sean Patrick Jun 20 '15 at 10:02
• Sean, if you made it work go ahead and post the solution as an answer. (Otherwise the question will keep popping up as unanswered) – george2079 Jun 20 '15 at 13:32
• how to ......@george2079 – Sean Patrick Jun 20 '15 at 16:48

Phasor /: Phasor[p1_, r1_] + Phasor[p2_, r2_] := p1*E^(I r1) + p2*E^(I r2) Infix[{Abs[Phasor[3, Pi/3] + Phasor[3, Pi/6]], Arg[Phasor[3, Pi/3] + Phasor[3,Pi/6]]}, ","] 

Two lines of code is really enough to solve problem.Thanks for @Guess who it is.♦

• …well, what you did is in fact what you're supposed to replace (* stuff *) with in my very first comment. :) – J. M.'s discontentment Jun 21 '15 at 6:39
• You can use Module[] to encapsulate your procedure… – J. M.'s discontentment Jul 1 '15 at 19:12
• Can you do an example for me? I have trouble understanding Module although Mathematica already gave some examples.This almost drives me crazy!！I’ve been working on this problem and also been modling Foucault's pendulum using mathematica for hours and It's 3:40 am now!!I'have to go to sleep and I'll check news of this problem tomorrow . – Sean Patrick Jul 1 '15 at 19:33

Here is a definition that works for arbitrary number of phasors:

ClearAll[phasor]

phasor /: Plus[p : _phasor ..] :=
phasor @@
ToPolarCoordinates@
Total[{p} /. phasor -> (FromPolarCoordinates[{##}] &)]


Example:

phasor[1, Pi] + phasor[2, Pi/4] + phasor[3, Pi/3]


$$\text{phasor}\left(\sqrt{\left(\frac{1}{2}+\sqrt{2}\right)^2+\left(\sqrt{2}+\frac{3 \sqrt{3}}{2}\right)^2},\tan ^{-1}\left(\frac{\sqrt{2}+\frac{3 \sqrt{3}}{2}}{\frac{1}{2}+\sqrt{2}}\right)\right)$$

It uses the new functions (in version 10.1) FromPolarCoordinates and ToPolarCoordinates.

To make it work with arbitrary number of phasors, I use a named pattern p with Repeated, which collects all phasors appearing in a sum. They are then converted to Cartesian coordinates, added with Total, and converted back to phasor form (the last step could be omitted if you want the output to be in Cartesian coordinates).

• I am still in version 10.so When I search Wolfram Documentation I didn't get much help.Thank you for your answer. – Sean Patrick Jul 2 '15 at 14:33
• There is a function in version 10 called CoordinateTransformData perhaps this would help a bit,too. – Sean Patrick Jul 2 '15 at 14:50