1 % TeX code generated by batTeX. Don't edit this file; edit the
2 % input file pdiff.tex instead.
3 \documentclass[12pt
]{article
}
8 \title{A positional derivative package for Maxima
}
9 \author{Barton Willis \\
10 University of Nebraska at Kearney \\
12 \date{September
10,
2002\footnote{With minor updates November,
2006.
}}
18 \subsection*
{Introduction
}
20 \noindent Working with derivatives of unknown functions
\footnote{By
21 {\em unknown function\/
}, we mean a function that isn't bound to a formula and
22 that has a derivative that isn't known to Maxima.
} can be cumbersome in Maxima.
23 If we want, for example, the first order Taylor polynomial of
24 $f(x + x^
2)$ about $x =
1$, we get
28 taylor(f(x + x^
2),x,
1,
1);
34 f
\left(
2\right)+
\left(
\left.
{{d
}\over{d\,x
}}\,f
\left(x^
2+x
\right)
35 \right|_
{x=
1}\right)\,
\left(x-
1\right)+
\cdots
38 \noindent To ``simplify'' the Taylor polynomial, we must assign a gradient to $f$
45 taylor(f(x+x^
2),x,
1,
1);
49 f
\left(
2\right)+
3\,df
\left(
2\right)\,
\left(x-
1\right)+
\cdots
52 This method works well for simple problems, but it
53 is tedious for functions of several variables or high order
54 derivatives. The positional derivative package
{\tt pdiff
} gives
55 an alternative to using
{\tt gradef
} when working with derivatives
60 To use the positional derivative package, first load it from the Maxima input prompt.
68 {\tt pdiff.lisp
} sets the option variable
{\tt use
\_pdiff} to true;
69 when
{\tt use
\_diff} is true, Maxima will
70 indicate derivatives of unknown functions positionally. To illustrate,
71 the first three derivatives of $f$ are
83 \left[ f_
{\left(
1\right)
}(x),f_
{\left(
2\right)
}(x),f_
{\left(
3
87 The subscript indicates the order of the derivative; since $f$ is a function of
88 one variable, the subscript has only one index. When a function has more
89 than one variable, the subscript has an index for each variable
93 [diff(f(x,y),x,
0,y,
1), diff(f(y,x),x,
0,y,
1)
];
97 \left[ f_
{\left(
0,
1\right)
}(x,y),f_
{\left(
1,
0\right)
}(y,x)
101 \noindent Setting
{\tt use
\_pdiff} to false (either locally or globally) inhibits
102 derivatives from begin computed positionally
106 diff(f(x,x^
2),x), use_pdiff : false;
112 {{d
}\over{d\,x
}}\,f
\left(x,x^
2\right)
116 diff(f(x,x^
2),x), use_pdiff : true;
122 f_
{\left(
1,
0\right)
}(x,x^
2)+
2\,x\,f_
{\left(
0,
1\right)
}(x,x^
2)
126 Taylor polynomials of unknown functions can be found without using
127 {\tt gradef
}. An example
131 taylor(f(x+x^
2),x,
1,
2);
137 f
\left(
2\right)+
3\,f_
{\left(
1\right)
}(
2)\,
\left(x-
1\right)+
{{
138 \left(
2\,f_
{\left(
1\right)
}(
2)+
9\,f_
{\left(
2\right)
}(
2)
\right)\,
139 \left(x-
1\right)^
2}\over{2}}+
\cdots
142 \noindent Additionally, we can verify that $ y = f(x-c \, t) + g(x+c \,t)$ is
143 a solution to a wave equation without using
{\tt gradef
}
147 y : f(x-c*t) + g(x+c*t)$
151 ratsimp(diff(y,t,
2) - c^
2 * diff(y,x,
2));
164 \noindent Expressions involving positional derivatives can be differentiated
172 f_
{\left(
1,
0\right)
}(x,y)
182 f_
{\left(
1,
1\right)
}(x,y)
186 \noindent The chain rule is applied when needed
190 [diff(f(x^
2),x), diff(f(g(x)),x)
];
196 \left[ 2\,x\,f_
{\left(
1\right)
}(x^
2),g_
{\left(
1\right)
}(x)\,f_
{
197 \left(
1\right)
}(g
\left(x
\right))
\right]
201 The positional derivative package doesn't alter the way known functions
216 \noindent To convert positional derivatives to standard Maxima derivatives,
217 use
{\tt convert
\_to\_diff}
221 e :
[diff(f(x),x), diff(f(x,y),x,
1,y,
1)
];
227 \left[ f_
{\left(
1\right)
}(x),f_
{\left(
1,
1\right)
}(x,y)
\right]
231 e : convert_to_diff(e);
237 \left[ {{d
}\over{d\,x
}}\,f
\left(x
\right),
{{d^
2}\over{d\,y\,d\,x
}}
238 \,f
\left(x,y
\right)
\right]
241 \noindent To convert back to a positional derivative, use
{\tt ev
} with
{\tt diff
}
252 \left[ f_
{\left(
1\right)
}(x),f_
{\left(
1,
1\right)
}(x,y)
\right]
255 \noindent Conversion to standard derivatives sometimes requires the
256 introduction of a dummy variable. Here's an example
260 e : diff(f(x,y),x,
1,y,
1);
266 f_
{\left(
1,
1\right)
}(x,y)
276 f_
{\left(
1,
1\right)
}(x,p
\left(s
\right))
280 e : convert_to_diff(e);
286 \left.
{{d^
2}\over{d\,\%x_0\,d\,x
}}\,f
\left(x,\%x_0
\right)
\right|_
{
287 \left[ \%x_0=p
\left(s
\right)
\right] }
290 Dummy variables have the form ci, where i=
0,
1,
2\dots and c is the
291 value of the option variable
{\tt dummy
\_char}. The default value
292 for
{\tt dummy
\_char} is
{\tt \%x
}. If a user variable conflicts with a
293 dummy variable, the conversion process can give an
294 incorrect value. To convert the previous expression back to a positional derivative,
295 use
{\tt ev
} with
{\tt diff
} and
{\tt at
} as arguments
305 f_
{\left(
1,
1\right)
}(x,p
\left(s
\right))
309 Maxima correctly evaluates expressions involving positional derivatives
310 if a formula is later given to the function. (Thus converting an unknown
311 function into a known one.) Here is an example; let
321 2\,x\,f_
{\left(
1\right)
}(x^
2)
324 \noindent Now, give $f$ a formula
337 \noindent and evaluate
{\tt e
}
351 \noindent This result is the same as
365 \noindent In this calculation, Maxima first evaluates $f(x)$ to $x^
{10}$ and then
366 does the derivative. Additionally, we can substitute a value for $x$
382 \noindent We can duplicate this with
387 subst(
2,x,diff(f(x^
2),x));
407 \noindent We can also evaluate a positional derivative using a local
418 g_
{\left(
1\right)
}(x)
428 {{1}\over{2\,
\sqrt{x
}}}
438 {{1}\over{2\,
\sqrt{x
}}}
448 h_
{\left(
1\right)
}(x)
452 e, g = lambda(
[t
],t^
2);
462 \subsection*
{The
{\tt pderivop
} function
}
464 If $F$ is an atom and $i_1, i_2,
\dots i_n$ are nonnegative
465 integers, then $
\mbox{pderivop
}(F,i_1,i_2,
\dots i_n)$, is the
466 function that has the formula
468 \frac{\partial^
{i_1 + i_2 +
\cdots + i_n
}}{\partial x_1^
{i_1
}
469 \partial x_2^
{i_2
} \cdots \partial x_n^
{i_n
}} F(x_1,x_2,
\dots x_n).
471 If any of the derivative arguments are not nonnegative integers,
479 Each derivative order must be a nonnegative integer
482 \noindent The
{\tt pderivop
} function can be composed with itself
485 pderivop(pderivop(f,
3,
4),
1,
2);
493 \noindent If the number of derivative arguments between two calls
494 to
{\tt pderivop
} isn't the same, Maxima gives an error
497 pderivop(pderivop(f,
3,
4),
1);
500 The function f expected
2 derivative argument(s), but it received
1
503 When
{\tt pderivop
} is applied to a known function, the result is
504 a lambda form
\footnote{If you repeat theses calculations, you
505 may get a different prefix for the
{\tt gensym
} variables.
}
524 \lambda\left(
\left[ Q_
{1253} \right] ,
2\,Q_
{1253}\right)
544 \lambda\left(
\left[ Q_
{1254} \right] ,
2\right)
568 If the first argument to
{\tt pderivop
} is a lambda form, the
569 result is another lambda form
574 f : pderivop(lambda(
[x
],x^
2),
1);
580 \lambda\left(
\left[ Q_
{1255} \right] ,
2\,Q_
{1255}\right)
594 f : pderivop(lambda(
[x
],x^
2),
2);
600 \lambda\left(
\left[ Q_
{1256} \right] ,
2\right)
614 f : pderivop(lambda(
[x
],x^
2),
3);
620 \lambda\left(
\left[ Q_
{1257} \right] ,
0\right)
638 If the first argument to
{\tt pderivop
} isn't an atom or
639 a lambda form, Maxima will signal an error
647 Non-atom g+f used as a function
650 You may use
{\tt tellsimpafter
} together with
{\tt pderivop
} to
651 give a value to a derivative of a function at a point; an
656 tellsimpafter(pderivop(f,
1)(
1),
1)$
660 tellsimpafter(pderivop(f,
2)(
1),
2)$
664 diff(f(x),x,
2) + diff(f(x),x)$
675 This technique works for functions of several variables as well
683 tellsimpafter(pderivop(f,
1,
0)(
0,
0),a)$
687 tellsimpafter(pderivop(f,
0,
1)(
0,
0),b)$
691 sublis(
[x =
0, y =
0], diff(f(x,y),x) + diff(f(x,y),y));
701 \subsection*
{\TeX{}-ing positional derivatives
}
703 Several option variables control how positional derivatives
704 are converted to
\TeX{}. When the option variable
705 {\tt tex
\_uses\_prime\_for\_derivatives} is true (default false),
706 makes functions of one variable
\TeX{} as superscripted primes
710 tex_uses_prime_for_derivatives : true$
714 tex(makelist(diff(f(x),x,i),i,
1,
3))$
718 \left[ f^
{\prime}(x),f^
{\prime\prime}(x),f^
{\prime\prime\prime}(x)
723 tex(makelist(pderivop(f,i),i,
1,
3))$
727 \left[ f^
{\prime},f^
{\prime\prime},f^
{\prime\prime\prime} \right]
730 When the derivative order exceeds the value of the option
731 variable
{\tt tex
\_prime\_limit}, (default
3)
732 derivatives are indicated with parenthesis delimited superscripts
736 tex(makelist(pderivop(f,i),i,
1,
5)), tex_prime_limit :
0$
740 \left[ f^
{(
1)
},f^
{(
2)
},f^
{(
3)
},f^
{(
4)
},f^
{(
5)
} \right]
744 tex(makelist(pderivop(f,i),i,
1,
5)), tex_prime_limit :
5$
749 \left[ f^
{\prime},f^
{\prime\prime},f^
{\prime\prime\prime},f^
{\prime
750 \prime\prime\prime},f^
{\prime\prime\prime\prime\prime} \right]
753 The value of
{\tt tex
\_uses\_prime\_for\_derivatives} doesn't change the way
754 functions of two or more variables are converted to
\TeX{}.
758 tex(pderivop(f,
2,
1));
767 When the option variable
{\tt tex
\_uses\_named\_subscripts\_for\_derivatives}
768 (default false) is true, a derivative with respect to the i-th argument is
769 indicated by a subscript that is the i-th element of the option variable
770 {\tt tex
\_diff\_var\_names}. An example is the clearest way to
775 tex_uses_named_subscripts_for_derivatives : true$
790 tex(
[pderivop(f,
1,
0), pderivop(f,
0,
1), pderivop(f,
1,
1), pderivop(f,
2,
0)
]);
793 $$
\left[ f_
{x
},f_
{y
},f_
{xy
},f_
{xx
} \right] $$
797 tex_diff_var_names :
[a,b
];
808 tex(
[pderivop(f,
1,
0), pderivop(f,
0,
1), pderivop(f,
1,
1), pderivop(f,
2,
0)
]);
811 $$
\left[ f_
{a
},f_
{b
},f_
{ab
},f_
{aa
} \right] $$
816 tex_diff_var_names :
[x,y,z
];
826 tex(
[diff(f(x,y),x), diff(f(y,x),y)
]);
829 $$
\left[ f_
{x
}(x,y),f_
{x
}(y,x)
\right] $$
833 When the derivative order exceeds
{tt tex
\_prime\_limit}, revert to the default
834 method for converting to
\TeX{}
838 tex(diff(f(x,y,z),x,
1,y,
1,z,
1)), tex_prime_limit :
4$
846 tex(diff(f(x,y,z),x,
1,y,
1,z,
1)), tex_prime_limit :
1$
849 $$f_
{\left(
1,
1,
1\right)
}(x,y,z)$$
850 \subsection*
{A longer example
}
852 We'll use the positional derivative package to change the independent
853 variable of the differential equation
857 de :
4*x^
2*'diff(y,x,
2) +
4*x*'diff(y,x,
1) + (x-
1)*y =
0;
863 4\,x^
2\,
\left(
{{d^
2}\over{d\,x^
2}}\,y
\right)+
4\,x\,
\left(
{{d
864 }\over{d\,x
}}\,y
\right)+
\left(x-
1\right)\,y=
0
867 With malice aforethought, we'll assume a solution of the form
868 $ y = g(x^n)$, where $n$ is a number. Substituting $y
\rightarrow g(x^n)$
869 in the differential equation gives
873 de : subst(g(x^n),y,de);
879 4\,x^
2\,
\left(
{{d^
2}\over{d\,x^
2}}\,g
\left(x^
{n
}\right)
\right)+
4\,
880 x\,
\left(
{{d
}\over{d\,x
}}\,g
\left(x^
{n
}\right)
\right)+
\left(x-
1
881 \right)\,g
\left(x^
{n
}\right)=
0
891 4\,x^
2\,
\left(n^
2\,x^
{2\,n-
2}\,g^
{\prime\prime}(x^
{n
})+
\left(n-
1
892 \right)\,n\,x^
{n-
2}\,g^
{\prime}(x^
{n
})
\right)+
4\,n\,x^
{n
}\,g^
{\prime
893 }(x^
{n
})+
\left(x-
1\right)\,g
\left(x^
{n
}\right)=
0
896 Now let $x
\rightarrow t^
{1/n
}$
900 de : radcan(subst(x^(
1/n),x, de));
906 4\,n^
2\,x^
2\,g^
{\prime\prime}(x)+
4\,n^
2\,x\,g^
{\prime}(x)+
\left(x
907 ^
{{{1}\over{n
}}}-
1\right)\,g
\left(x
\right)=
0
910 Setting $n
\rightarrow 1/
2$, we recognize that $g$ is the order
1 Bessel
921 x^
2\,g^
{\prime\prime}(x)+x\,g^
{\prime}(x)+
\left(x^
2-
1\right)\,g
926 \subsection*
{Limitations
}
929 \item Positional derivatives of subscripted functions are not allowed.
931 \item Derivatives of unknown functions with symbolic orders are not
932 computed positionally.
934 \item The
{\tt pdiff.lisp
} code alters the Maxima functions
{\tt mqapply
}
935 and
{\tt sdiffgrad
} Although I'm unaware of any problems associated
936 with these altered functions, there may be some. Setting
{\tt use
\_pdiff} to
937 false should restore
{\tt mqapply
} and
{\tt sdiffgrad
} to their
938 original functioning.
942 \subsection*
{Conclusion
}
944 The
{\tt pdiff
} package provides a simple way of working with
945 derivatives of unknown functions. If you find a bug in the package,
946 or if you have a comment or a question, please send it to
947 {\tt willisb@unk.edu
}.
949 The
{\tt pdiff
} package could serve as a basis for a Maxima package
950 differential and integral operators.