Skip to content

Commit 03ef0d7

Browse files
author
Rik
committed
doc: Improve Tex output for vector calculus functions.
* curl.m, del2.m, divergence.m: Redo Tex format codes to improve output. * gradient.m: Rewrite documentation to clarify how numerical gradient is calculated.
1 parent 7718b04 commit 03ef0d7

File tree

4 files changed

+62
-29
lines changed

4 files changed

+62
-29
lines changed

scripts/general/curl.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
## Calculate curl of vector field given by the arrays @var{fx}, @var{fy}, and
3333
## @var{fz} or @var{fx}, @var{fy} respectively.
3434
## @tex
35-
## $$ curl F(x,y,z) = \left( {\partial{F_z} \over \partial{y}} - {\partial{F_y} \over \partial{z}}, {\partial{F_x} \over \partial{z}} - {\partial{F_z} \over \partial{x}}, {\partial{F_y} \over \partial{x}} - {\partial{F_x} \over \partial{y}} \right)$$
35+
## $$ {\rm curl \ {\bf F}}(x,y,z) \equiv \nabla \times {\rm \bf F} = \left( \frac{\partial{F_z}}{\partial{y}} - \frac{\partial{F_y}}{\partial{z}}, \frac{\partial{F_x}}{\partial{z}} - \frac{\partial{F_z}}{\partial{x}}, \frac{\partial{F_y}}{\partial{x}} - \frac{\partial{F_x}}{\partial{y}} \right)$$
3636
## @end tex
3737
## @ifnottex
3838
##

scripts/general/del2.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,9 @@
3636
## operator.
3737
## @end ifnottex
3838
##
39-
## For a 2-dimensional matrix @var{M} this is defined as
39+
## For a 2-dimensional matrix @math{M(x, y)} this is defined as
4040
## @tex
41-
## $$L = {1 \over 4} \left( {d^2 \over dx^2} M(x,y) + {d^2 \over dy^2} M(x,y) \right)$$
41+
## $$L = {1 \over 4} \left( \frac{\partial^2 M}{\partial{x}^2} + \frac{\partial^2 M}{\partial{y}^2} \right)$$
4242
## @end tex
4343
## @ifnottex
4444
##

scripts/general/divergence.m

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,9 @@
3232
## @var{fy}, and @var{fz} or @var{fx}, @var{fy} respectively.
3333
## @tex
3434
## $$
35-
## div F(x,y,z) = \partial_x{F} + \partial_y{F} + \partial_z{F}
35+
## {\rm div \ {\bf F}}(x,y,z) \equiv \nabla \cdot {\rm \bf F} = \frac{\partial F_x}{\partial x} + \frac{\partial F_y}{\partial y} + \frac{\partial F_z}{\partial z}
3636
## $$
37+
##
3738
## @end tex
3839
## @ifnottex
3940
##

scripts/general/gradient.m

