# Plotting the divergence of a vector field along a parametric line

I find numerically a scalar field that satisfy Poisson equation. From its gradient I derive a vector field.

scalarField =
NDSolveValue[{D[u[x, y], x, x] + D[u[x, y], y, y] == -Exp[-y - x],
u[x, 0] == u[x, 1] == u[-1, y] == u[1, y] == 0},
u, {x, -1, 1}, {y, 0, 1}]
vectorField = {-D[scalarField[x, y], x], -D[scalarField[x, y], y]}


I want to plot the divergence of the vector field along a line. For example: the one in the figure generate by the following code (x == -0.3; 0 <= y <= 1).

Show[StreamPlot[vectorField, {x, -1, 1}, {y, 0, 1}, AspectRatio -> 1,
FrameLabel -> {"x", "y"}],
Graphics[{Thick, Line[{{-0.3, 0}, {-0.3, 1}}]}]]


fieldDivergence = Div[vectorField, {x, y}]


I can make a 3D plot of it with

Plot3D[fieldDivergence, {x, -1, 1}, {y, 0, 1} , Mesh -> All,
AxesLabel -> {"x", "y", "Div"}]


But I don't know how to proceed to do a 2D plot. I tried

Plot[fieldDivergence[-0.3, y], {y, 0, 1}]


Which gives an empty plot. From looking here I suspect it has to do with the fieldDivergence entity not returning a number.

I don't know what approach to try. How do I plot the divergence of a vector field along a parametric line?

• Is this perhaps what you are looking for? Plot[fieldDivergence /. x -> -0.3, {y, 0, 1}] Jun 8 '17 at 20:52

Plot[fieldDivergence /. {x -> -.3, y -> yy}, {yy, 0, 1}]


For a vector to be shown you need to plot an area. Thus simply restrict your plot to the narrow area enclosing your chosen line:

Show[StreamPlot[vectorField,
{x, -.31, -.29},
{y, 0, 1},
AspectRatio -> 10,
FrameLabel -> {"x", "y"}],
Graphics[{Thick, Line[{{-0.3, 0}, {-0.3, 1}}]}]]

• I am not trying to plot the vector, but its divergence in the points of a given line/curve. Jun 9 '17 at 17:49