# [✓] List layout using Grid?

GROUPS:
 Hello friends, I am new using Wolfram language and I have a problem. The issue is: I create two lists pc = Dynamic [Function [g, Rationalize [g, ct * 0.1]] / @ RandomReal [{- 10, 10}, n + 1]]; qc = Dynamic [Function [g, Rationalize [g, ct * 0.1]] / @ RandomReal [{- 10, 10}, m + 1]];  m & n are obtained by sliders and ct by means of a radio button The pc and qc lists seem to be calculated correctly but when I use them in a Grid: Grid [{pc, qc}, Frame -> All] Does not seem to recognize them properly. The output is: Grid [{{8, -2,5,4}, {- 3,7,1,4,5-1}}, Frame-> All] What am I doing wrong?
1 year ago
15 Replies
 Gianluca Gorni 1 Vote I would move the definitions pc= and qc= inside Dynamic, so that the Dynamic wrapper does not interfere with Grid: Slider[Dynamic[m], {1, 10, 1}] Slider[Dynamic[n], {1, 10, 1}] RadioButtonBar[Dynamic[ct], 10^-Range[10]] Dynamic[pc = Rationalize[RandomReal[{-10, 10}, n + 1], ct*0.1]] Dynamic[qc = Rationalize[RandomReal[{-10, 10}, m + 1], ct*0.1]] Dynamic[Grid[{pc, qc}, Frame -> All]] 
1 year ago
 I move pc and qc into Dynamic, as you advise, it works well. But there is another related problem, I will try to explain with the code: DynamicModule[{pc, n = 3, qc, m = 3, g, ct = 5}, Column[{ Row[{ Column[{ Slider[Dynamic[n], {1, 8, 1}, Appearance -> "Labeled"], Slider[Dynamic[m], {1, 8, 1}, Appearance -> "Labeled"] }], RadioButtonBar[ Dynamic[ct], {5 -> Z], 1 -> Q]}]} ], Dynamic[ pc = Function[g, Rationalize[g, ct*0.1]] /@ RandomReal[{-10, 10}, n + 1]], Dynamic[ qc = Function[g, Rationalize[g, ct*0.1]] /@ RandomReal[{-10, 10}, m + 1]], Dynamic[Grid[{pc, qc}, Frame -> All]] } ] ] If I run the above code, I get:As expected, but I want to show, as a final result, only the grid. To hide the lists pc and qc I replace commas by semicolons where pc and qc are defined: Dynamic[pc = Function[g, Rationalize[g, ct*0.1]] /@ RandomReal[{-10, 10}, n + 1]]; Dynamic[qc = Function[g, Rationalize[g, ct*0.1]] /@ RandomReal[{-10, 10}, m + 1]]; Dynamic[Grid[{pc, qc}, Frame -> All]] But now the result is:I have previously programmed with functional languages like Haskell but this one has me confused. Your help is and will be appreciated.
1 year ago
 l van Veen 1 Vote Grid[{Sequence @@ pc, Sequence @@ qc}, Frame -> All] 
1 year ago
 Hello I Van, I did what you advised me with a small change: DynamicModule[{pc, n = 3, qc, m = 3, g, ct = 5}, Column[{ Row[{ Column[{ Slider[Dynamic[n], {1, 8, 1}, Appearance -> "Labeled"], Slider[Dynamic[m], {1, 8, 1}, Appearance -> "Labeled"] }], RadioButtonBar[ Dynamic[ct], {5 -> \[DoubleStruckCapitalZ], 1 -> \[DoubleStruckCapitalQ]}]} ], pc = Dynamic[ Function[g, Rationalize[g, ct*0.1]] /@ RandomReal[{-10, 10}, n + 1]], qc = Dynamic[ Function[g, Rationalize[g, ct*0.1]] /@ RandomReal[{-10, 10}, m + 1]], Dynamic[Grid[{Sequence @@ pc, Sequence @@ qc}, Frame -> All]] } ] ] As you noticed, I wrapped the Grid inside a Dynamic. However I still have a problem, the partial results and the final result do not match:I guess it's due to the call to RandomReal. But I do not know how to make them match, any use of pc or qc will invoke RandomReal again. I appreciate your help
1 year ago
 l van Veen 1 Vote Hi Jorge, I don't understand exactly what you need. Your module will evaluate indeed different numbers after you change the values of m or n. If you want these values to remain the same I suggest you generate random numbers first ( a list of 9 numbers ) and then select these numbers with Part with the n and m. Or is this not what you mean because then you only select from a list. Could you show me what you expect when selecting m and n back and forth? DynamicModule[{pc, n = 3, qc, m = 3, g, ct = 5, rnd = RandomReal[{-10, 10}, 10]}, Column[{Row[{Column[{Slider[Dynamic[n], {1, 8, 1}, Appearance -> "Labeled"], Slider[Dynamic[m], {1, 8, 1}, Appearance -> "Labeled"]}], RadioButtonBar[ Dynamic[ct], {5 -> \[DoubleStruckCapitalZ], 1 -> \[DoubleStruckCapitalQ]}]}], pc = Dynamic[ Function[g, Rationalize[g, ct*0.1]] /@ rnd[[;; n + 1]]], qc = Dynamic[ Function[g, Rationalize[g, ct*0.1]] /@ rnd[[;; m + 1]]], Dynamic[Grid[{Sequence @@ pc, Sequence @@ qc}, Frame -> All]]}]] 
1 year ago
 Hello I van,I want to generate two queues (qc and pc) of random numbers. Each queue should be generated "just in time" when the user manipulates the corresponding slider.The queues will be used in a simulation system and the grid is a simplification of the actual output. It is important that the simulation be carried out with the same random numbers shown in the Grid.Generating a larger list and taking n or m numbers at the time should work but: how long should it be initially? When should it regenerate? and so.I hope I have explained clearly, thank you for your suggestions and contributions.
1 year ago
 l van Veen 1 Vote Hi Jorge, I think you should then use the suggestion from Jorge Manrique . This is what you want. The Set (=) is used inside Dynamic and is the regular way to do it. DynamicModule[{pc, n = 3, qc, m = 3, g, ct = 5}, Column[{Row[{Column[{Slider[Dynamic[n], {1, 8, 1}, Appearance -> "Labeled"], Slider[Dynamic[m], {1, 8, 1}, Appearance -> "Labeled"]}], RadioButtonBar[ Dynamic[ct], {5 -> \[DoubleStruckCapitalZ], 1 -> \[DoubleStruckCapitalQ]}]}], Dynamic[pc = Function[g, Rationalize[g, ct*0.1]] /@ RandomReal[{-10, 10}, n + 1]], Dynamic[qc = Function[g, Rationalize[g, ct*0.1]] /@ RandomReal[{-10, 10}, m + 1]], Dynamic@Grid[{pc, qc}, Frame -> All]}]] 
1 year ago
 Yes, it works great. But if I change the commas by semicolons it does not work.Is there any way to hide the intermediate results in the notebook? I mean just show the Grid
1 year ago
 Gianluca Gorni 1 Vote How about using Manipulate: numberList[n_, ct_] := Rationalize[RandomReal[{-10, 10}, n + 1], ct*0.1]; Manipulate[With[{pc = numberList[n, ct], qc = numberList[m, ct]}, Column[{pc, qc, Grid[{pc, qc}, Frame -> All]}]], {n, 1, 8, 1}, {m, 1, 8, 1}, {{ct, 5}, {5 -> \[DoubleStruckCapitalZ], 1 -> \[DoubleStruckCapitalQ]}}] 
1 year ago
 l van Veen 1 Vote Hi Gorni, Yes you are right. I believe Manipulate is the way to go also with all the other stuff Jorge wants to do around it.
1 year ago
 Hello guys, Gianluca's code does the job.I confess that I tried to avoid using Manipulate, for me it is very opaque and esoteric.I still wonder why if I replace commas with semicolons the former code stops workingSemicolons are used to avoid the outs, are they?Last question, I promise, how can I place the radio button to the right of the sliders?Thank you very much for your help
1 year ago
 Gianluca Gorni 1 Vote I think Dynamic triggers only when displayed. With Clear[a]; Dynamic[a = 1]; Dynamic[a] the command a=1 has no effect, because it is not displayed. Compare with Clear[a]; Dynamic[a = 1] Dynamic[a] I often get confused too.
 Shenghui Yang 1 Vote you may follow this link , like Manipulate[Plot[Sin[a x + b], {x, 0, 6}], Row[{Control@{a, 1, 4}, Control@{b, 0, 10}}]] vs Manipulate[Plot[Sin[a x + b], {x, 0, 6}], {a, 1, 4}, {b, 0, 10}]