Can anyone explain why the below code does not produce a plot?
Clear["Global`*"]
f[x_, a_] = a - x^2;
Solve[f[x, a] == x, x]
Manipulate[ Plot[{f[x, a], x}, {a, -2, 2}], {a, 1, 20, Appearance -> "Labeled"}]
f[x_, a_] = a - x^2;
Manipulate[
Plot[{f[x, a], x},
{x, -5, 5},
PlotRange -> {{-5, 5}, {-5, 5}},
Epilog -> {Red, PointSize[0.02], Point[{x, f[x, a]} /. # & /@ Solve[f[x, a] == x, x]]}
],
{a, 1, 20, Appearance -> "Labeled"}]
Epilog
line works. That is, what does ` /. # & /@ ` do? I am inferring that this places a red point where I have a fixed point, but i'm still curious. And thank you for the help!
$\endgroup$
/.
is shorthand Infix notation for ReplaceAll
. /@
is Infix notation for Map
. #
is Slot[1]
which is used for defining a pure function with &
is the short-hand for Function
. You can look up all of these in the documentation.
$\endgroup$
With a few bells and whistles.
Clear[f]
f[x_, a_] = a - x^2;
soln[x_, a_] = Solve[f[x, a] == x, x];
Manipulate[
Column[{
Plot[{f[x, a], x}, {x, -2, 2},
Epilog -> {Red, AbsolutePointSize[5],
Point[{x, f[x, a]} /. soln[x, a]]},
ImageSize -> 360,
PlotLegends -> Placed[{f[x, a], x}, {.7, .2}]],
StringForm["\nx = ``", Or @@ (x /. soln[x, a])]},
Alignment -> Center],
{{a, 0}, -0.25, 2, .05,
Appearance -> "Labeled"}]
Solve
doesn't set the value ofx
, so you are trying to plot something that has the parameterx
in it with no value plugged in forx
. You also have some scoping problems, I think, where thea
's aren't actually the same. It's actually pretty unclear what you're actually trying to do here. Can you add some explanations to your post? $\endgroup$x
, not fora
. Change to :Manipulate[ Plot[{f[x, a], x}, {x, -2, 2}], {a, 1, 20, Appearance -> "Labeled"}]
$\endgroup$