1
$\begingroup$

Consider the following code that generates the desired output for a single vector of parameters (i.e., values of the controls). My purpose is to generate a set of vectors by fixing x and y while successively changing z, and repeating the same procedure for other parameters like fixing x and z while successively changing y and so on.

I like to create a table of successive iterations and record individual vectors of parameters and the associated functional values.

 f[x_, y_, z_] := x y + z^2 + y z;

 Manipulate[
    outputs= {{f[x, y, z], f[x, y, z]^2, f[x, y, z]^3}};
    TableForm[
        Map[If[NumericQ[#], If[# < 1 , Floor@#, Round[#, .1]], #] &, outputs, {-1}],
        TableHeadings -> {{{"x=" <> ToString[x], "y=" <> ToString[y],"z=" <> ToString[z]}}, {"Output 1", "Output 2", "Output 3"}}, 
        TableAlignments -> Right
             ],
  {x, 1, 20, 1},
  {y, 1, 20, 1},
  {z, .1, 1, .05}
 ]

An example table to be created looks like:

enter image description here

As is seen from the above table, I keep x and y variables fixed but z changes.

I like to create the above table using Manipulate.

$\endgroup$

2 Answers 2

1
$\begingroup$
ClearAll[g, f, x, y, z, inputlist]

f[x_, y_, z_] := x y + z^2 + y z;

g[{x_, y_, z_}] := {f[x, y, z], f[x, y, z]^2, f[x, y, z]^3}

Using a smaller range for the three variables:

ranges = {xrange, yrange, zrange} = {Range[3], Range[3], Range[2, 4] .05};

Take 2-subsets of ranges form pairs for each subset:

tuples = Tuples /@ (Reverse /@ Subsets[Reverse@{xrange, yrange, zrange}, {2}]);

Use tuples to define a function that creates the desired input lists for g:

inputlist[x_, y_, z_] := Join @@ MapIndexed[
  Insert[tuples[[#2[[1]]]], #, Thread[{Range[Length@tuples[[#2[[1]]]]], #2[[1]]}]] &, 
  {x, y, z}];

Use with Manipulate:

Manipulate[TableForm[Map[If[NumericQ[#], If[# < 1, Floor@#, Round[#, .1]], #] &, 
     g /@ inputlist[x, y, z], {-1}], 
   TableHeadings -> {({"x=" <> ToString[#], "y=" <> ToString[#2], 
        "z=" <> ToString[#3]} & @@@ inputlist[x, y, z]),
     {"Output 1",  "Output 2", "Output 3"}}, 
   TableAlignments -> Right], 
 {x, xrange, Slider},
 {y, yrange, Slider}, 
 {z, zrange, Slider}]

enter image description here

$\endgroup$
0
0
$\begingroup$

This is a partial answer because it does not have the flexibility of choosing a specific set of parameter values. It simply gives us sets of outputs:

 f[x_, y_, z_] := x y + z^2 + y z;

 Manipulate[
  outputs=Flatten[Table[{x, y, z, f[x, y, z], f[x, y, z]^2,f[x, y, z]^3},{x,1,5,1}, {y,1,5,1}, {z,.1,1,.1}], 1];
  TableForm[
     Map[If[NumericQ[#], If[# < 0 , Floor@#, Round[#, .1]], #] &, outputs[[n]],{-1}], 
     TableHeadings -> {None, {"x","y","z","output 1","output 2","output 3"}}, 
     TableAlignments -> Right
            ],
  {n, 1, Length[outputs], 1}
 ]
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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