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.
- 3,867
- 1
- 20
- 35
- 147
- 7
2 Answers
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).
- 97,245
- 7
- 213
- 499
-
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 02 '15 at 14:33
-
There is a function in version 10 called CoordinateTransformData perhaps this would help a bit,too. – Sean Patrick Jul 02 '15 at 14:50
Phasor /: Phasor[p1_, r1_] + Phasor[p2_, r2_] := p1E^(I r1) + p2E^(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 J. M.
- 124,525
- 11
- 401
- 574
- 147
- 7
-
…well, what you did is in fact what you're supposed to replace
(* stuff *)with in my very first comment. :) – J. M.'s missing motivation Jun 21 '15 at 06:39 -
You can use
Module[]to encapsulate your procedure… – J. M.'s missing motivation Jul 01 '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 01 '15 at 19:33
Phasor[r, θ], and then define a way to add twoPhasor[]objects:Phasor /: Phasor[r1_, θ1_] + Phasor[r2_, θ2_] := (* stuff *)…Abs[]andArg[]will be useful, of course. – J. M.'s missing motivation Jun 20 '15 at 09:35Norm[]andAbs[]are equivalent for complex number argument. – J. M.'s missing motivation Jun 20 '15 at 09:54\[rho]. In order to convert these back to greek letters you can use this tool. 3) You can write it as a reusable function that people can copy into their own projects, using Guess who it is'Phasordefinition above. 4) "c" in "change" should be capitalized. I already gave you my vote though. – C. E. Jun 21 '15 at 10:47AnglePathmight interest you. – Greg Hurst Jul 02 '15 at 02:06AnglePathis that the angles there are relative rotations, which isn't the same as complex addition. – Jens Jul 02 '15 at 05:50