I'd appreciate help with changing the scale of the following code from linear to logarithmic. It's intended to plot a radiation pattern. Also possibly with rotating the axes and displaying it in 3D. I am very new to Mathematica; a friend actually wrote the following and didn't know how to assist with the change of scale etc.

W[θ_,
KL_] := ((Cos[KL/2 Cos[θ]] - Cos[KL/2])/Sin[θ])^2
PolarPlot[{Limit[
W[θ, π/2]/W[π/2, π/2], θ -> x],
Limit[W[θ, π]/W[π/2, π], θ -> x],
Limit[W[θ, (5 π)/2]/W[π/2, (5 π)/2], θ ->
x]}, {x, 0, 2 Pi},
PlotLegends -> {"\!$$\*FractionBox[\(KL$$,     \
$$2$$]\)=\!$$\*FractionBox[\(π$$, $$4$$]\)",
"\!$$\*FractionBox[\(KL$$, $$2$$]\)=\!$$\*FractionBox[\(π$$,   \
$$2$$]\)",
"\!$$\*FractionBox[\(KL$$, $$2$$]\)=\!$$\*FractionBox[\(5 \ π$$, $$4$$]\)"}, PolarAxes -> True, PlotRange -> Automatic,
PolarGridLines -> Automatic, PolarAxesOrigin -> {0, 1},
PolarTicks -> {"Degrees", Automatic}]

• Could you at least plot a normal PolarPlot or 3D version of more or less of what you want and show it to us in order to see what you specifically want changed? You know, even if you are new to Mathematica, you have make a little effort, so we can help you. One remark: are you sure, the function is defined correctly? Cos[KL/2 Cos[θ]] looks weird. – Mauricio Fernández Nov 29 '16 at 13:07
• How may I attach graphs here? I have a couple of attachments showing exactly the graphs I need plotted. And the function is defined correctly. – Yuval Nov 29 '16 at 13:57
• Option (1): on the bottom of your question, you have "share", "edit" and "flag". Press "edit". Then, you can edit your question. On the top of the editing box, you have the controls for "Strong", "Emphasis", "Hyperlink", "Blockquote", "Code Sample" and "Image". Press "Image". Option (2), share a hyperlink to the picture. – Mauricio Fernández Nov 29 '16 at 14:06
• Done. One is the desired 3D plot, the second how I would like the graph already coded to be. – Yuval Nov 29 '16 at 14:17

First you need to figure out the function which discribes the "profile" of the field. Use ParametricPlot to display it:

ϕ[u_] := (Cos[3 u]) Cos[u];
ψ[u_] := (Cos[3 u]) Sin[u];
ParametricPlot[{ϕ[u], ψ[u]}, {u, 0, π}]


Then you can "revolve" that and plot the surface of revolution with ParametricPlot3D:

f[u_, v_] := {ϕ[u] Cos[v],
ϕ[u] Sin[v],
ψ[u]}
ParametricPlot3D[f[u, v], {u, 0, π}, {v, 0, 2 π}, PlotPoints -> 25, Mesh -> All]


there are a lot of dots to fill in from the opening post, but here are some elements which should set you up nicely to continue.

Polar Plot

The first problem is that the PolarPlot provided to us doesn't run (at a reasonable speed). The reason for this is the presence of Limit in the expressions to plot. I understand the reasoning behind it as the functions present an apparent singularity in $0$ $mod[2\pi]$, which resolves to $0$ when you take the limit (similar to $\frac{sin(x)}{x}$). However, calculating the limit for every point sampled for the plot is unnecessary.

Since (like $\frac{sin(x)}{x}$), the function approaches the limit continuously from both sides, an easy workaround is to simply plot the function while barely avoiding the apparent discontinuity.

If we remove the limits, your code gives:

W[θ_, KL_] := ((Cos[KL/2 Cos[θ]] - Cos[KL/2])/Sin[θ])^2
PolarPlot[{W[θ , π/2]/W[π/2, π/2],
W[θ , π]/W[π/2, π],
W[θ , (5 π)/2]/W[π/2, (5 π)/2]},
{θ , 0.1, 2 Pi - 0.1},
PolarAxes -> True, PlotRange -> Automatic,
PolarGridLines -> Automatic, PolarAxesOrigin -> {0, 1},
PolarTicks -> {"Degrees", Automatic}]


Note the plot range {θ , 0.1, 2 Pi-0.1}. I've removed the plot legends in the name of typing economy (aka laziness)...

3D Plot

Next, as @Gyebro suggested, you need to look into parametric plots to draw the revolution surface of the PolarPlot. However, since the original plot is drawn in polar coordinates, I feel it is easier to use spherical coordinates instead of Cartesian, thus SphericalPlot3D:

SphericalPlot3D[{W[θ  + π/2, (5 π)/2]/W[π/2, (5 π)/2],
W[θ + π/2, π/2]/W[π/2, π/2]},
{θ , 0.1, π}, {ϕ, 0, 4 π/3}, PlotRange -> All,
Axes -> False, Boxed -> False]


I chose to plot only two of the radiation profiles. Note that the revolution parameter here is $φ$, which I didn't make go a full circle ($2\pi$) to give the "cutout" feel like in the first plot. For some reason, the revolution axis of SphericalPlot3D in the frame of reference of the polar diagram is the transversal (horizontal) axis, so I've flipped the figure by 90 degrees, which corresponds to drawing W[θ + π/2, KL] instead of W[θ, KL].

Logarithmic Scale

We were asked to put the plots in logarithmic scale, in deciBels it seems... But if we look at the second diagram, we can see that the scale is actually linear (10, 20, 30...). So what we need to do actually is to put the functions we're drawing in deciBels before plotting but still have a linear scale.

This is where I make a some inferences on the physics of the problem. I assume that $W(θ,KL)$ represents power and the plotted functions are ratios of $\frac{power}{reference\,power}$. So conveniently, the power in deciBels is $$10\;\log_{10}(\frac{power}{reference\,power})$$

Before moving forward, you should realise that the emitted power we're plotting is always inferior to the reference and that it reaches 0 sometimes.

Plot[W[θ, (5 π)/2]/W[π/2, (5 π)/2], {θ, 0, 2 π}]


Thus, the deciBel values will be negative (consistent with the second diagram showing "dB down") and the zero values in the previous plots will lead to a divergence here (corresponding to infinite attenuation). That said, here are the plots:

PolarPlot[{10 Log[10, W[θ, π/2]/W[π/2, π/2]],
10 Log[10, W[θ, π]/W[π/2, π]],
10 Log[10, W[θ, (5 π)/2]/W[π/2, (5 π)/2]]},
{θ, 0.1, 2 Pi - 0.1}]
SphericalPlot3D[{10 Log[10,
W[θ + π/2, π/2]/W[π/2, π/2]],
10 Log[10,
W[θ + π/2, (5 π)/2]/
W[π/2, (5 π)/2]]}, {θ, 0.1, π}, {ϕ,
0, π}, PlotRange -> {{-30, 30}, {-30, 30}, {-30, 30}},
Axes -> False, Boxed -> False]


Good luck figuring this all out!