2
$\begingroup$

I would like to plot the (most likely) multi-valued solution to an equation, as I vary one of the parameters. Here's my approach:

ClearAll[F, a, eq]
eq[f_, a_] := Exp[(1 - f)*0.5] == a* (1 - f)*0.5 + 1;
Solve[eq[f, 2], f]
Plot[Solve[eq[f, a], f], {a, 1, 10}]

This function is multi-valued for a > 1. However, the output of Solve is of the form {{f -> -1.51286}, {f -> 1.}}, which apparently is something that Plot does not understand. How can I plot both values, for varying a, in the same graph?

$\endgroup$
5
$\begingroup$

The issue is the argument for Plot. Note:

eq[f_, a_] := Exp[(1 - f)*0.5] == a*(1 - f)*0.5 + 1;

Plot[f /. Solve[eq[f, a], f], {a, 1, 10}]

yields:

enter image description here

You can see the solutions:

fun[f_, a_] := Exp[(1 - f)*0.5] - a*(1 - f)*0.5 - 1;
Manipulate[
 Plot[fun[x, a], {x, -10, 10}, PlotRange -> {-20, 100}, 
  MeshFunctions -> (#2 &), Mesh -> {{0.}}, 
  MeshStyle -> {Red, PointSize[0.02]}], {a, 1, 10}]

enter image description here

NSolve finds (in this particular case and suppressing thrown errors with Quiet). In the following the dashed plot is a v root to show that NSolve is finding the roots other than 1.

sol[a_] := w /. First@NSolve[fun[w, a] == 0, w]
Manipulate[
 Quiet@Show[
   Plot[fun[x, a], {x, -10, 10}, PlotRange -> {-20, 100}, 
    MeshFunctions -> (#2 &), Mesh -> {{0.}}, 
    MeshStyle -> {Red, PointSize[0.02]}],
   ParametricPlot[{sol[x], x}, {x, 1, 10}, 
    PlotRange -> {{-10, 10}, {-20, 100}}, PlotStyle -> Dashed], 
   Graphics[{Red, Point[{s[a], a}]}], GridLines -> {{s[a]}, None}
   ], {a, 1, 10}]

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.