Message Boards Message Boards

[?] Figure out the problem from this Plot[]/Epilog/NSolve[] error message?

Posted 7 years ago

I get lots of error messages. I do not look at many of them. Sometimes I consider myself lucky to get an error message, since I also often get no message and no desired output.

I usually just go to the code to see if I can figure out what is confusing Mma.

I am hoping one of the experts here can expose the meaning of this one. This is from an example in the Mathematica Navigator book. Here's the example:

enter image description here

Here's my (intentionally slight) change.

f0[x_] := x^5 - 7 x^3 + 9 x (* was f = x^5 - 7 x^3 + 9 x *)

g0[q_] := 2 q (* was g = 2 x *)

Plot[{f0, g0}, {x, -2.5, 2.5}
 , Epilog -> {Point[{#, f0 /. x -> #}] & /@ (x /. 
      NSolve[f0 == g0, x])}]

The error message is: HoldForm is not a Graphics primitive or directive.

Huh??

Needless to say I did not code HoldForm[]. I did find this HoldForm[] command in the output of FullForm[]: (output snipped due to volume).

So my questions is/are:

Q: Is this related to SetDelayed[]?

I was able to debug this one. A working version is:

Plot[{f0[x], g0[x]}, {x, -2.5, 2.5}
 , Epilog -> {Point[{#, f0[x] /. x -> #}] & /@ (x /. 
      NSolve[f0[x] == g0[x], x])}]

Q: Does the corrected code help me relate the error message to the incorrect code?

Thanks in advance.

POSTED BY: Aeyoss Antelope
2 Replies

Sorry, I forgot the x in the functions to plot; also, we can remove unnecessary #,&,/@

Plot[{f0[x], g0[x]}, {x, -2.5, 2.5}, 
 Epilog -> {Point[{x, f0[x]}] /. NSolve[f0[x] == g0[x], x]}]
POSTED BY: Gianluca Gorni

In the way you define f0, you cannot omit the variable x in f0[x] etc.:

Plot[{f0, g0}, {x, -2.5, 2.5}, 
 Epilog -> {Point[{#, f0[x] /. x -> #}] & /@ (x /. 
      NSolve[f0[x] == g0[x], x])}]

f0 is not equivalent to f0[x].

In the book example f0 was itself the expression, without need for x. Different syntax for different purpose.

POSTED BY: Gianluca Gorni
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract