How to Display Dynamic Values as Plain Numbers?

  • Context: Mathematica 
  • Thread starter Thread starter Swamp Thing
  • Start date Start date
  • Tags Tags
    Dynamic Value
Join the discussion
Ask a follow-up here, or get your own question answered by working scientists, mathematicians and engineers — people, not an autocomplete.
Real named experts · corrections over time · the nuance an AI answer skips
6 replies · 2K views
Swamp Thing
Insights Author
Messages
1,062
Reaction score
819
TL;DR
How to force expressions containing dynamic variables to display as numeric values?
In the example below, x is static while x1 is a dynamic copy of x. Also, y and z are similar expressions containing x and x1 respectively.
If we evaluate expressions containing x and x1, they display in numeric and mathematical formats, respectively (y and z below). How can I display z as a plain numeric value just as y is displayed?
dynamic.png
 
Physics news on Phys.org
Something is wrong with your y. That value is not correct and it should not be displayed like that. However, I also cannot get it to display as a single decimal. The closest I get is

Code:
z = N[Sqrt[x1/2/Pi]]

But this gives ##0.398942 \sqrt{200}##
 
Dale said:
Something is wrong with your y.

Yes, there was. I corrected that, and now the y needs to be fed through N[] in order to see the numeric.

jedishrfu said:
Have you tried the eval() function on your dynamic expression?
Neither N[] nor Evaluate[] are helpful in the dynamic case.

dynamic.png
 
This may explain the problem (but I'm still trying to understand it fully) :
https://reference.wolfram.com/language/tutorial/IntroductionToDynamic.html#1063215934

It seems to imply that you can't use Dynamic as an input to other functions, because it never goes to the kernel. It's just a directive for the front end.

The solution is probably to make sure that Dynamic encloses all the code that is going to use the variable that we want to make dynamic. I am experimenting along these lines.

But if we put Dynamic around a whole block of code, and if that block of code references many global variables, then it has no way to know which ones we want it to watch and respond to. All global variables would become dynamic. There must be a way to make it dynamic with respect to some selected variables and ignore changes in others?