Message Boards Message Boards

0
|
1488 Views
|
4 Replies
|
1 Total Likes
View groups...
Share
Share this post:

What is the preferred way to PolarPlot a complex function?

Posted 1 year ago

As a newcomer to Mathematica (V13.2 Home Edition), I encountered an issue that might be due to my misunderstanding of the use of the AbsArg function within the PolarPlot of a complex function. The notebook file shown below compares polar plots of Exp[I [Omega]]. The first plot uses separate Abs and Arg functions, and produces the anticipated results. The second plot uses the AbsArg function, and is inconsistent with the first plot.

My understanding is that the AbsArg function separates abs and arg as elements of a list. Then why do the two plots differ?

Any insight into this behavior is greatly appreciated.

POSTED BY: Jack Mandelman
4 Replies

Eric,

You are exactly correct. Omega had been assigned a global value. All OK now.

Thank you.

POSTED BY: Jack Mandelman

Eric,

Thank you for the quick reply. One other question about the use of Evaluate within PolarPlot.

PolarPlot[Evaluate[AbsArg[Exp[I \[Omega]]]], {\[Omega], 0, \[Pi]/2}]

Execution of this cell indicates that arg has a constant value (Pi) regardless of the value of omega. Arg is expected to be equal to omega for omega from 0 to Pi/2. What am I missing?

POSTED BY: Jack Mandelman
Posted 1 year ago

I'm guessing that somewhere you gave a value to omega in the Global context. This is the risk of forcing evaluation. If omega has no value defined for it, then forcing Evaluate is okay, because the evaluation stops at a point where omega appears as just a symbol, and then it will take on the values in the range specifier. But if omega was given a value, then Evaluate will keep going, plugging in that value.

You can sort of protect against this if you use formal symbols:

PolarPlot[
 Evaluate[AbsArg[Exp[I \[FormalOmega]]]], 
 {\[FormalOmega], 0, \[Pi]/2}]

Formal symbols are protected by default, so if you try to assign it a value, it'll fail to do the assignment and give you a message.

POSTED BY: Eric Rimbey
Posted 1 year ago

Couple of things going on here. When using the various plotting functions, you need to understand that the "body", the first argument, is held unevaluated. It's kept as the sort of template expression that will be evaluated at various points in the specfied range. Then next thing to understand is that the typical behavior of plotting functions when you give them a list is to treat it as multiple, independent plots.

So, in this example

PolarPlot[{Abs[Exp[I \[Omega]]],Arg[Exp[I \[Omega]]]},{\[Omega],0,\[Pi]/2}]

You should expect to get two plots (distinguished by color). And this is indeed what you get.

In this example

PolarPlot[{AbsArg[Exp[I \[Omega]]]},{\[Omega],0,\[Pi]/2}]

there is only one "thing" in the body, so it thinks it's going to plot a single plot. That's why there is only one color in the result. By the way, the {} are superfluous, as AbsArg returns a list. Now, you can force something to evaluate that would otherwise be held. You do this with Evaluate. So, you can reproduce the first plot like this:

PolarPlot[Evaluate[AbsArg[Exp[I \[Omega]]]], {\[Omega], 0, \[Pi]/2}]

Now when PolarPlot goes to work, it "sees" two things.

Having said all of that, I'm not sure what plot you were trying to create, so I'm not sure what the "preferred way" is.

POSTED BY: Eric Rimbey
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract