I generated n number of Sliders
using the idea from Manipulate with a variable number of sliders
But I need the updated values of these sliders to use to evaluate a function . I tried couple of things but I could not figure is out. I can get the values but even if I have 4 values , the dimension of the data is 1.How can I get these values?
ClearAll@Preplot;
SetAttributes[Preplot, HoldFirst];
Preplot[u_, vars_, poi_] := Module[{v1, v2, posv1, posv2, vars1} ,
v1 = poi[[1]]; (*Get the first variable for the plane of interest *)
v2 = poi[[2]]; (*Get the second variable for the plane of interest *)
posv1 = Position[vars, v1][[1]]; (* Position of v1 in vars list *)
posv2 = Position[vars, v2][[1]]; (* Position of v2 in vars list *)
lv1 = vars[[posv1[[1]], 2, 1]]; (*Lower limit of v1*)
lv2 = vars[[posv2[[1]], 2, 1]]; (*Lower limit of v2*)
rv1 = vars[[posv1[[1]], 2, 2]]; (*Upper limit of v1*)
rv2 = vars[[posv2[[1]], 2, 2]]; (*Uppler limit of v2*)
(*Print[{lv1,rv1,lv2,rv2}];*)
(* Create a new list of the other dimensions vars1*)
vars1 = Delete[vars, {{posv1[[1]]}, {posv2[[1]]}}];
countersvar = Dimensions[vars1][[1]]; (*Size of it*)
(* Lower and upper limits of n-2 variables *)
limsL = ConstantArray[0, countersvar];
limsR = ConstantArray[0, countersvar];
lims = ConstantArray[0, countersvar];
steplims = ConstantArray[0, countersvar];
midpoints = ConstantArray[0, countersvar];
transferd = ConstantArray[0, countersvar];
Do[
lims[[i]] = vars1[[i, 1]]; (*The variable *)
limsL[[i]] = vars1[[i, 2, 1]]; (*Lower Limit*)
limsR[[i]] = vars1[[i, 2, 2]]; (*Upper Limit*)
steplims[[i]] = (-vars1[[i, 2, 1]] + vars1[[i, 2, 2]])/25;
midpoints[[i]] =
vars1[[i, 2, 1]] + (-vars1[[i, 2, 1]] + vars1[[i, 2, 2]])/
2; (*Mid point for the sliders*)
, {i, countersvar}];
(*Dynamically create n-2 sliders*)
data = midpoints;
controls =
DynamicModule[{n = Length[midpoints]},
Column[{Dynamic[
Grid[Table[
With[{i = i}, {lims[[i]],
Slider[Dynamic[data[[i]]], {limsL[[i]], limsR[[i]],
steplims[[i]]}], Dynamic[data[[i]]]}], {i, n}]]],
Dynamic[data[[i]]];,
(*I need to do the following because I can't use poi[[
1]] as an argument in the plot3d*)
(*
and for some reason I need to create new u function in every \
change*)
u1 = u /. poi[[1]] -> v3;
u2 = u1 /. poi[[2]] -> v4;
(*Here is my problem I need to do evaluate the u function with \
the dynamic data which is changing as the user using sliders.
First I know that Dynamic@data[[1]] is a number.
So I need each sliders numeric value so I can evaluate the \
function wrt to corresponding slider value dynamically. *)
u2 = u2 /. lims[[1]] -> Dynamic@data[[1]];
u2 = u2 /. lims[[2]] -> Dynamic@data[[2]];
u2 = u2 /. lims[[3]] -> Dynamic@data[[3]];
u2 = u2 /. lims[[4]] -> Dynamic@data[[4]];
Print[
SetAccuracy[u2,
30]]; (*As you can see that the number are not evaluated *)
\
(*I need to evaluate u2 in a doloop of table because number of \
variables can change *)
(*Do[
u2=u2/.lims[[i]]\[Rule]Dynamic@data[[i]];
,{i,n}];*)
(* my goal is to able dynamically plot 2D slices of n \
dimensional function.
And user will change dynamically how this 2D evaluated as well \
as plane of interest by rerunning the code. *)
Plot3D[u2, {v3, lv1, rv1}, {v4, lv2, rv2},
PerformanceGoal -> "Quality", Mesh -> None,
ColorFunction -> Function[{x, y, z}, Hue[z]],
ImageSize -> Medium]
}, Center]];
Return[controls];
];
(* Variables and their limits *)
vars = {{x, {1, 2}}, {z, {3, 4}}, {y, {5, 6}}, {l, {7, 8}}, {w, {9,
10}}, {o, {11, 12}}};
poi = {x, w}; (*Plane of interest*)
u = Cos [x z] + Sin [Pi y l] + w^2/o; (*Function*)
Preplotvar = Preplot[u, vars, poi]
Dynamic[{1,2,3}]//Dimensions
gives{1}
, you need something likeDynamic@Dimensions@Setting@values
$\endgroup$a+b
instead of all this unclear procedures. $\endgroup$