# User Input Through Dynamic

For my application, I am using Dynamic functionality to make a number of input fields through which a user can enter numbers. I then take these numbers and place them as the entries in a dynamic matrix. I then use the matrix as an input to a function I've written.

For some reason, I find that Mathematica cannot do anything with a matrix that is formed in this way. Though the matrix seems to be correctly formed, I find that Mathematica will not fully evaluate any expressions involving the dynamic matrix.

Here is some example code

DynamicModule[{numElements = 3, list1,list2},Dynamic@Column[

list1=Table[Symbol["n"<>ToString@i],{i,1,numElements}];
list2=Table[Symbol["t"<>ToString@i],{i,1,numElements}];
{
InputField[Dynamic@numElements],

Dynamic@Column[Flatten@Table[{Row[{With[{i=i},InputField[Dynamic[list1[[i]]],Number]], With[{i=i}, InputField[Dynamic[list2[[i]]], Number]]}]}, {i,1,numElements}]],

stack = Table[With[{i=i}, {Dynamic[list1[[i]]],Dynamic[list2[[i]]]}], {i,1,numElements}], Button["Press to find max", Print@Max[stack]]}
]]


This generates a simple user interface that allows you to control two lists list1 and list2 with entries n1, n2, n3, etc. and t1, t2, t3, etc., and it allows you to control their length. It then takes these values and makes a 2 x numElements matrix.

However, it doesn't seem like I can do anything with this matrix. Above I tried to print out its maximum value through a button. What could be the issue here?

• In all likelihood you have Dynamic positioned in the wrong place but we need to see your code. – Mike Honeychurch Jan 27 '15 at 6:21
• Thanks, guys. I just updated it with an example of the issue. – Noah Rubin Jan 27 '15 at 6:24
• @NoahRubin The example doesn't work for me, but the problem is what Mike said. You cannot evaluate Max[Dynamic[val1],Dynamic[val2]], it has to be Dynamic@Max[val1,val2]. The issue is similar to lite item six here. Once you wrap your number with Dynamic it doesn't go away. And it is not possible to determine if Dynamic something is larger than Dynamic something else, these are not numeric values. There is more about this in the documentation, if I recall correctly there is a paragraph specifically about where to place Dynamic. – C. E. Jan 27 '15 at 6:46
• There was one misplaced ] that creeped in there, I fixed it now and it should work. Thanks for your replies. If I need to do Dynamic@Max[val1,val2], how do I get that to evaluate when val1 and val2 need to be dynamic variables themselves, as in this example? It seems I can't actually do anything with the matrix of dynamic variables, even a multiplication of the matrix by 5, say, doesn't evaluate. – Noah Rubin Jan 27 '15 at 14:43

Button["Press to find max", Print@Max[{list1, list2}]]