Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

Please consider the following:

InputField[Dynamic[X1], Number, Alignment -> Center];
InputField[Dynamic[X2], Number, Alignment -> Center];
Slider[Dynamic[Y1], {0, 200, 1}];
Slider[Dynamic[Y2], {0, 200, 1}];
Dynamic[FK, Dynamic[X1*(1 + Y1/100)]];
Dynamic[MK, Dynamic[X2*(1 + Y2/100)]];
Dynamic[HK, Dynamic[FK + MK]];
HeadTest = NumberQ[#] & /@ {X1, X2, Y1, Y2, FK, MK, HK}

Why would FK,MK and HK not have the head Number? (I guess I just did not understand how to use Dynamic and DynamicModule.)

share|improve this question
2  
You do not need to create a pure function (# &) to Map (/@) an existing one: NumberQ[#] & /@ is not needed, NumberQ /@ will suffice. –  Mr.Wizard Aug 17 '12 at 10:33
    
Related: (1864), (2972), (5817) –  Mr.Wizard Sep 2 '13 at 7:21

1 Answer 1

up vote 8 down vote accepted

For any beginner these are a must:

Because for your code as it is right now, with no additional definitions, those variables are symbols - you did not define them numerically (Dynamic got nothing to do with it).

X1 // Head

Symbol

Now if you do this you'll get your 'Number':

{X1, X2, Y1, Y2, FK, MK, HK} = Range[7];
InputField[Dynamic[X1], Number, Alignment -> Center];
InputField[Dynamic[X2], Number, Alignment -> Center];
Slider[Dynamic[Y1], {0, 200, 1}];
Slider[Dynamic[Y2], {0, 200, 1}];
Dynamic[FK, Dynamic[X1*(1 + Y1/100)]];
Dynamic[MK, Dynamic[X2*(1 + Y2/100)]];
Dynamic[HK, Dynamic[FK + MK]];
HeadTest = NumberQ[#] & /@ {X1, X2, Y1, Y2, FK, MK, HK}

{True, True, True, True, True, True, True}

I am not sure what you trying to get, but generally the price of dynamic updating is change of Head. Maybe this example will help to understand - turn your attention to what changes, what evaluates and what does not:

{Slider[Dynamic[x]], Dynamic[x], x, Dynamic[x] // Head, x // Head, 
 Sin[x], Sin[Dynamic@x], Dynamic@Sin[x]}

enter image description here

share|improve this answer
1  
"...generally the price of dynamic updating is change of Head." Great insight into and explanation for how to think about dynamic updating. +1 –  Jagra Aug 17 '12 at 12:56
    
Vitaliy, thanks for identifying the duplicate. Please vote to close the new question as such. –  Mr.Wizard Sep 2 '13 at 7:14
    
Vitaliy, we get this question often enough that I believe it needs to be added to the pitfalls post. You have the best reviewed answers here on the subject. Would you be willing to write one? If you do please also include whatever part of John Fultz's answer seem appropriate, with attribution. If you do not wish to do this I will try my best. –  Mr.Wizard Sep 2 '13 at 7:26
    
@Mr.Wizard I would appreciate if you could write this. And yes John's answer of course is super. –  Vitaliy Kaurov Sep 2 '13 at 7:30
    
Okay, I'll try. When you see it come up (perhaps not tonight) please review and correct it as needed. –  Mr.Wizard Sep 2 '13 at 7:31

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.