2
$\begingroup$

The given function is

enter image description here

This function is plotted to be

enter image description here

V[x_, r_] := 
 Piecewise[{{-Sqrt[2] r + Sqrt[r^2 - x^2], 
    Abs[x] <= Sqrt[2]/2 r}, {-1 + Sqrt[2] x - Sqrt[
     r^2 - (Abs[x] - 1)^2], Abs[x] >= 1 - Sqrt[2]/2 r}, {-Abs[x],}}]

My problem is how to write the otherwise condition as given in the paper for the Mathematica and plot the function for different values of r.

$\endgroup$

1 Answer 1

4
$\begingroup$
  • -1 + Sqrt[2] x - Sqrt[ r^2 - (Abs[x] - 1) should be -1 + Sqrt[2] r - Sqrt[r^2 - (Abs[x] - 1)^2]
  • The otherwise condition -Abs[x] is at the end of all List.
expr = Piecewise[{{-Sqrt[2] r + Sqrt[r^2 - x^2], 
    Abs[x] <= Sqrt[2]/2 r}, {-1 + Sqrt[2] r - 
     Sqrt[r^2 - (Abs[x] - 1)^2], Abs[x] >= 1 - Sqrt[2]/2 r}}, -Abs[
    x]]
Plot[Table[expr, {r, {.01, .1, .2}}] // Evaluate, {x, -1, 1}, 
 PlotRange -> {-1, 0}, PlotStyle -> {Black, Red, Blue}, Frame -> True,
  Axes -> False, 
 PlotLegends -> 
  Placed[LineLegend[{Black, Red, Blue}, {"r=0.2", "r=0.1", "r=0.01"}, 
    LegendMarkers -> "OpenMarkers"], {.2, .8}]]

enter image description here

$\endgroup$
2
  • 2
    $\begingroup$ It is not necessary to repeat the styles in the PlotLegends, e.g., PlotLegends -> Placed[(HoldForm[r = #] & /@ {0.2, 0.1, 0.01}), {.175, .8}] I also recommend including PlotRangePadding -> Scaled[.02] $\endgroup$
    – Bob Hanlon
    Sep 8, 2022 at 13:48
  • 2
    $\begingroup$ @BobHanlon Thanks, I also don't know how to add LegendMarkers since I found that LegendMarkers->Automatic can not work. $\endgroup$
    – cvgmt
    Sep 8, 2022 at 14:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.