Mathematica How to Display Dynamic Values as Plain Numbers?

  • Thread starter Thread starter Swamp Thing
  • Start date Start date
  • Tags Tags
    Dynamic Value
Click For Summary
The discussion centers on the challenges of displaying dynamic and static variables in a mathematical context, specifically how to represent a dynamic variable (x1) in a numeric format similar to a static variable (x). The user expresses confusion over the output of expressions involving x and x1, noting that while y displays correctly, z does not, and attempts to convert z into a plain numeric value have been unsuccessful. The conversation highlights the limitations of using functions like N[] and Evaluate[] with dynamic expressions, as dynamic variables do not interact with the kernel in the expected way. A potential solution involves enclosing all relevant code within a Dynamic directive, but this raises concerns about managing multiple global variables and ensuring that only specific variables are monitored for changes. The need for a method to selectively apply dynamic behavior to certain variables while ignoring others is emphasized as a key issue to resolve.
Swamp Thing
Insights Author
Messages
1,045
Reaction score
775
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
That is weird. Why is y displayed like that? It should be displayed like z.
 
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}##
 
Is it because defining x1 as dynamic that symbolic evaluation is being done?

Have you tried the eval() function on your dynamic expression?
 
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?
 

Similar threads

  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 5 ·
Replies
5
Views
2K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 14 ·
Replies
14
Views
3K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 6 ·
Replies
6
Views
2K
  • · Replies 1 ·
Replies
1
Views
4K
  • · Replies 1 ·
Replies
1
Views
7K
  • · Replies 1 ·
Replies
1
Views
3K
Replies
7
Views
2K