linalg::grad
-- vector
gradientlinalg::grad
(f, x)
computes the vector
gradient of the scalar function f(x) with respect to
x in Cartesian coordinates. This is the vector grad(f)
= [diff(f,x[1]),...,diff(f,x[n])],.
linalg::grad(f, x)
linalg::grad(f, x, ogCoord)
f |
- | an arithmetical expression in the variables given in
x |
x |
- | a list of (indexed) identifiers |
ogCoord |
- | a list, or a name (identifier) of a predefined coordinate system |
a column vector of the domain Dom::Matrix()
.
linalg::curl
, linalg::divergence
, linalg::ogCoordTab
, linalg::vectorPotential
linalg::grad
(f,
x, ogCoord)
computes the gradient of f
with respect
to x
in the orthogonally curvilinear coordinate system
specified by ogCoord
. The scaling factors of the specified
coordinate system must be the value of the index ogCoord
of the table linalg::ogCoordTab
(see example
2).ogCoord
is an identifier then the scaling factors
must be defined under the name of the identifier as an entry of the
table linalg::ogCoordTab
.We compute the vector gradient of the scalar function f(x,y) = x^2 + y in Cartesian coordinates:
>> delete x, y: linalg::grad(x^2 + y, [x, y])
+- -+ | 2 x | | | | 1 | +- -+
We compute the gradient of the function f(r,phi,z) = r*cos(phi)*z (0<=phi<=2*PI) in cylindrical coordinates:
>> delete r, z, phi: linalg::grad(r*cos(phi)*z, [r, phi, z], Cylindrical)
+- -+ | z cos(phi) | | | | -z sin(phi) | | | | r cos(phi) | +- -+
We want to compute the gradient of the function f(r,theta,phi) = r*cos(theta)*sin(phi) (0<=theta<=PI, 0<=phi<=2*PI) in spherical coordinates.
The vectors
e_r = [sin(theta)*cos(phi), sin(theta)*sin(phi), cos(theta)], e_theta = [cos(theta)*cos(phi), cos(theta)*sin(phi),-sin(theta)], e_phi = [-sin(phi), cos(phi), 0],
form an orthogonal system in spherical coordinates.
The scaling factors of the corresponding coordinate transformation
(see linalg::ogCoordTab
) are:
g1=|e_r|=1, g2=|e_theta|=r, g3=|e_phi|=r*sin(theta), which
we use in the following example to compute the gradient of the function
f in spherical coordinates:
>> delete r, theta, phi: linalg::grad( r*cos(theta)*sin(phi), [r, theta, phi], [1, r, r*sin(theta)] )
+- -+ | sin(phi) cos(theta) | | | | -sin(phi) sin(theta) | | | | cos(phi) cos(theta) | | ------------------- | | sin(theta) | +- -+
Note that the spherical coordinates are already defined
in linalg::ogCoordTab
, i.e., the
last result can also be achieved with the input
linalg::grad(r*cos(theta)*sin(phi), [r, theta, phi],
Spherical)
.
x
must be given as a list, vectors are
not longer allowed.Dom::Matrix()
.