2
$\begingroup$

I want to show values of a function $f[r,t]$ using DensityPlot but I don't know how to show the function only fo $r>1$. Could somebody please help me? I have written the below code, but I don't know how to make it work only for $r>1$.

Rc = 0.1;
f[r_, t_] := 
  Exp[-Sum[(-16 (((r^2 - 2 Rc^2 - r Sqrt[r^2 - 4 Rc^2])/(2 Rc^2)))^(
         2 + 4 mz) - 
        8 (-1)^mz (((r^2 - 2 Rc^2 - r Sqrt[r^2 - 4 Rc^2])/(2 Rc^2)))^(
         1 + 2 mz) (Sin[(3 + 2 mz) t] - 
           Sin[t - 
             2 mz t]))/((-1 + (((r^2 - 2 Rc^2 - 
               r Sqrt[r^2 - 4 Rc^2])/(2 Rc^2)))^(2 + 4 mz)) (1 + 
          2 mz) \[Pi]), {mz, 0, 10}]];
DensityPlot[
 f[Sqrt[x^2 + y^2], ArcTan[x, y]], {x, y} \[Element] 
  Disk[{0, 0}, 1.5], 
 PlotPoints -> 200, PlotLegends -> Automatic, 
 ColorFunctionScaling -> False, PlotRange -> {{-1, 2}, {0, 1}, All}]
$\endgroup$
9
  • $\begingroup$ When I evaluate your code I get "General::munfl Exp[-938.837] is too small" messages which means that the function needs to be rescaled. I think this also explains why the plot has only two colors. $\endgroup$
    – Lotus
    Dec 3, 2019 at 9:01
  • $\begingroup$ How can I rescale it?@Lotus $\endgroup$
    – Marco
    Dec 3, 2019 at 9:03
  • $\begingroup$ Try to plot without Exp, you will see more interesting picture and also PlotLegend shows very big negative values for Sum, that explains message "Exp[...] is too small". $\endgroup$
    – Alx
    Dec 3, 2019 at 9:12
  • $\begingroup$ I agree that it's better but still, most of the plane is blue @Alx $\endgroup$
    – Marco
    Dec 3, 2019 at 9:17
  • $\begingroup$ I think the problem is I can't make exclusion work @Alx because if I can, the very very large values disappear. $\endgroup$
    – Marco
    Dec 3, 2019 at 9:21

1 Answer 1

2
$\begingroup$

It is better to use RegionDifference instead of Exclusions->Disk[...], this also solves the problem of small exponents: they appear near to {0,0} and RegionDifference does exclude this region.

Rc = 0.1;
f[r_, t_] := 
  Exp[-Sum[(-16 (((r^2 - 2 Rc^2 - 
               r Sqrt[r^2 - 4 Rc^2])/(2 Rc^2)))^(2 + 4 mz) - 
        8 (-1)^mz (((r^2 - 2 Rc^2 - 
               r Sqrt[r^2 - 4 Rc^2])/(2 Rc^2)))^(1 + 
            2 mz) (Sin[(3 + 2 mz) t] - 
           Sin[t - 2 mz t]))/((-1 + (((r^2 - 2 Rc^2 - 
                r Sqrt[r^2 - 4 Rc^2])/(2 Rc^2)))^(2 + 4 mz)) (1 + 
          2 mz) π), {mz, 0, 10}]];
DensityPlot[
 f[Sqrt[x^2 + y^2], ArcTan[x, y]], {x, y} ∈ 
  Region[RegionDifference[Disk[{0, 0}, 1.5], Disk[{0, 0}, 0.8]]], 
 PlotLegends -> Automatic, ColorFunction -> "Rainbow", 
 PlotRange -> {{-2, 2}, {0, 2}, All}, PlotPoints -> 100]

enter image description here

Or using Plot3D:

Plot3D[f[Sqrt[x^2 + y^2], ArcTan[x, y]], {x, y} ∈ 
  Region[RegionDifference[Disk[{0, 0}, 1.5], Disk[{0, 0}, 0.8]]], 
 PlotLegends -> Automatic, ColorFunction -> "Rainbow", 
 PlotRange -> {{-2, 2}, {0, 2}, All}, PlotPoints -> 100]

enter image description here

$\endgroup$

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.