Fractals/Mathematics/Vector field

Vector field[1]

Here mainly numerical methods for time independent 2D vector fields are described.


  • vector function is a function that gives vector as an output
  • field : space (plane, sphere, ... )
  • field line is a line that is everywhere tangent to a given vector field
  • scalar/ vector / tensor:
    • Scalars are real numbers used in linear algebra. Scalar is a tensor of zero order
    • Vector is a tensor of first order. Vector is an extension of scalar
    • tensor is an extension of vector


Forms of 2D vector:[2]

  • [z1] ( only one complex number when first point is known , for example z0 is origin
  • [z0, z1] = two complex numbers
  • 4 scalars ( real numbers)
    • [x, y, dx , dy]
    • [x0, y0, x1, y1]
    • [x, y, angle, magnitude]
  • 2 scalars : [x1, y1] for second complex number when first point is known , for example z0 is origin


The numerical gradient of a function:

  • "is a way to estimate the values of the partial derivatives in each dimension using the known values of the function at certain points."[3]

Gradient function G of function f at point (x0,y0)

  G(f,x0,y0) = (x1,y1)


  • function f
  • point (x0,y0) where gradient is computed


  • vector from (x0,yo) to (x1,y1) = gradient



  • "The gradient is calculated as: (f(x + h) - f(x - h)) / (2*h) where h is a small number, typically 1e-5 f(x) will be called for each input elements with +h and -h pertubation. For gradient checking, recommend using float64 types to assure numerical precision."[5]
  • in matlab[6][7]
  • in R[8]
  • python[9]

Field typesEdit

  • time independent (= stationary = Steady ) or time dependent ( unsteady flow)
  • dimension: 2D, 3D, ...
  • mesh ( grid) type
  • scalar function
    • potential
    • electric, magnetic, ...
  • vector function
    • equation ( for symbolic computations) - ODE
    • numerical values ( for numerical computations)
  • field line integration method (scheme):[10]


  • start with
    • plane (parameter plane or dynamic plane)
    • scalar function
    • vector function
  • create scalar field using scalar function ( potential)
  • create vector field from scalar field using vector function ( gradient of the potential)
  • compute:

Field line computingEdit


  • Field line tracing = curve sketching
  • drawing contour maps ( in computer graphic) = Numerical continuation ( in math)

Methods ( solvers) available for the field-lines[11]

  • Euler
  • RK2
  • RK3
  • RK4 - the original authors of those sampling algorithms; Herr Runge und Herr Kutta.
  None of these 4 methods generate an exact answer, but they are (from left to right) increasingly more accurate. They also take (from left to right) more and more time to finish as they require more samples for each iteration.
  You won't be able to create reliably closed curves using iterative sampling methods as small errors at any step may be amplified in successive steps. There is also no guarantee that the field-line ends up in the exact coordinate where it started.
  The Grasshopper metaball solver on the other hand uses a marching squares algorithm which is capable of finding closed loops because it is a grid-cell approach and sampling inaccuracy in one area doesn't carry over to another. 
  However the solving of iso-curves is a very different process    from the solving of particle trajectories through fields. ... 
  Typically field lines shoot to infinity rather than form closed loops. That is one reason why I chose the RK methods here, because marching-cubes is very bad at dealing with things that tend to infinity.[12]


Construction of a field line

Given a vector field   and a starting point   a field line can be constructed iteratively by finding the field vector at that point  . The unit tangent vector at that point is:  . By moving a short distance   along the field direction a new point on the line can be found


Then the field at that point   is found and moving a further distance   in that direction the next point of the field line is found


By repeating this and connecting the points,the field line can be extended as far as desired. This is only an approximation to the actual field line, since each straight segment isn't actually tangent to the field along its length, just at its starting point. But by using a small enough value for  , taking a greater number of shorter steps, the field line can be approximated as closely as desired. The field line can be extended in the opposite direction from   by taking each step in the opposite direction by using a negative step  .

rk4 numerical integration methodEdit

Fourth-order Runge-Kutta (RK4) in case of 2D time independent vector field

  is a vector function that for each point p

p = (x, y)

in a domain assigns a vector v


where each of the functions   is a scalar function:


A field line is a line that is everywhere tangent to a given vector field.

Let r(s) be a field line given by a system of ordinary differential equations, which written on vector form is:



  • s representing the arc length along the field line
  •   is a seed point

Given a seed point   on the field line, the update rule ( RK4) to find the next point  along the field line is[13]



  • h is the step size
  • k are the intermediate vectors:


Visualisation of vector fieldEdit

Plot types (Visualization Techniques for Flow Data) : [14]

  • Glyphs = Icons or signs for visualizing vector fields
    • simplest glyph = Line segment (hedgehog plots)
    • arrow plot = quiver plot = Hedgehogs (global arrow plots)
  • Characteristic Lines [15]
    • streamlines = curve everywhere tangential to the instantaneous vector (velocity) field (time independent vector field). For time independent vector field streaklines = Path lines = streak lines [16]
  • texture (line integral convolution = LIC)[17]
  • Topological skeleton [18]
    • fixed point extraction ( Jacobian)



    • white noise
    • original vector field

LIC examples:

quiver plotEdit


  • "A quiver plot displays velocity vectors as arrows with components (u,v) at the points (x,y)"[19]

stream plotEdit

A stream plot uses stream lines

Example fieldsEdit

Potential of Mandelbrot setEdit






See alsoEdit


  1. Vector field in wikipedia
  2. Euclidian vector in wikipedia
  3. matlab : gradient function
  4. stackoverflow question: is-there-any-standard-way-to-calculate-the-numerical-gradient
  5. nnp_numerical_gradient by Mamy Ratsimbazafy
  6. matrixlab-examples : gradient
  7. matlab-function-gradient-numerical-gradient by itectec
  8. numDeriv : grad
  9. numpy : gradient
  10. Numerical Methods for Particle Tracing in Vector Fields by Kenneth I. Joy
  11. liruics : Introduction to Scientific Visualization - Flow Field
  12. grasshopper3d forum: field-lines-how-to-rebuild-and-make-periodic?overrideMobileRedirect=1
  13. Classification and visualisation of critical points in 3d vector fields. Master thesis by Furuheim and Aasen
  14. Flow Visualisation from TUV
  15. Data visualisation by Tomáš Fabián
  16. A Streakline Representation of Flow in Crowded Scenes from UCF
  17. lic by Zhanping Liu
  18. Vector Field Topology in Flow Analysis and Visualization by Guoning Chen
  19. matlab ref : quiver plot