Tell me more ×
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

1 Answer

up vote 6 down vote accepted

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
"...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

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.