# Apply Grad and Mod to Matrix

Let f:=x^3+y*x*z+z^3; Let mat = {{2, 2, 2}, {3, 1, 7}, {1, 6, 3},{4, 5, 1},{0,4,9}}; be a list of points .

I want to compute the first derivative of f at each point of m and then apply Mod 4 to each value of derivative.

I have calculated the first derivatives but I do not know how can apply Mod 4 to the derivatives at each point.

I have tried the following code :

grad[x_, y_, z_] = Grad[f, {x, y, z} ]
mat = {{2, 2, 2}, {3, 1, 7}, {1, 6, 3},{4, 5, 1},{0,4,9}};
grad[##] & @@@ mat //TableForm


## 1 Answer

f = x^3 + y x z + z^3;

grad = Plus @@ Map[D[f, #] &, {x, y, z}]


3 x^2 + x y + x z + y z + 3 z^2

Or

grad = Plus @@ Grad[f, {x, y, z}];


Same result

vals = Function[{x, y, z},
Evaluate@grad] @@@ {{2, 2, 2}, {3, 1, 7}, {1, 6, 3}, {4, 5, 1}, {0,4, 9}}


{36, 205, 57, 80, 279}

Mod[vals, 4]


{0, 1, 1, 0, 3}

Put together:

Function[{x, y, z},
Evaluate@Mod[Plus @@ Grad[f, {x, y, z}], 4]] @@@
{{2, 2, 2}, {3, 1, 7}, {1, 6, 3}, {4, 5, 1}, {0, 4, 9}}


{0, 1, 1, 0, 3}