# StreamPlot a gradient of a vector interpolating function

I have a vector-valued function, that is a result of some computation and I would like to plot streamlines of its gradient. I have to multiply the gradient with some vector first, because the gradient is matrix. But when I try to plot the result, all I get is an empty plot.

Here is a simplified code:

data1 = Flatten[Table[{{x, y}, RandomInteger[10]}, {x, 4}, {y, 4}], 1];
data2 = Flatten[Table[{{x, y}, RandomInteger[15]}, {x, 4}, {y, 4}], 1];

f1 = Interpolation[data1];
f2 = Interpolation[data2];
f = {{f1}, {f2}};

g = Grad[f[x, y], {x, y}];
h = g.{{1/2}, {1/2}};

StreamPlot[h[x, y], {x, 1, 4}, {y, 1, 4}]


Modify your definitions of f,g,h:

data1 = Flatten[Table[{{x, y}, RandomInteger[10]}, {x, 4}, {y,4}], 1];
data2 = Flatten[Table[{{x, y}, RandomInteger[15]}, {x, 4}, {y,4}],1];

f1 = Interpolation[data1];
f2 = Interpolation[data2];
f = {f1 , f2 }

g = Map[Grad[#[x, y], {x, y}] &, f]
h = Function[{x, y}, g . {{1/2}, {1/2}} // Flatten // Evaluate]

StreamPlot[h[x, y]   , {x, 1, 4}, {y, 1, 4}]


Hope it helps!

• It works, thank you. Commented Oct 5, 2022 at 16:02

Using Through.

Clear["Global*"];
SeedRandom[1];
data1 = Flatten[Table[{{x, y}, RandomInteger[10]}, {x, 4}, {y, 4}], 1];
data2 = Flatten[Table[{{x, y}, RandomInteger[15]}, {x, 4}, {y, 4}], 1];
f1 = Interpolation[data1];
f2 = Interpolation[data2];

f = {f1, f2};
g = Grad[Through@f[x, y], {x, y}];
StreamPlot[g . {{1/2}, {1/2}}, {x, 1, 4}, {y, 1, 4}]
`