sim icon

Vector Field Visualisation

This simulation shows a two-dimensional vector field. Hover the mouse over the simulation or click a location to see the field values, divergence and curl at that location.

The divergence of a 2-D vector field is \[ \nabla\cdot \vec{f} = \frac{\partial f_x}{\partial x} + \frac{\partial f_y}{\partial y} \]

The curl of a 2-D vector field is \[ |\nabla\times \vec{f}| = \frac{\partial f_y}{\partial x} - \frac{\partial f_x}{\partial y} \]

Both divergence and curl can be investigated with this simulation. Start by considering the uniform field. If this were a flow field, with a fluid of constant density, then the uniform length of the vectors show the fluid flowing in from the left and out to the right. There is no gain or loss of fluid in the field - there are no sources or sinks in the uniform field.

Repeat the same process with the source, sink and vortex fields. Investigate how these factors change the divergence and curl of the field. Recall, the divergence of a field refers to "matter" created or destroyed in the field and curl refers to rotation within the field.

Some custom fields to consider are

Position:
Field Value:
Divergence:
Curl:
x-Equation:
y-Equation:

Code Samples

Matlab
% Calculate a grid of points from -2-2 with 11 points in each direction
[x,y] = meshgrid(linspace(-2,2,11),linspace(-2,2,11));

% Calculate the vector field (source field)
fx = x;
fy = y;

% Plot arrows
figure(1)
quiver(x, y, fx, fy);
Gnuplot
# Define the vector field (source field)
fx(x, y) = x/4;
fy(x, y) = y/4;

# Setup the plot limits and number of vectors
set xrange [-2:2]; set yrange [-2:2]
set samples 9; set isosamples 9

# Generate the plot using a special file
plot "++" using 1:2:(fx($1, $2)):(fy($1, $2)) with vectors notitle
Python
import numpy as np
import matplotlib.pyplot as plt

# Calculate a grid of points from -2-2 with 11 points in each direction
[x,y] = np.meshgrid(np.linspace(-2,2,11),np.linspace(-2,2,11));

# Calculate the vector field (source field)
fx = x;
fy = y;

# Plot arrows
plt.figure();
plt.quiver(x, y, fx, fy);
plt.show();