Previous Page Next Page Contents

linalg::divergence -- divergence of a vector field

Introduction

linalg::divergence(v, x ...) computes the divergence of the vector field v with respect to x in Cartesian coordinates. This is the sum div(v) = sum(diff(v,x[i]),i=1..n.

Call(s)

linalg::divergence(v, x)
linalg::divergence(v, x, ogCoord)

Parameters

v - a list of arithmetical expressions, or a vector (i.e., an n x 1 or 1 x n matrix of a domain of category Cat::Matrix)
x - a list of (indexed) identifiers
ogCoord - a list, or a name (identifier) of a predefined coordinate system

Returns

an arithmetical expression, or an element of the component ring of v.

Related Functions

linalg::curl, linalg::grad, linalg::ogCoordTab

Details

Example 1

We compute the divergence of the vector field v((x,y,z)=(x^2, 2y, z) in Cartesian coordinates:

>> delete x, y, z:
   v := matrix([x^2, 2*y, z])
                                 +-     -+
                                 |    2  |
                                 |   x   |
                                 |       |
                                 |  2 y  |
                                 |       |
                                 |   z   |
                                 +-     -+
>> linalg::divergence(v, [x, y, z])
                                  2 x + 3

Example 2

We compute the divergence of the vector field v(r,phi,z)=(r,cos(phi),z) (0<=phi<=2*PI) in cylindrical coordinates:

>> delete r, phi, z:
   linalg::divergence([r, sin(phi), z], [r, phi, z], Cylindrical)
                              3 r + cos(phi)
                              --------------
                                    r

The following relations between Cartesian and cylindrical coordinates hold:

x=r*cos(phi), y=r*sin(phi), z=z.

Other predefined orthogonal coordinate systems can be found in the table linalg::ogCoordTab.

Example 3

We want to compute the divergence of the vector field v(r,theta,phi)=(r^2,0,0) (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 divergence of the above vector field in spherical coordinates:

>> delete r, theta, phi:
   linalg::divergence(
     [r^2, 0, 0], [r, theta, phi], [1, r, r*sin(theta)]
   )
                                    4 r

Note that the spherical coordinates are already defined in linalg::ogCoordTab, i.e., the last result can also be achieved with the input linalg::divergence([r^2, 0, 0], [r, theta, phi], Spherical).

Changes




Do you have questions or comments?


Copyright © SciFace Software GmbH & Co. KG 2000