0
$\begingroup$

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"}]

enter image description here

$\endgroup$
  • 1
    $\begingroup$ Welcome to Mathematica.SE! I suggest the following: 0) Browse the common pitfalls question 1) As you receive help, try to give it too, by answering questions in your area of expertise. 2) Read the faq! 3) When you see good questions and answers, vote them up by clicking the gray triangles, because the credibility of the system is based on the reputation gained by users sharing their knowledge. Also, please remember to accept the answer, if any, that solves your problem, by clicking the checkmark sign! $\endgroup$ – Dr. belisarius Feb 24 '16 at 0:41
  • $\begingroup$ Partly because using Solve doesn't set the value of x, so you are trying to plot something that has the parameter x in it with no value plugged in for x. You also have some scoping problems, I think, where the a'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$ – march Feb 24 '16 at 0:43
  • 1
    $\begingroup$ You should plot for x, not for a. Change to : Manipulate[ Plot[{f[x, a], x}, {x, -2, 2}], {a, 1, 20, Appearance -> "Labeled"}] $\endgroup$ – garej Feb 24 '16 at 10:28
2
$\begingroup$
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"}]

enter image description here

$\endgroup$
  • $\begingroup$ OP here. I had to log into the correct account. Sorry for the confusion in my post. I'm not familiar with how the end of the 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$ – Ozera Feb 24 '16 at 0:56
  • $\begingroup$ /. 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$ – march Feb 24 '16 at 0:58
  • $\begingroup$ Okay. Thank you for the information. Since I am not in the original account I posted in (my mistake), I supposed i'll just say: POST RESOLVED ?Maybe I can ask a moderator to accept this post? $\endgroup$ – Ozera Feb 24 '16 at 1:01
  • $\begingroup$ @Ozera. You should be able to merge accounts, perhaps by contacting a moderator. $\endgroup$ – march Feb 24 '16 at 3:03
  • $\begingroup$ @Ozera, please see this for help with merging your accounts. $\endgroup$ – J. M.'s technical difficulties Feb 24 '16 at 10:23
2
$\begingroup$

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"}]

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.