1

I've been using the TI-NSpire CX Cas calculator to solve some electronic problems that work a lot with polar coordinates, in this calculator representing these exercises is very easy, as shown below.

Polar coordinates to rectangular numbers

In Mathematica I have tried using "FromPolarCoordinates", but it seems to me that it is very tedious, I wanted to know if there is an easier way to represent polar coordinates. Thanks

J. M.'s missing motivation
  • 124,525
  • 11
  • 401
  • 574

1 Answers1

4

Display a complex number as a phasor

Here is a bit of code that may give you some ideas about how to display numeric complex values in phasor notation.

ClearAll[phasor]

Format[phasor[z_Complex]] := With[{angleSymbol = Style[FromCharacterCode[8736], 18, Bold]}, Row[{Abs[z], Round[Arg[z]/Degree, 1] [Degree]}, angleSymbol] ]

z = 5 Exp[I 125 π/180]; z // N // phasor z // phasor

enter image description here

The Format statement tells Mathematica how to display one particular type of expression. The expression must consist of the wrapper phasor applied to a numeric value having Complex as its head. To create the angle symbol, we start with the Mathematica symbol \[Angle] and use a font size of 18 with an appearance of Bold.

To test the Format, we assign a complex value to $z$. But, $z$ is still symbolic. We must also apply N to get the numerical value of $z$ and then apply phasor, which we have told Mathematica to display in phasor notation.

Without converting $z$ to a numeric value, Mathematica displays the wrapper applied to the expression.

Input a complex number as a phasor

First, we define a function called phasor that acts on 2 values to produce a complex-valued expression. The 2 values are the magnitude and the phase of the complex value. In this definition, we assume the phase is given in degrees.

phasor[mag_, deg_] := mag Exp[I π deg/180]

5 ~ phasor ~ 125 // N (* this is infix notation *)

When phasor appears with 2 arguments, it is a function that returns a complex value. Earlier, when phasor appeared with 1 argument, it was a wrapper.

We want to be able to enter 5 \[Angle] 125 and have Mathematica recognize that as 5 ~ phasor ~ 125. To do that we need to load the Notation package.

<< Notation`

When we evaluate that expression the Notation Palette appears. We select the InfixNotation menu item. That produces an InfixNotation template that we must fill in. Now comes the tricky part. We click once on the left box (the first argument of the InfixNotation command) and type in \[Angle]. Then click once on the right box (the second argument) and type in phasor. Finally, press Shift-Enter to evaluate the InfixNotation command.

Do not try to do this without the Notation Palette, unless you are already an expert.

Now test the new notation by evaluating 5 \[Angle] 125. Be sure to include a space before the 125. It should appear as $5 \text{ }\angle\text{ } 125$ and evaluate to -2.86788 + 4.09576 I. If it works, save your notebook with the InfixNotation template already filled in.

If it doesn't work, or if you get an error when press Shift-Enter to evaluate the InfixNotation command, delete that InfixNotation command and try it again with a fresh template from the Notation Palette. The place where I always make a mistake is in clicking (just one time) on those little boxes in the InfixNotation template.

LouisB
  • 12,528
  • 1
  • 21
  • 31
  • Hello and sorry for asking you so late, but how can I make that format start in each session – Guillermo Rojas Sep 21 '21 at 04:11
  • @GuillermoRojas There are probably several good ways to accomplish that, but the only one I have used is to put commands in the init.m file. That is an initialization file that is loaded when MMA starts. You can read about it in the documentation. You may find questions about init.m in this forum. If you have trouble, please ask a new question, in order to get an expert answer. – LouisB Sep 21 '21 at 10:39
  • Thanks for the reply, I tried to put your code inside the init.m located in "C:\Users\apemangr\AppData\Roaming\Mathematica\FrontEnd\init.m" but it doesnt work :( – Guillermo Rojas Sep 22 '21 at 01:15
  • @GuillermoRojas I am using Linux, so I can't say anything about Windows. That said, the commands I put in /home/louis/.Mathematica/Autoload/FrontEnd/init.m execute fine. If the documentation has any examples, start by getting them running. Or, search this forum for a simple working example. Start simple is my motto. – LouisB Sep 22 '21 at 01:34
  • Could you please explain to me exactly how you added the code?, since after adding it to the top of the file and saving it, Mathematica crashes and then the init.m file is restored to its original version – Guillermo Rojas Sep 22 '21 at 02:08
  • @GuillermoRojas Sorry, but I can't advise you on this. – LouisB Sep 22 '21 at 02:29
  • The location in Windows is $UserBaseDirectory/Kernel/init.m – Guillermo Rojas Nov 27 '21 at 02:24