# How to use a Table to generate numerical data from tridimensional scalar or vector function? [closed]

I am interested to generate numerical values for a scalar and vector function (both are complex functions).

My question and concern are how is possible to evaluate if the functions have three coordinates (variables). I mean to obtain a numerical Table of two values [x, y] or [x,y,z] numerical data and after be able to plot them.

Here, is the code but the implementation is incorrect, Please run the code

Clear["Global*"];

L = 15; step = 0.5; (*size grid and numerical step*)
gh = Sin[ x +    0.5  y  + 5  z]  + Exp[I 2 x + I y + I 0.5 z]

gradf = Grad[gh, {x, y, z}]

data1 = Table[gh /. { y -> 0,  z -> 0}, {x, -L, L, step}]

data2 = Table[gradf /. { y -> 0,  z -> 0}, {x, -L, L, step}]

data3 = Table[Norm[gradf /. { y -> 0,  z -> 0}], {x, -L, L, step}]


Of course, the data can be generated forcing the problem, after using and defining two variables as zero, but they are tridimensional functions and they are not one-dimensional function?

## closed as off-topic by m_goldberg, Alex Trounev, Henrik Schumacher, Öskå, MarcoBAug 6 at 1:08

This question appears to be off-topic. The users who voted to close gave this specific reason:

• "This question arises due to a simple mistake such as a trivial syntax error, incorrect capitalization, spelling mistake, or other typographical error and is unlikely to help any future visitors, or else it is easily found in the documentation." – m_goldberg, Alex Trounev, Öskå
If this question can be reworded to fit the rules in the help center, please edit the question.

• Why not make gh and gradf functions instead of expressions with gh[x_, y_, z_] := ...? – lirtosiast Aug 4 at 3:59
• @lirtosiast, Yes I already used this form you mention, but it does not work properly also this doesn't solve the problem. – irondonio Aug 4 at 5:13
• I don't understand the question. "but the implementation is incorrect" -- Please explain what exactly what makes you think so. – Henrik Schumacher Aug 5 at 15:15

## 1 Answer

@lirtosiast's comment shows the right way to solve your problem:

gh[x_, y_, z_] :=Sin[x + 0.5 y + 5 z] + Exp[I 2 x + I y + I 0.5 z] //Evaluate

gradf[x_, y_, z_] = Grad[gh[x, y, z], {x, y, z}]

data1 = Table[gh[x, 0, 0] , {x, -L, L, step}];
(* {5.28257, 3.30335, 2.47209,,...}*)

data2 = Table[gradf[x, 0, 0]   , {x, -L, L, step}]
(* {-2.73575 + 0.308503 I, -1.36788 + 0.154251 I,-4.29246 +0.0771257 I}, {-1.68219 - 1.49612 I, -0.841096 -0.748058 I, -2.10644 - 0.374029 I},...}*)

data3 = Table[Norm@gradf[x, 0, 0]   , {x, -L, L,step}]
(*{5.28257, 3.30335, 2.47209,,...}*)

• Thanks, but there is the problem still remains because the function (scalar or vector) depends on [x, y, z] in the output is only a function of x. The data is generated imposing the condition [x,0,0]. The question is if there any way to generate a uniform grid (mesh grid) for all variables [x,y,z] at the same time and generate a numerical table? The main aim is to sample numerically a function scalar or vector using Mathematica. – irondonio Aug 4 at 14:14
• @irondonio Table[gh[x, y, z], {x, -L, L, step}, {y, -L, L, step}, {z, -L, L, step}]? – MelaGo Aug 5 at 2:31
• Thanks for your comments, @MelaGo. These codes can generate a Table. but I expect to have a Table with a single numeric value after evaluating numerically a scalar function, Any comment about how can it be implemented? – irondonio Aug 5 at 10:47
• @irondonio I'm not sure exactly what you mean. You do get a single value (though a complex one). You can flatten the table with Flatten`... – MelaGo Aug 5 at 17:54
• Thanks, @MelaGo, sorry for the confusion, I mean a single value, after the evaluation of the function f[x,y,z], in the case of the complex function, should be the norm as in the vector case. The point is the output should be represented as a pair of numbers [x,f[x,y,z]] where f[x,y,z] were previously evaluated and represent a simple real value – irondonio Aug 6 at 5:53