The idea is: I'd like to have the dynamic parameter a change the graph, without the need of actually re-evaluate the Plot command after each change of the parameter a. But this code delivers no plot printed on the screen. I've tried adding an Evaluate command as well, without luck.

What am I missing of the Dynamic command? Or where did I do something wrong?

I can read this question a couple of ways. It is easy to do if Plot is to be reevaluated dynamically as the current answers show -- that is, the user does not have to hit shift-enter. It is possible to do if you do not want the function Plot to be actually reevaluated every time the parameter a changes, but the result will likely be dissatisfying, unless your example func is exactly the function you want to use.
–
Michael E2Aug 5 '13 at 15:24

@MichaelE2 I'm intrigued by the second possibility you mention. I don't know a lot about the dynamic capabilities of Mathematica, so could you elaborate what you have in mind?
–
sebhoferAug 5 '13 at 15:50

@sebhofer What I had in mind was taking the Graphics output from Plot and remapping the coordinates to depend dynamically on a. It seems a bad idea to me. Since Plot makes choices depending on func, you lose that. (The sample function could be done with Graphics@Dynamic@Line[{{-5, -5+a}, {5, 5+a}}], but I assume the OP has something more complicated in mind.) I haven't been able to imagine a situation in which this second method would be a real advantage. But technically, it should be possible.
–
Michael E2Aug 5 '13 at 16:00

@MichaelE2 Now I see what you... that would of course be closer to the OP's original idea.
–
sebhoferAug 5 '13 at 16:12

1

In your comments to answers provided you below keep talking about using locators. You need to put the details of what you want in your question. Readers are not psychic.
–
Mike HoneychurchAug 5 '13 at 22:11

3 Answers
3

Here's an easier way to do what I mentioned in a comment. We avoid Plot altogether and simply plot a line. You miss out on the recursive refinement that Plot offers to smooth out curves of high curvature, but in some cases that might be ok. You can even make the pllot depend on the function dynamically.

Thank you for your fast answer, but I'd like to not use Manipulate. I'm searching for a way of having an "invisible Locator" somewhere on the graph which modulus (distance to 0) is a, and to move the Locator and thus changing the value of a. This is, I think, not possible inside Manipulate—but I could be wrong. Could you help with this too? Thanks a lot in advance!
–
GabrielAug 5 '13 at 13:35

2

@user7285 Then you should state so in your question! But yes, this can be accomplished in Manipulate, see edit.
–
sebhoferAug 5 '13 at 14:50

Thank you a lot for your answer, this helped well. I have now this problem: when using the code here, the two Locators move together. I think, it's due to the Plot command, as the two Locators move independently if I delete that command. Where is the problem? DynamicModule[{pt1 = {1, 2}, pt2 = {4, 3}}, Dynamic@Show[ Plot[x *pt1[[1]], {x, 0, 6}, PlotRange -> 10] , Graphics [{ Locator[Dynamic[pt1]] , Locator[Dynamic[pt2]] }] ] ]
–
GabrielAug 5 '13 at 14:42

This does not seem an unreasonable use of Dynamic here. There are issues with a being uninitialized at the beginning of a session. One could use Dynamic[If[NumericQ[a], Plot[x + a, {x, 0, 6}], "Initialize a"]] if for some reason one wants a to be a global variable. (By the way, the first line Dynamic[a]; is unnecessary.)
–
Michael E2Aug 5 '13 at 15:29

1

@user7285 The Locator question probably ought to be stated as a new question.
–
Michael E2Aug 5 '13 at 15:31

Mathematica is a registered trademark of Wolfram Research, Inc. While the mark is used herein with the limited permission of Wolfram Research, Stack Exchange and this site disclaim all affiliation therewith.