Previous Page Next Page Contents

linalg::grad -- vector gradient

Introduction

linalg::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])],.

Call(s)

linalg::grad(f, x)
linalg::grad(f, x, ogCoord)

Parameters

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

Returns

a column vector of the domain Dom::Matrix().

Related Functions

linalg::curl, linalg::divergence, linalg::ogCoordTab, linalg::vectorPotential

Details

Example 1

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   |
                                 +-     -+

Example 2

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)  |
                             +-             -+

Example 3

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).

Changes




Do you have questions or comments?


Copyright © SciFace Software GmbH & Co. KG 2000