From: Harald Geyer <hgeyer@us...>  20070730 13:03:58

Update of /cvsroot/maxima/maxima/share/contrib/vector3d In directory sc8prcvs16.sourceforge.net:/tmp/cvsserv12212/share/contrib/vector3d Added Files: vector3d.dem vector3d.mac vector3d.usg Log Message: Added the vector3d package of Walter Eastes (eastes@...) as share/contrib/vector3d. This closes patch tracker item #974304. This commit is based on a newer version (than in the patch tracker) with clarified copyright status. I made some minor changes to vector3d.usg to make the tone more appropriate with regard to the current status of the other vector packages in maxima.  NEW FILE: vector3d.dem  /* File name: vector3d.dem * Demonstration and test of the vector3d package * Walter Eastes: June, 2004 */ load("vector3d.mac"); "Let's define some vectors to use"$ a : [ax,ay,az]; b : [bx,by,bz]; c : [cx,cy,cz]; "These are vector and scalar functions of the coordinates"$ u : [ux,uy,uz]; v : [vx,vy,vz]; depends([ux,uy,uz,vx,vy,vz], [x,y,z]); depends([f], [x,y,z]); "Now let's prove some elementary identities"$ is(cross(a,b) = cross(b,a)); is(cross(a,h*b) = cross(h*a,b)); is(cross(a,a) = [0,0,0]); is( expand(cross(a, cross(b,c))) = expand((a . c)*b  (a . b)*c) ); "Now some identities for the differential operators"$ is( expand(div(cross(u,v))) = expand(curl(u) . v  u . curl(v)) ); is( curl(curl(u)) = grad(div(u))  laplacian(u) ); is( div(grad(f)) = laplacian(f) ); "Now let's change to spherical polar coordinates"$ coordsys(spherical); "Define vector functions of these coordinates"$ u : [ur,uth,uph]; v : [vr,vth,vph]; depends([ur,uth,uph,vr,vth,vph], [r,th,ph]); depends([f], [r,th,ph]); "Now see if the differential operator identities still hold"$ is( expand(div(cross(u,v))) = expand(curl(u) . v  u . curl(v)) ); is( expand(curl(curl(u))) = expand(grad(div(u))  laplacian(u)) ); is(equal( div(grad(f)), laplacian(f) )); "Finally prove the identity in the original demo"$ "Need these vectors first"$ a : [ar,ath,aph]; b : [br,bth,bph]; is( expand( cross(a,b) . cross(u,v) + cross(b,u) . cross(a,v) + cross(u,a) . cross(b,v) ) = 0);  NEW FILE: vector3d.mac  /* File name: vector3d.mac * Package providing vector algebra and differential calculus operations * on three dimensional vectors in orthogonal coordinate systems. * Implements cross product of two vectors, div, curl, and laplacian * of vector functions of the coordinates. and grad and laplacian * of scalar functions of the coordinates. The vector arguments must * be three element lists. * Walter Eastes: June, 2004 * Copyright updated: July, 2007 */ /* Copyright (C) 20042007 by Walter Eastes These routines are free software; you can redistribute them and/or modify them under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. */ coordsys(sys):= ( if sys=cartesian then (scalef : [1,1,1], coordvar : [x,y,z]) else if sys=cylindrical then (scalef : [1,r,1], coordvar : [r,ph,z]) else if sys=spherical then (scalef : [1,r*sin(ph),r], coordvar : [r,th,ph]) else (scalef : read("Scale factors"), coordvar : read("Coordinates")) )$ coordsys(cartesian)$ cross(a,b) := [ a[2]*b[3]a[3]*b[2], a[3]*b[1]a[1]*b[3], a[1]*b[2]a[2]*b[1] ] $ div(v) := ( diff(scalef[2]*scalef[3]*v[1], coordvar[1]) + diff(scalef[3]*scalef[1]*v[2], coordvar[2]) + diff(scalef[1]*scalef[2]*v[3], coordvar[3]) ) / (scalef[1]*scalef[2]*scalef[3]) $ curl(a) := [ (diff(scalef[3]*a[3], coordvar[2])  diff(scalef[2]*a[2], coordvar[3])) / (scalef[2]*scalef[3]), (diff(scalef[1]*a[1], coordvar[3])  diff(scalef[3]*a[3], coordvar[1])) / (scalef[3]*scalef[1]), (diff(scalef[2]*a[2], coordvar[1])  diff(scalef[1]*a[1], coordvar[2])) / (scalef[1]*scalef[2]) ]$ grad(f) := [ diff(f,coordvar[1]) / scalef[1], diff(f,coordvar[2]) / scalef[2], diff(f,coordvar[3]) / scalef[3] ]$ laplacian(v) := if listp(v) then grad(div(v))  curl(curl(v)) else ( diff(diff(v,coordvar[1]) * scalef[2]*scalef[3]/scalef[1], coordvar[1]) + diff(diff(v,coordvar[2]) * scalef[3]*scalef[1]/scalef[2], coordvar[2]) + diff(diff(v,coordvar[3]) * scalef[1]*scalef[2]/scalef[3], coordvar[3]) ) / (scalef[1]*scalef[2]*scalef[3]) $  NEW FILE: vector3d.usg  VECTOR3D The vector3d package adds functions for doing vector algebra and calculus in orthogonal coordinate systems in three dimensions. It provides the vector or cross product and the differential operators grad, div, curl, and laplacian. This package provides an alternative to vect and vector. Unlike those packages, vector3d does not require vectors to be declared nonscalar, does not require the coordinate transformation to be given explicitly, does not need express() to display the components, and does not need an array of simplification options. Usually, expand() is enough to collapse complex chains of vector operators into recognizable form. On the other hand, vector3d does not do as much as the other packages. The operators that work on vectors do not work with abstract vectors; they must be defined as three element lists even if the list elements are unbound. It does assume but not check that the coordinate system is orthogonal but works just from the scale factors. Therefore, conversion from one coordinate system to another is not available. Potentials and Christoffel symbols are not implemented either. Definitions for vector3d coordsys(sys) sets the orthogonal coordinate system to be used, default cartesian. If sys is not one of cartesian, cylindrical, or spherical, then the user is asked for the names of the three coordinate variables and for the three scale factors. The coordinate variables for the already defined systems are [x,y,z] for cartesian, [r,ph,z] for cylindrical, and [r,th,ph] for spherical. Note that ph is the polar angle in this spherical polar system. There is nothing stopping you from setting the scale factors scalef:[ , , ] and coordinate variables coordvar:[ , , ] yourself and not using this function. cross(a,b) returns the vector or cross product of the two vectors a and b. curl(u) returns the vector curl (del cross u) of the vector u, each component of which is a function of the coordinates. If it is not given explicitly, do something like u : [ux,uy,uz]; depends([ux,uy,uz],[x,y,z]); to establish it. div(u) returns the scalar divergence (del dot u) of the vector u. grad(f) returns the vector gradient (del f) of the scalar f, which is a function of the coordinates. Use depends([f],[x,y,z]), for example, to establish the functional dependence if it is not given explicitly already. laplacian(u) If u is a scalar function of the coordinates, then the scalar laplacian (div(grad(u)) is returned. If u is a vector function, then the vector laplacian (del squared u) is returned. a . b, a + b, a * s The dot product of vectors a and b returns a scalar, and is available outside this package. The vector sum of two vectors and the product of a vector and a scalar are likewise available and compatible with the other operators. Walter Eastes (eastes@...) June, 2004 