Display/manipulating numeric values inside a DynamicModule[]

*To*: mathgroup at smc.vnet.net*Subject*: [mg110744] Display/manipulating numeric values inside a DynamicModule[]*From*: Leo Alekseyev <dnquark at gmail.com>*Date*: Sun, 4 Jul 2010 03:10:13 -0400 (EDT)

Recently, I've been using DynamicModules[] to interactively explore some plots that I make -- by introducing a locator, whose coordinates allow me to trace the plotted data in some fashion (e.g. by displaying the function value for the x coordinate of the locator, or finding the closest plotted point to a locator in a ListPlot, etc.) My problem is that I haven't figured out a good way to display dynamically updated values as part of the plot or, for that matter, perform manipulations with the dynamic values. The reason seems to be that once an expression has head Dynamic, the behavior of many familiar functions changes (e.g. NumericQ on a dynamic value returns False, which makes it impossible to numerically evaluate Re or Im, etc.) Below is a simple example of what I'm doing, and workaround that I came up with. Here are some concrete questions: (a) is there a better way to display the dynamic values "a" and "b" inside a formatted string?.. My workaround is to use something like Grid[{{"a:", a, "; b:", b}}], which is not entirely satisfactory (b) is there a better way of doing arithmetic with the dynamic value "a"? I would like to be able to say something like b = Re[a], as opposed to b = Dynamic[Re[whatever long expression I might have used to compute a]] (c) are there any good examples of using Dynamic to trace plots, as described above?.. I'm sure I'm not the only one who is doing this :) Clear[f]; f[x_] := x^2 + I; DynamicModule[{p = {1, 1}, a, b}, a := Dynamic[f[p[[1]]]]; b := Dynamic[Re@f[p[[1]]]]; Show[{Plot[{Re[f[x]]}, {x, -2, 2}, Frame -> True], Graphics@Locator[Dynamic[p], Appearance -> {Large}], Graphics@Text[Grid[{{"a:", a, "; b:", b}}], {-1, 2}]}]]