Lines changed: 57 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -27,43 +27,75 @@
2727
## @deftypefn {} {@var{dx} =} gradient (@var{m})
2828
## @deftypefnx {} {[@var{dx}, @var{dy}, @var{dz}, @dots{}] =} gradient (@var{m})
2929
## @deftypefnx {} {[@dots{}] =} gradient (@var{m}, @var{s})
30-
## @deftypefnx {} {[@dots{}] =} gradient (@var{m}, @var{x}, @var{y}, @var{z}, @dots{})
30+
## @deftypefnx {} {[@dots{}] =} gradient (@var{m}, @var{sx}, @var{sy}, @var{sz}, @dots{})
3131
## @deftypefnx {} {[@dots{}] =} gradient (@var{f}, @var{x0})
3232
## @deftypefnx {} {[@dots{}] =} gradient (@var{f}, @var{x0}, @var{s})
33-
## @deftypefnx {} {[@dots{}] =} gradient (@var{f}, @var{x0}, @var{x}, @var{y}, @dots{})
33+
## @deftypefnx {} {[@dots{}] =} gradient (@var{f}, @var{x0}, @var{sx}, @var{sy}, @dots{})
3434
##
3535
## Calculate the gradient of sampled data or a function.
36+
## @tex
37+
## $$
38+
## {\rm grad} \ F(x,y,z) \equiv \nabla F = \frac{\partial F_x}{\partial x} \hat{i} + \frac{\partial F_y}{\partial y} \hat{j} + \frac{\partial F_z}{\partial z} \hat{k}
39+
## $$
40+
## @end tex
41+
## @ifnottex
3642
##
37-
## If @var{m} is a vector, calculate the one-dimensional gradient of @var{m}.
38-
## If @var{m} is a matrix the gradient is calculated for each dimension.
43+
## @group
44+
## @verbatim
45+
## d d d
46+
## grad F(x,y,z) = -- F(x,y,z) i + -- F(x,y,z) j + -- F(x,y,z) k
47+
## dx dy dz
48+
## @end verbatim
49+
## @end group
3950
##
40-
## @code{[@var{dx}, @var{dy}] = gradient (@var{m})} calculates the
41-
## one-dimensional gradient for @var{x} and @var{y} direction if @var{m} is a
42-
## matrix. Additional return arguments can be use for multi-dimensional
43-
## matrices.
51+
## @end ifnottex
4452
##
45-
## A constant spacing between two points can be provided by the @var{s}
46-
## parameter. If @var{s} is a scalar, it is assumed to be the spacing for all
47-
## dimensions. Otherwise, separate values of the spacing can be supplied by
48-
## the @var{x}, @dots{} arguments. Scalar values specify an equidistant
49-
## spacing. Vector values for the @var{x}, @dots{} arguments specify the
50-
## coordinate for that dimension. The length must match their respective
51-
## dimension of @var{m}.
53+
## If @var{m} is a vector, calculate the one-dimensional numerical gradient of
54+
## @var{m}. If @var{m} is a matrix the gradient is calculated for each
55+
## dimension. The return argument(s) are the estimated partial derivatives
56+
## for each dimension at the specified sample points.
5257
##
53-
## At boundary points a linear extrapolation is applied. Interior points
54-
## are calculated with the first approximation of the numerical gradient
58+
## The default spacing of between data points is 1. A constant spacing between
59+
## points can be specified with the @var{s} parameter. If @var{s} is a scalar,
60+
## the single spacing value is used for all dimensions. Otherwise, separate
61+
## values of the spacing can be supplied by the @var{sx}, @dots{} arguments.
62+
## Scalar values specify an equidistant spacing. Vector values for the
63+
## @var{sx}, @dots{} arguments specify the coordinate for that dimension. The
64+
## length must match the respective dimension of @var{m}.
65+
##
66+
## If the first argument @var{f} is a function handle, the gradient of the
67+
## function is calculated for the points in @var{x0}. As with sampled data,
68+
## the spacing values between the points from which the gradient is estimated
69+
## can be set via the @var{s} or @var{dx}, @var{dy}, @dots{} arguments. By
70+
## default a spacing of 1 is used, however this is normally overly large unless
71+
## the function is very slowly varying, and it is often necessary to specify a
72+
## smaller sample spacing.
73+
##
74+
## Example: numerical gradient of @code{cos} (analytically = @code{-sin})
5575
##
5676
## @example
57-
## y'(i) = 1/(x(i+1)-x(i-1)) * (y(i-1)-y(i+1)).
77+
## @group
78+
## gradient (@@cos, pi/2, .1)
79+
## @result{} -0.9983
80+
## -sin (pi/2)
81+
## @result{} -1
82+
## @end group
83+
## @end example
84+
##
85+
## Programming Notes:
86+
## The value for interior data points is approximated using the central
87+
## difference.
88+
##
89+
## @example
90+
## y'(i) = 1/2 * (y(i+1) - y(i-1)).
91+
## @end example
92+
##
93+
## At boundary points a linear extrapolation is applied.
94+
##
95+
## @example
96+
## y'(1) = y(2) - y(1).
5897
## @end example
5998
##
60-
## If the first argument @var{f} is a function handle, the gradient of the
61-
## function at the points in @var{x0} is approximated using central difference.
62-
## For example, @code{gradient (@@cos, 0)} approximates the gradient of the
63-
## cosine function in the point @math{x0 = 0}. As with sampled data, the
64-
## spacing values between the points from which the gradient is estimated can
65-
## be set via the @var{s} or @var{dx}, @var{dy}, @dots{} arguments. By default
66-
## a spacing of 1 is used.
6799
## @seealso{diff, del2}
68100
## @end deftypefn
69101

0 commit comments

Comments
 (0)