5
$\begingroup$

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.

$\endgroup$
  • 7
    $\begingroup$ 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. $\endgroup$ – J. M.'s discontentment Jun 20 '15 at 9:35
  • $\begingroup$ Norm[] and Abs[] are equivalent for complex number argument. $\endgroup$ – J. M.'s discontentment Jun 20 '15 at 9:54
  • $\begingroup$ Oh yes...so I guess my problem has been solved.Thanks:D $\endgroup$ – Sean Patrick Jun 20 '15 at 10:02
  • 1
    $\begingroup$ Sean, if you made it work go ahead and post the solution as an answer. (Otherwise the question will keep popping up as unanswered) $\endgroup$ – george2079 Jun 20 '15 at 13:32
  • $\begingroup$ how to ......@george2079 $\endgroup$ – Sean Patrick Jun 20 '15 at 16:48
3
$\begingroup$

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.♦

| improve this answer | |
$\endgroup$
  • $\begingroup$ …well, what you did is in fact what you're supposed to replace (* stuff *) with in my very first comment. :) $\endgroup$ – J. M.'s discontentment Jun 21 '15 at 6:39
  • $\begingroup$ You can use Module[] to encapsulate your procedure… $\endgroup$ – J. M.'s discontentment Jul 1 '15 at 19:12
  • $\begingroup$ 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 . $\endgroup$ – Sean Patrick Jul 1 '15 at 19:33
3
$\begingroup$

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).

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.