1
$\begingroup$

Plot $f(r) = - a/r^2-b/r^3$ for the three parameter sets (a=1, b=1), (a=-1, b=-1), (a=0, b=1) in a single plot. The three cases should each be a different color and labeled with its associated parameter set (r ranges from 0 to 10).

I need help with making the plot.

$\endgroup$

closed as off-topic by Artes, LCarvalho, MarcoB, Henrik Schumacher, gwr Nov 24 '17 at 22:37

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "This question arises due to a simple mistake such as a trivial syntax error, incorrect capitalization, spelling mistake, or other typographical error and is unlikely to help any future visitors, or else it is easily found in the documentation." – Artes, LCarvalho, MarcoB, Henrik Schumacher, gwr
If this question can be reworded to fit the rules in the help center, please edit the question.

1
$\begingroup$
f[a_, b_, r_] = -a/r^2 - b/r^3
Plot[{f[1, 1, r], f[-1, -1, r], f[0, 1, r]}, {r, 1, 10},PlotLegends->{"1,1","-1,1","0,1"}]
$\endgroup$
1
$\begingroup$

Based on Sumit's solution, but offering a differing labeling scheme based on the fairly new option PlotLabels, which I think work better than legends for this plot.

f[a_, b_, r_] = -a/r^2 - b/r^3
Plot[{f[1, 1, r], f[-1, -1, r], f[0, 1, r]}, {r, 1, 10}, 
  PlotLabels -> {"(a=1, b=1)", "(a=-1, b=-1)", "(a=0, b=1)"}]

plot

Update

I got to thinking that it would be nice to have an implementation that would work for a general list of parameter pairs. This is what I came up with.

With[{params = {{-1, -1}, {-1, 0}, {-1, 1}, {1, -1}, {1, 0}, {1, 1}}},
  Module[{avals, bvals, curves, lbls, items},
    {avals, bvals} = Transpose @ params; 
    curves = MapThread[-#1/r^2 - #2/r^3 &, {avals, bvals}]; 
    lbls = MapThread[Row[{" a=", #1, ", b=", #2}] &, {avals, bvals}];
    items =
      MapThread[
        Callout[#1, #2, {5, (#1 + .03 Sign[#1]) /. r -> 2.7}, {3, #1 /. r -> 3}] &, 
        {curves, lbls}];
    Plot[Evaluate @ items, {r, 1, 10}, ImageSize -> 500]]]

fancy_plot

The callouts must be adjusted by eyeball, but that kind of adjustment must be accepted if one is fussy about label placement.

$\endgroup$

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