1Math::Symbolic::VectorCUaslecrulCuosn(t3r)ibuted Perl DoMcautmhe:n:tSaytmiboonlic::VectorCalculus(3)
2
3
4
6 Math::Symbolic::VectorCalculus - Symbolically comp. grad, Jacobi matri‐
7 ces etc.
8
10 use Math::Symbolic qw/:all/;
11 use Math::Symbolic::VectorCalculus; # not loaded by Math::Symbolic
12
13 @gradient = grad 'x+y*z';
14 # or:
15 $function = parse_from_string('a*b^c');
16 @gradient = grad $function;
17 # or:
18 @signature = qw(x y z);
19 @gradient = grad 'a*x+b*y+c*z', @signature; # Gradient only for x, y, z
20 # or:
21 @gradient = grad $function, @signature;
22
23 # Similar syntax variations as with the gradient:
24 $divergence = div @functions;
25 $divergence = div @functions, @signature;
26
27 # Again, similar DWIM syntax variations as with grad:
28 @rotation = rot @functions;
29 @rotation = rot @functions, @signature;
30
31 # Signatures always inferred from the functions here:
32 @matrix = Jacobi @functions;
33 # $matrix is now array of array references. These hold
34 # Math::Symbolic trees. Or:
35 @matrix = Jacobi @functions, @signature;
36
37 # Similar to Jacobi:
38 @matrix = Hesse $function;
39 # or:
40 @matrix = Hesse $function, @signature;
41
42 $wronsky_determinant = WronskyDet @functions, @vars;
43 # or:
44 $wronsky_determinant = WronskyDet @functions; # functions of 1 variable
45
46 $differential = TotalDifferential $function;
47 $differential = TotalDifferential $function, @signature;
48 $differential = TotalDifferential $function, @signature, @point;
49
50 $dir_deriv = DirectionalDerivative $function, @vector;
51 $dir_deriv = DirectionalDerivative $function, @vector, @signature;
52
53 $taylor = TaylorPolyTwoDim $function, $var1, $var2, $degree;
54 $taylor = TaylorPolyTwoDim $function, $var1, $var2,
55 $degree, $var1_0, $var2_0;
56 # example:
57 $taylor = TaylorPolyTwoDim 'sin(x)*cos(y)', 'x', 'y', 2;
58
60 This module provides several subroutines related to vector calculus
61 such as computing gradients, divergence, rotation, and Jacobi/Hesse
62 Matrices of Math::Symbolic trees. Furthermore it provides means of
63 computing directional derivatives and the total differential of a
64 scalar function and the Wronsky Determinant of a set of n scalar func‐
65 tions.
66
67 Please note that the code herein may or may not be refactored into the
68 OO-interface of the Math::Symbolic module in the future.
69
70 EXPORT
71
72 None by default.
73
74 You may choose to have any of the following routines exported to the
75 calling namespace. ':all' tag exports all of the following:
76
77 grad
78 div
79 rot
80 Jacobi
81 Hesse
82 WronskyDet
83 TotalDifferential
84 DirectionalDerivative
85 TaylorPolyTwoDim
86
88 grad
89
90 This subroutine computes the gradient of a Math::Symbolic tree repre‐
91 senting a function.
92
93 The gradient of a function f(x1, x2, ..., xn) is defined as the vector:
94
95 ( df(x1, x2, ..., xn) / d(x1),
96 df(x1, x2, ..., xn) / d(x2),
97 ...,
98 df(x1, x2, ..., xn) / d(xn) )
99
100 (These are all partial derivatives.) Any good book on calculus will
101 have more details on this.
102
103 grad uses prototypes to allow for a variety of usages. In its most
104 basic form, it accepts only one argument which may either be a
105 Math::Symbolic tree or a string both of which will be interpreted as
106 the function to compute the gradient for. Optionally, you may specify a
107 second argument which must be a (literal) array of Math::Sym‐
108 bolic::Variable objects or valid Math::Symbolic variable names
109 (strings). These variables will the be used for the gradient instead of
110 the x1, ..., xn inferred from the function signature.
111
112 div
113
114 This subroutine computes the divergence of a set of Math::Symbolic
115 trees representing a vectorial function.
116
117 The divergence of a vectorial function F = (f1(x1, ..., xn), ...,
118 fn(x1, ..., xn)) is defined like follows:
119
120 sum_from_i=1_to_n( dfi(x1, ..., xn) / dxi )
121
122 That is, the sum of all partial derivatives of the i-th component func‐
123 tion to the i-th coordinate. See your favourite book on calculus for
124 details. Obviously, it is important to keep in mind that the number of
125 function components must be equal to the number of variables/coordi‐
126 nates.
127
128 Similar to grad, div uses prototypes to offer a comfortable interface.
129 First argument must be a (literal) array of strings and Math::Symbolic
130 trees which represent the vectorial function's components. If no second
131 argument is passed, the variables used for computing the divergence
132 will be inferred from the functions. That means the function signatures
133 will be joined to form a signature for the vectorial function.
134
135 If the optional second argument is specified, it has to be a (literal)
136 array of Math::Symbolic::Variable objects and valid variable names
137 (strings). These will then be interpreted as the list of variables for
138 computing the divergence.
139
140 rot
141
142 This subroutine computes the rotation of a set of three Math::Symbolic
143 trees representing a vectorial function.
144
145 The rotation of a vectorial function F = (f1(x1, x2, x3), f2(x1, x2,
146 x3), f3(x1, x2, x3)) is defined as the following vector:
147
148 ( ( df3/dx2 - df2/dx3 ),
149 ( df1/dx3 - df3/dx1 ),
150 ( df2/dx1 - df1/dx2 ) )
151
152 Or "nabla x F" for short. Again, I have to refer to the literature for
153 the details on what rotation is. Please note that there have to be
154 exactly three function components and three coordinates because the
155 cross product and hence rotation is only defined in three dimensions.
156
157 As with the previously introduced subroutines div and grad, rot offers
158 a prototyped interface. First argument must be a (literal) array of
159 strings and Math::Symbolic trees which represent the vectorial func‐
160 tion's components. If no second argument is passed, the variables used
161 for computing the rotation will be inferred from the functions. That
162 means the function signatures will be joined to form a signature for
163 the vectorial function.
164
165 If the optional second argument is specified, it has to be a (literal)
166 array of Math::Symbolic::Variable objects and valid variable names
167 (strings). These will then be interpreted as the list of variables for
168 computing the rotation. (And please excuse my copying the last two
169 paragraphs from above.)
170
171 Jacobi
172
173 Jacobi() returns the Jacobi matrix of a given vectorial function. It
174 expects any number of arguments (strings and/or Math::Symbolic trees)
175 which will be interpreted as the vectorial function's components.
176 Variables used for computing the matrix are, by default, inferred from
177 the combined signature of the components. By specifying a second lit‐
178 eral array of variable names as (second) argument, you may override
179 this behaviour.
180
181 The Jacobi matrix is the vector of gradient vectors of the vectorial
182 function's components.
183
184 Hesse
185
186 Hesse() returns the Hesse matrix of a given scalar function. First
187 argument must be a string (to be parsed as a Math::Symbolic tree) or a
188 Math::Symbolic tree. As with Jacobi(), Hesse() optionally accepts an
189 array of signature variables as second argument.
190
191 The Hesse matrix is the Jacobi matrix of the gradient of a scalar func‐
192 tion.
193
194 TotalDifferential
195
196 This function computes the total differential of a scalar function of
197 multiple variables in a certain point.
198
199 First argument must be the function to derive. The second argument is
200 an optional (literal) array of variable names (strings) and Math::Sym‐
201 bolic::Variable objects to be used for deriving. If the argument is not
202 specified, the functions signature will be used. The third argument is
203 also an optional array and denotes the set of variable (names) to use
204 for indicating the point for which to evaluate the differential. It
205 must have the same number of elements as the second argument. If not
206 specified the variable names used as coordinated (the second argument)
207 with an appended '_0' will be used as the point's components.
208
209 DirectionalDerivative
210
211 DirectionalDerivative computes the directional derivative of a scalar
212 function in the direction of a specified vector. With f being the func‐
213 tion and X, A being vectors, it looks like this: (this is a partial de‐
214 rivative)
215
216 df(X)/dA = grad(f(X)) * (A / ⎪A⎪)
217
218 First argument must be the function to derive (either a string or a
219 valid Math::Symbolic tree). Second argument must be vector into whose
220 direction to derive. It is to be specified as an array of variable
221 names and objects. Third argument is the optional signature to be used
222 for computing the gradient. Please see the documentation of the grad
223 function for details. It's dimension must match that of the directional
224 vector.
225
226 TaylorPolyTwoDim
227
228 This subroutine computes the Taylor Polynomial for functions of two
229 variables. Please refer to the documentation of the TaylorPolynomial
230 function in the Math::Symbolic::MiscCalculus package for an explanation
231 of single dimensional Taylor Polynomials. This is the counterpart in
232 two dimensions.
233
234 First argument must be the function to approximate with the Taylor
235 Polynomial either as a string or a Math::Symbolic tree. Second and
236 third argument must be the names of the two coordinates. (These may
237 alternatively be Math::Symbolic::Variable objects.) Fourth argument
238 must be the degree of the Taylor Polynomial. Fifth and Sixth arguments
239 are optional and specify the names of the variables to introduce as the
240 point of approximation. These default to the names of the coordinates
241 with '_0' appended.
242
243 WronskyDet
244
245 WronskyDet() computes the Wronsky Determinant of a set of n functions.
246
247 First argument is required and a (literal) array of n functions. Second
248 argument is optional and a (literal) array of n variables or variable
249 names. If the second argument is omitted, the variables used for
250 deriving are inferred from function signatures. This requires, however,
251 that the function signatures have exactly one element. (And the func‐
252 tion this exactly one variable.)
253
255 Please send feedback, bug reports, and support requests to the
256 Math::Symbolic support mailing list: math-symbolic-support at lists dot
257 sourceforge dot net. Please consider letting us know how you use
258 Math::Symbolic. Thank you.
259
260 If you're interested in helping with the development or extending the
261 module's functionality, please contact the developers' mailing list:
262 math-symbolic-develop at lists dot sourceforge dot net.
263
264 List of contributors:
265
266 Steffen Müller, symbolic-module at steffen-mueller dot net
267 Stray Toaster, mwk at users dot sourceforge dot net
268 Oliver Ebenhöh
269
271 New versions of this module can be found on http://steffen-mueller.net
272 or CPAN. The module development takes place on Sourceforge at
273 http://sourceforge.net/projects/math-symbolic/
274
275 Math::Symbolic
276
277
278
279perl v5.8.8 2008-02-22 Math::Symbolic::VectorCalculus(3)