## Inputting Dynamic Variables

Mathematica

### Next

• 1. Replace not spotting a replacement
Hi Folks, Seems the replace function is being a bit dim here. This fails: Sqrt[2 \[Pi]] \[Tau]^(3/2) /. Sqrt[ 2 \[Pi] \[Tau]] -> \[Mu] Apologies if this is an FAQ - I couldn't see anything about it. What do I need to do here to coerce Mathematica into making this replacement? I tried using the Collect function on tau first, but that didn't seem to work. I also tried re-writing the replacement rule as Sqrt[2 \[Pi]] \[Tau]^(3/2) /. Sqrt[ 2 \[Pi] ] t^(1/2) -> \[Mu] But still no joy. Anyone know? Many thanks, David.
• 2. BarChart Range
All, I have: BarChart[{43.34, 43.60, 44.19, 44.73}] Can someone show me how to set the range to run from 40 to 50?
• 3. Resume an aborted calculation?
Hi everybody, Is it possible to resume an aborted calculation (with Alt+.)? This would be a very convenient feature!!!! Cheers, psycho_dad

### Inputting Dynamic Variables

```I am trying to organize a set of dynamic variables that can be
modified either by using an input field or by updating the variables
from a file. When updating from a file I use a button.  I have a large
number of variables although in the toy example below I just give 3.
The modules will end up in a private context.  The idea below is that
the function pp[] contains a list of all the variables in a held form.
The list named vals can be obtained by reading from a file with new
values updated from new files.

Below I give an example that works. However, there must be a better
way... Having a ClearAll in a button seems a poor method for getting
back to symbols rather than values.  Any suggestion for a better
approach.?

ReSet[] := DynamicModule[{},
Dynamic[TableForm[
Table[InputLine[pp[][[i]]], {i, Length[iv]}]
]]
]

InputLine[{p_, q_}] := DynamicModule[{t},
ReleaseHold[ Row[{p, InputField[Dynamic[t]]}] /. t :> q]
]

ButtonReSet[] := Button["New values",
Module[{aa, bb},
ClearAll[a, b, c];
aa = ReleaseHold[pp[][[All, 2]]];
bb = pp[][[All, 1]] /. vals;
Evaluate[aa] = bb;]]

F[] := DynamicModule[{},
Dynamic[Plot[a x^2 + b x + c, {x, -1, 1}]]
]

ClearAll[pp, a, b, c];
iv = {a, b, c};
pp[] := {{"coff a ", Hold[a]}, {"coff b ", Hold[b]}, {"coff c ", Hold
[c]}};
vals = {"coff a " :> 2, "coff b " :> 3, "coff c " :> 4};
Dynamic[#] & /@ iv

ReSet[]

F[]

ButtonReSet[]

```

### Re: Inputting Dynamic Variables

```you may use method similar to the one used for bookmarks in manipulate

here is simple example

ClearAll[a, b, c];
vals := {a = 4, b = 3, c = 4};
Save[NotebookDirectory[] <> "\\1.val", vals]
vals := {a = 5, b = 3, c = 4};
Save[NotebookDirectory[] <> "\\2.val", vals]
ReSet[] :=
DynamicModule[{},
Dynamic[TableForm[Table[InputLine[pp[][[i]]], {i, Length[iv]}]]]]
InputLine[{p_, q_}] :=
DynamicModule[{t},
ReleaseHold[Row[{p, InputField[Dynamic[t]]}] /. t :> q]]
ButtonReSet[] := Button["reset values", vals]
ButtonBrowse[] :=
Button["browse for New values",
{NotebookDirectory[], {"val file" -> {"*.val"}}},
If[xfile =!= \$Canceled, Get[xfile]; vals]], Method -> "Queued"]
F[] := DynamicModule[{}, Dynamic[Plot[a x^2 + b x + c, {x, -1, 1}]]]
ClearAll[pp, a, b, c];
iv = {a, b, c};
pp[] := {{"coff a ", Hold[a]}, {"coff b ", Hold[b]}, {"coff c ",
Hold[c]}};
vals := {a = 2, b = 3, c = 4};
Dynamic[#] & /@ iv
ReSet[]
F[]
Row@{ButtonReSet[], ButtonBrowse[]}

```

### Who is online

Users browsing this forum: No registered users and 76 guest