Update of /cvsroot/maxima/maxima/share/physics
In directory usw-pr-cvs1:/tmp/cvs-serv9177
Added Files:
dimension.html dimension.mac dimension.pdf dimension.tex
Log Message:
Barton Willis's Dimensional analysis package and documentation
--- NEW FILE: dimension.html ---
<HTML>
<HEAD>
<!-- This HTML file has been created by texi2html 1.52
from dimension.texi on 7 April 2002 -->
<TITLE>Untitled Document</TITLE>
</HEAD>
<BODY>
<H1>Untitled Document</H1>
<P>
<P><HR><P>
<H2><A NAME="SEC1" HREF="dimension_toc.html#TOC1">Introduction to the Dimensional Analysis Package</A></H2>
<P>
This document describes a new dimensional analysis package for Maxima.
There is an older Maxima package for dimensional analysis that
is similar to the one that was shipped with the commercial Macsyma system.
The software described in this document differs greatly from the
older package.
</P>
<P>
The new dimensional analysis code was written by Barton Willis of the
University of Nebraska at Kearney. The complete distribution contains
source code, texinfo documentation, a file for testing (in standard
Maxima "rtest" form), and a TeX file that provides additional documentation
and examples of how to use the package. You may download
the distribution from http://www.unk.edu/acad/math/people/willisb
and you may contact the author at willisb@....
</P>
<P>
To use the dimensional analysis package, you must first load the file
<B>dimension.mac</B>. Provided this file has been installed in a directory
that Maxima can find, load it with the command
<PRE>
(C1) load("dimension.mac")$
</PRE>
<P>
Alternatively, you can compile <B>dimension.mac</B> with the command
<PRE>
(C1) compile_file("dimension.mac")$
</PRE>
<P>
After it has been compiled, load it with
<PRE>
(C2) load("dimension.o")$
</PRE>
<P>
The compiled code runs about thirty percent faster than the interpreted
code.
</P>
<P>
Use <B>qput</B> to define the dimension of a variable; thus
to define <EM>x</EM> to be a length, <EM>t</EM> a time, and <EM>c</EM> a speed, use
<PRE>
(C1) qput(x,"length",dimension)$
(C2) qput(t,"time",dimension)$
(C3) qput(c,"length"/"time",dimension)$
</PRE>
<P>
To find the dimension of an expression, use the <B>dimension</B> function.
For example,
<PRE>
(C4) dimension(c*t/5);
(D4) length
(C5) dimension(c-x/t);
length
(D5) ------
time
</PRE>
<P>
When an expression is dimensionally inconsistent, <B>dimension</B>
should signal an error
<PRE>
(C6) dimension(c-x);
Expression is dimensionally inconsistent.
</PRE>
<P>
Any symbol may be used to represent a dimension; if you like,
you can use "L" instead of "length" for the length dimension. It
isn't necessary to use strings for the dimensions; however, doing
so reduces the chance of conflicting with other variables.
Thus to use the dimensions "M","L", and "T", for mass, length, and time,
respectively, use the commands
<PRE>
(C1) qput(x,"L",dimension)$
(C2) qput(t,"T",dimension)$
(C3) qput(c,"L"/"T",dimension)$
(C4) qput(m,"M",dimension)$
</PRE>
<P>
Then
<PRE>
(C4) dimension(m * 'diff(x,t));
L M
(D4) ---
T
</PRE>
<P>
An <EM>equation</EM> is dimensionally consistent if either one side of
the equality vanishes or if both sides have the same
dimensions. Thus
<PRE>
(C5) dimension(x=c*t);
(D5) L
(C6) dimension(x=0);
(D6) L
(C7) dimension(x=c);
Expression is dimensionally inconsistent.
</PRE>
<P>
The dimension function supports most Maxima operators and it
automatically maps over lists. For example,
<PRE>
(C1) dimension([x^3,x.t,x/t,x^^2]);
3 L 2
(D1) [L , L T, -, L ]
T
</PRE>
<P>
The dimension of a subscripted symbol is the dimension of the
non-subscripted variable. For example,
<PRE>
(C1) dimension(x[3]);
(D1) L
</PRE>
<P>
When the dimensions of a symbol are undefined, dimension returns
an unevaluated expression
<PRE>
(C2) dimension(z);
(D2) dimension(z)
</PRE>
<P>
The remaining functions in the package, <B>dimensionless</B>,
<B>dimension_as_list</B>, and <B>natural_unit</B> require that
all expressions have dimensions that are members of the
list <B>fundamental_dimensions</B>. The default value of this
list is
<PRE>
(C1) fundamental_dimensions;
(D1) [mass, length, time]
</PRE>
<P>
A user may redefine this list; to use "M", "L", and "T" for
the fundamental dimensions, make the assignment
<PRE>
(C2) fundamental_dimensions : ["M", "L", "T"]$
</PRE>
<P>
The list <B>fundamental_dimensions</B> must be nonempty, but it
can have any finite cardinality.
</P>
<P>
To find the dimensions of an expression as a list of the exponents
of the fundamental dimensions, use the <B>dimension_as_list</B> function
<PRE>
(C3) dimension_as_list('diff(x,t,3));
(D3) [0, 1, - 3]
</PRE>
<P>
Thus the dimension of the third derivative of x
with respect to t is L / T^3.
</P>
<P>
To find the dimensionless expressions that can be formed as a
product of elements of a list of atoms, use the
<B>dimensionless</B> function. For example,
<PRE>
(C1) dimensionless([c,t,x]);
Dependent equations eliminated: (1)
x
(D1) [---, 1]
c t
</PRE>
<P>
Finally, to find quantities that have a given dimension, use
the <B>natural_unit</B> function. To find an expression with
dimension time, use the command
<PRE>
(C1) natural_unit("T",[x,c]);
Dependent equations eliminated: (1)
x
(D1) [-]
c
</PRE>
<H2><A NAME="SEC2" HREF="dimension_toc.html#TOC2">Definitions for Dimensional Analysis</A></H2>
<a name="FUNDAMENTAL_DIMENSIONS"></a><P>
<DL>
<DT><U>Variable:</U> <B>FUNDAMENTAL_DIMENSIONS</B>
<DD><A NAME="IDX1"></A>
FUNDAMENTAL_DIMENSIONS is a list of the fundamental dimensions. The
default value is ["mass", "length", "time"]; however, a user may
redefine it to be any nonempty list of atoms. The function
<B>dimension</B> doesn't use this list, but the other functions
in the dimensional analysis package do use it.
</P>
</DL>
<a name="DIMENSION"></a><P>
<DL>
<DT><U>Function:</U> <B>DIMENSION</B> <I>(e)</I>
<DD><A NAME="IDX2"></A>
Return the dimension of the expression e. If
e is dimensionally inconsistent, signal an error.
The dimensions of the symbols in the expression e
should be first defined using <B>qput</B>.
</P>
</DL>
<a name="DIMENSION_AS_LIST"></a><P>
<DL>
<DT><U>Function:</U> <B>DIMENSION_AS_LIST</B> <I>(e)</I>
<DD><A NAME="IDX3"></A>
Return the dimension of the expression e as a list of
the exponents of the dimensions in the list
<B>fundamental_dimensions</B>. If e is dimensionally
inconsistent, signal an error.
</P>
</DL>
<a name="DIMENSIONLESS"></a><P>
<DL>
<DT><U>Function:</U> <B>DIMENSIONLESS</B> <I>([e1,e2,...,en])</I>
<DD><A NAME="IDX4"></A>
</P>
<P>
Return a basis for the dimensionless quantities that can be formed as
a product of powers of the expressions e1, e2, ..., en.
</P>
</DL>
<a name="NATURAL_UNIT"></a><P>
<DL>
<DT><U>Function:</U> <B>NATURAL_UNIT</B> <I>(q, [e1,e2,...,en])</I>
<DD><A NAME="IDX5"></A>
</P>
<P>
Return a basis for the quantities that can be formed as a product of
powers of the expressions e1, e2, ..., en that have the
same dimension as does q.
</P>
</DL>
<P>
</P>
<P>
<P><HR><P>
This document was generated on 7 April 2002 using the
<A HREF="http://wwwcn.cern.ch/dci/texi2html/">texi2html</A>
translator version 1.51a.</P>
</BODY>
</HTML>
--- NEW FILE: dimension.mac ---
eval_when(batch,ttyoff : true)$
/*
Copyright (C) 2002 Barton Willis
Brief Description:
Maxima code for dimensional analysis.
Author:
Barton Willis, willisb@...
Department of Mathematics
University of Nebraska at Kearney
Kearney NE 68849
License:
GPL
*/
put('dimension,1,'version)$
/*
If e is a list, return true iff e[i] = e[j] for all
1 <= i,j <= length(e) or if e is empty. If e isn't a
list, return false.
*/
all_equalp (e) := block([n, e1, b],
modedeclare(n, fixnum),
if b : listp(e) then (
if (n : length(e)) > 1 then (
e1 : part(e,n),
while (b and n > 1) do (
n : n - 1,
b : b and is(part(e,n) = e1)))),
b);
/*
fundamental_dimensions is a Maxima list that is used by the functions
dimensionless, natural_unit, and dimension_as_list; the function
dimension doesn't use this list. A user may insert an remove
elements form the list; for example, to use quantities that
involve temperature, you could cons "temp" onto fundamental_dimensions.
You'll get into trouble if you call any one of the functions
dimensionless, natural_unit, or dimension_as_list with expressions
that have dimensions not in the list fundamental_dimensions.
Be careful.
The default value of fundamental_dimensions is ["mass","length","time"];
I used strings here to try and minimize the changes of interfering
with one of your variables. If you don't like this, it is
fine to change fundamental_dimensions to something like
fundamental_dimensions : [m,l,t];
or
fundamental_dimensions : ["M","L","T"];
*/
assume("mass" > 0);
assume("length" > 0);
assume("time" > 0);
fundamental_dimensions : ["mass","length","time"];
/* Notes
0. When e is a list, map dimension over the list.
1. Use logcontract so that log(a) - log(b) is okay when a and b have the
same dimensions.
1.5. Under commerical macsyma a string is not a symbol; thus
symbolp("mass") is false. So under commerical macsyma,
dimension("mass") misbehaves.
2. Maybe this should return "Unknown dimensions."
2.5 dimension(a[x]) = dimension(a) regardless of what x is.
3. In a sum, check that all terms have the same dimensions; if not,
signal the error "Expression is dimensionally inconsistent."
4. ABS, SQRT, MAX, and MIN are the only prefix functions that may
take an argument that isn't dimensionless.
5. Check that all function arguments are dimensionless; if not,
signal the error "Expression is dimensionally inconsistent."
Return the dimensions of the expression e; if e is dimensionally
inconsistent, signal an error "Expression is dimensionally inconsistent."
The infix binary operators +, *, /, ^, ^^, ., = and ~ are supported.
(Maxima's vector package defines ~ to be the cross product
operator.) For the = operator, the expression is dimensionally
inconsistent if the dimension of the right and left sides differ.
It supports the prefix unary negation and the abs function. The nary
min and max functions are supported; for the min and max functions,
all arguments must have the same dimension, otherwise, the
expression is dimensionally inconsistent.
*/
dimension (e) := block([op, dim, var, i, n],
modedeclare([i, n], fixnum),
if listp(e) then ( /* 0 */
map ('dimension, e))
else (
if not atom(e) then (
op : part(e,0)),
e : logcontract (e), /* 1 */
if constantp (e) then (
1)
else if symbolp (e) then ( /* 1.5 */
if member(e, fundamental_dimensions) then (
e)
else (
dim : get (e, 'dimension),
if dim = false then (
funmake ('dimension, [e])) /* 2 */
else (
dim)))
else if subvarp (e) then ( /* 2.5 */
dimension(part(e,0)))
else if op = "*" or op = "." or op = "~" then (
apply ("*", map ('dimension, args (e))))
else if op = "//" or op = "/" then (
dimension(num(e)) / dimension(denom(e)))
/* apply (op, map ('dimension, args (e)))) */
else if (op = "^" or op = "^^") and dimension (part (e,2)) = 1 then (
dimension(part(e,1)) ^ part(e,2))
else if op = "-" then (
dimension(part(e,1)))
else if op = "+" or ?equal(op, 'MAX) or ?equal(op, 'MIN) then ( /*3*/
dim : map ('dimension, args (e)),
if all_equalp (dim) then (
first (dim))
else (
error ("Expression is dimensionally inconsistent.")))
else if ?equal(op, 'MATRIX) then (
dim : map ('dimension, args (e)),
dim : apply ('append, dim),
if all_equalp (dim) then (
first(dim))
else (
error ("Expression is dimensionally inconsistent.")))
else if (op = "=" or op = "#" or op = "<" or op = ">" or
op = "<=" or op = ">=" ) then (
if part(e,1) = 0 then (
dimension (part(e,2)))
else if part (e,2) = 0 then (
dimension (part(e,1)))
else (
dim : dimension(part(e,1)),
if dim = dimension(part(e,2)) then (
dim )
else (
error ("Expression is dimensionally inconsistent."))))
else if ?equal(op, 'ABS) then ( /* 4 */
dimension (part (e, 1)))
else if ?equal(op, 'SQRT) then (
dimension (part(e,1)) ^ (1/2))
else if op = nounify('diff) then (
var : args(e),
n : length(var) - 1,
dim : dimension (part(var,1)),
for i : 2 thru n step 2 do (
dim : dim / dimension (part(var,i)) ^ part(var,i+1)),
dim)
else if op = nounify('INTEGRATE) then (
var : args(e),
dim : dimension(part(var,1)) * dimension(part(var,2)),
if length (e) = 4 and not all_equalp([dimension(part(var,2)),
dimension(part(var,3)),dimension(part(var,4))]) then (
error ("Expression is dimensionally inconsistent."))
else (
dim))
else if op = nounify('SUM) or op = nounify('PRODUCT) then (
error("The function dimension doesn't handle sums or products."))
else if op = "DIV" or op = "div" or op = "GRAD" or op = "grad" or
op = "CURL" or op = "curl" then (
if listp(part(e,1)) then (
dim : map ('dimension, part(e,1)),
if all_equalp(dim) then (
dim : first(dim))
else (
error ("Expression is dimensionally inconsistent.")))
else (
dim : dimension (part(e,1))),
dim / "length")
else if op = "LAPLACIAN" then (
dimension(part(e,1) / "length"^2))
else ( /* 5 */
dim : map ('dimension, args(e)),
if all_equalp (cons (1,dim)) then (
dim : dimension(part(e,0)),
if not atom(dim) and ?equal(part(dim,0),'dimension) then (
1)
else (
dim ))
else (
error ("Expression is dimensionally inconsistent.")))));
/*
For the expression e, return a list of the exponents of the
fundamental_dimensions. Thus if fundamental_dimensions =
[mass, length, time] and c is a velocity, dimension_as_list(c)
returns [0,1,-1].
*/
dimension_as_list (e) := block([s : [ ], i, n],
modedeclare([i,n], fixnum, s, list),
if listp(e) then (
map ('dimension_as_list, e))
else (
e : dimension (e),
n : length(fundamental_dimensions),
for i : 1 thru n do (
s : endcons(hipow(e, part(fundamental_dimensions,i)), s)),
s));
/*
Maxima translates makelist into ugly Lisp and compiled code sometimes
doesn't work; here is my version of makelist that translates into reasonable
looking Lisp that also works when compiled.
*/
my_makelist(e,i,low,high) := block([s : [ ]],
modedeclare([j, low, high], fixnum, s, list),
for j from low thru high do (
s : endcons(subst(j,i,e), s)),
s);
/*
Return a basis for the dimensionless quantities that can be formed
from a product of powers of elements of the list e. The basis excludes
the constants.
*/
dimensionless (e) := block([s, vars, linsolve_params : true,
back_subst : true,globalsolve : false, solve_inconsistent_error : false,
p, n, basis, sub, i, k, si],
modedeclare([i, k, n], fixnum, s, list),
if not listp(e) then (
merror ("Argument to DIMENSIONLESS must be a list.")),
s : map ('dimension_as_list, e),
vars : my_makelist (p[k], k, 1,length (s)),
s : linsolve (s . vars, vars),
n : length(%rnum_list),
basis : [1],
if (n > 0 and s # [ ]) then (
s : map ('rhs, s),
s : apply ("*", map("^",e,s)),
sub : map("=", %rnum_list, my_makelist(0,i,1,n)),
for i : 1 thru n do (
si : subst(1,%rnum_list[i], s),
si : sublis(sub,si),
basis : cons(si, basis))),
basis);
natural_unit(dim,e) := block([s,vars,k,i,n,p,basis,si,sub,linsolve_params : true,
back_subst : true, globalsolve : false,
solve_inconsistent_error : false],
modedeclare([k,i,n], fixnum),
if not listp(e) then (
merror ("Second argument to NATURAL_UNIT must be a list.")),
dim : dimension_as_list(dim),
s : map ('dimension_as_list,e),
vars : my_makelist(p[k],k,1,length(s)),
s : linsolve(s . vars - dim, vars),
n : length(%rnum_list),
basis : [ ],
if (s # [ ] and n = 0) then (
s : map('rhs,s),
basis : [apply("*", map ("^", e, s))])
else if (s # [ ] and n > 0) then (
s : map('rhs, s),
sub : map("=", %rnum_list, my_makelist(0,i,1,n)),
for i : 1 thru n do (
si : subst(1,%rnum_list[i],s),
si : sublis(sub, si),
si : apply("*",map ("^",e,si)),
basis : cons(si, basis))),
basis);
eval_when(batch,ttyoff : false)$
--- NEW FILE: dimension.pdf ---
%PDF-1.2
3 0 obj <<
/Length 4 0 R
/Filter /FlateDecode
>>
stream
xÚ¥WYÛ6ò_!äI*®xéh^
¢¬ä§YTu/yDÑL}©Ë¢`ZáêÅDf
B³,/Öú
I2õvûòæÎ"²,ÑvçU¶õ¯ñM"t÷v#t| ÅgógÓ¢Mõ`î,-vÃHDÝt¶¡7íæ÷í9x++!
x²>áqj&T
Ü.Þ<Ï&gÚÖ<3Ë(ÛM>á˹÷>| Æóp¨æy|ôy
Ð~ùýöü¢øF«(ï""~zÞué¡ÿê´âð_ÌK&Tþü4<¼qÀ2³eY¬XÆL¢õWÝô
]yý7_$Ì"ÉÏFÒÙïß¾xá^Ð
endobj
4 0 obj
1284
endobj
2 0 obj <<
/Type /Page
/Contents 3 0 R
/Resources 1 0 R
[...1047 lines suppressed...]
0000040512 00000 n
0000041044 00000 n
0000054500 00000 n
0000054523 00000 n
0000054545 00000 n
0000054568 00000 n
0000054589 00000 n
0000054621 00000 n
0000055586 00000 n
0000055661 00000 n
0000055714 00000 n
trailer
<<
/Size 109
/Root 107 0 R
/Info 108 0 R
>>
startxref
55810
%%EOF
--- NEW FILE: dimension.tex ---
% TeX code generated by batTeX. Don't edit this file; edit the
% input file dimdem2.tex instead.
\documentclass[12pt]{article}
\usepackage{mathptm}
%\usepackage{euler}
\usepackage{battex}
\usepackage{color}
%\usepackage{fleqn}
\title{A new Maxima package for dimensional analysis}
\author{Barton Willis \\
University of Nebraska at Kearney \\
Kearney Nebraska}
\begin{document}
\maketitle
[...988 lines suppressed...]
\end{document}
(D84) DONE
(C84)
|