项目作者: PabRod

项目描述 :
A couple of functions for computing path integrals and scalar potentials
高级语言: Matlab
项目地址: git://github.com/PabRod/Potential.git
创建时间: 2017-03-10T11:05:51Z
项目社区:https://github.com/PabRod/Potential

开源协议:

下载


Potential

A couple of functions for computing path integrals and scalar potentials in an arbitrary number of dimensions.

Requires Matlab R2012a or newer.

Background

The main purpose of this piece of code is computing the scalar potential function associated to a given vector field. In order to do so, we’ll introduce the tool of path integral.

Path integrals

A path integral, also known as line or curve integral, is an integral where the integrand is evaluated along a curve:

GeneralPathIntegral

The usual way of evaluating a path integral requires the specification of a parameterization of the curve:

GeneralParametric

So our path integral becomes the classical integral:

PathIntegralEvaluation

Gradient fields

A gradient field is a vector field that can be derived as the gradient of a scalar field. For historical reasons, a minus sign is introduced

GradientField

Path integrals over gradient fields depend only on the beginning and finishing points of the integration, being independent of the particular curve chosen to integrate between them. So, provided f is a gradient field, we can make non-ambiguous sense of an expression like:

PathOverGradient

One straightforward consequence of this is that any path integral over a gradient field and along a closed curve (which starts and ends at the same point) should equal zero.

PathOverClosedPath

Scalar potentials

Provided a gradient field, we can compute the associated scalar potential using:

Potential

Where the value of the potential at x_0 is an arbitrary integration constant.

Examples of usage

Path integral along a parametric curve

  1. % Underlying field
  2. field = @(x) [-x(2), -x(1)];
  3. % Parametric curve specification
  4. curve = @(t) [t, t];
  5. dcurve = @(t) [1, 1];
  6. tmin = -2;
  7. tmax = 1;
  8. % Path integral
  9. s = PathIntegral(field, curve, dcurve, tmin, tmax);

Path integral over a gradient field

In the case of gradient fields the integral only depends in the initial and final points of the integration path. Thus, we can specify only those points regardless of the integration curve

  1. % Underlying field
  2. field = @(x) [-2.*x(1).*x(2), -x(1).^2];
  3. % Initial and final points
  4. x0 = [1 2];
  5. x = [3 4];
  6. % Path integral
  7. s = PathIntegral(field, x0, x);

Path integral using symbolic functions

For those used to work with the symbolic toolbox of Matlab

  1. % Define symbolic variables
  2. syms x y t;
  3. % Underlying field
  4. field(x,y) [-y, -x];
  5. % Parametric curve specification
  6. curve(t) = [t, t];
  7. tmin = -2;
  8. tmax = 1;
  9. % Path integral
  10. s = PathIntegral(field, curve, tmin, tmax);

One-dimensional potential

Given a gradient field, we can compute the associated potential

  1. % Underlying field
  2. field = @(x) -4*x.^3 + 3*x.^2 + 10*x - 1;
  3. % Grid characteristics
  4. x = -2:0.05:3;
  5. % Setting the reference potential
  6. x0 = -2;
  7. V0 = 0;
  8. % Compute the potential
  9. V = Potential(field, V0, x0, x);
  10. % Plot results
  11. plot(x, V);

Potential1D

Two-dimensional potential

  1. % Underlying field
  2. field = @(x) [ -x(1).^3 + x(1), -x(2).^3 + x(2)];
  3. % Grid characteristics
  4. x = -1.5:0.1:1.5;
  5. y = -1.5:0.1:1.5;
  6. [xm, ym] = meshgrid(x,y);
  7. % Setting the reference potential
  8. x0 = zeros(1, 2);
  9. V0 = 0;
  10. % Compute the potential
  11. V = Potential(field, V0, x0, xm, ym);
  12. % Plot results
  13. figure; surf(xm, ym, V);

Potential2D

By Pablo Rodríguez-Sánchez, March 2017.