I am trying to train a physics model and then check its profile. For this model, data for physics model is defined with:

data = Table[{x, physics[20, 20, 2, x]}, {x, 0, 0.5, 0.01}];

I also did something similar with a neural network and define its data with:

NNdata = Table[{data[[i]][[1]]} -> {data[[i]][[2]]}, {i, 1, Length[data]}];

Now for the profiles, I can check model profile with:

Plot[physics[20, 20, 2, x], {x, 0, 1}]

and for NN model,

Plot[trainedNN[[1]][i], {i, 0, 1}]

I wish to modify the models to take extra input such that I could now make plots as follows:

Plot3D[physics[20, y, 2, x], {x, 0, 1},{y, 0, 1}]

Now, my question is this: how do I modify code lines 2 and 4 (shown above) to accommodate y as a variable instead of a constant? Thank you in anticipation of your kind suggestions.


 physics[C1_, y_, w_, x_] := Module[{B, D, cos, sin, z},
   B = w*x;
   D = w*y;
   cos = Cos[D];
   sin = Sin[B];
   z = (C1)*sin*cos;
   z // N
  • 1
    $\begingroup$ Simply define physics[2, y, x] instead of physics[2, 20, x] $\endgroup$ Commented Apr 22 at 8:36
  • $\begingroup$ Many thanks @DanielHuber. I have now got this part. So what would be the implication of this on NNdata = Table[{data[[i]][[1]]} -> {data[[i]][[2]]}, {i, 1, Length[data]}]; and Plot[trainedNN[[1]][i], {i, 0, 1}]? $\endgroup$
    – Dean
    Commented Apr 23 at 19:18
  • $\begingroup$ Without knowing how "physics" and "data" are defined, it is hard to say. Note also "data[[i]][[1]]" can be written: "data[[i,1]]" $\endgroup$ Commented Apr 23 at 19:59
  • $\begingroup$ @DanielHuber, I have just added the requested information to my original question. Thank you! $\endgroup$
    – Dean
    Commented Apr 23 at 21:40
  • $\begingroup$ I do not see any parameters for the NN. What do you want to adjust? $\endgroup$ Commented Apr 24 at 6:52

1 Answer 1


Not really sure if this is what you're after, but maybe it'll at least lead to a clarification of the problem.

data2 = Table[{x, y, physics[20, y, 2, x]}, {x, 0, 1, 0.025}, {y, 0, 1, 0.025}];

To get the other structures...

NNdata = Map[Take[#, 2] -> #[[3]] &, data2, {2}]
(* This will have some additional list structure, but you could apply Flatten to it. *)


NNdata = Map[Take[#, 2] -> #[[3]] &, Catenate[data2]]
(* This one will be "flat". *)

If you want to use Part instead of Take, use this as the function to map:

#[[1 ;; 2]] -> #[[3]] &

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.