Mathematica manages variables that are already defined

Can Mathematica be used to modify variables that have already been declared?

Example:

changeme = 8; p = SomeSortOfPlot[changeme]; manipulate[Show[p],{changeme,1,10}] 

The main idea is that I want to make a plot with a specific mutable value, but declare it outside of manipulation.

Any ideas?

+4
source share
2 answers

One option is to use Dynamic [] and LocalizeVariables β†’ False.

Example:

 changeme = 8; p[x_] := Plot[Sin[t], {t, 1, x}]; { Manipulate[p[changeme], {changeme, 2, 9}, LocalizeVariables -> False], Dynamic[changeme] (* This line is NOT needed, inserted just to see the value *) } 

A "changeme" score after the Manipulate action will retain the last Manipulate value.

NTN!

+6
source

If you need something reasonably complex or flexible, it is better to use Dynamic and DynamicModule instead of Manipulate . The only exception is if you write demonstration .

For example, a very simple way to do what you want (in fact, you don’t even need Row and Slider if you just want to change changeme manually.)

 changeme=8; p[x_]:=Plot[Sin[t],{t,1,x}]; Row[{"x \[Element] (1, ",Dynamic[changeme],") ",Slider[Dynamic[changeme],{2,9}]}] Dynamic[p[changeme]] 
+2
source

All Articles