## Path Integrals

For my multivariable calculus class, I wanted an easy-to-call suite of symbolic integrators for path integrals of the form $\int_C f(x,y) dr$, $\int_C {\bf F}(x,y)\cdot d{\bf r} = \int_C \langle P(x,y), Q(x,y) \rangle\cdot \langle dx, dy \rangle$, or $\int_C {\bf F}(x,y,z)\cdot d{\bf r} = \int_C \langle P(x,y,z), Q(x,y,z), R(x,y,z) \rangle\cdot \langle dx, dy, dz \rangle$.

My overarching design idea was that the input arguments needed to look the way they do when I teach the course:

• a scalar field $f(x,y):R^2 \rightarrow R$ or a vector field ${\bf F}(x,y): R^2 \rightarrow R^2$ or ${\bf F}(x,y,z): R^3 \rightarrow R^3$
• a curve $C$ defined by a vector-valued function ${\bf r}(t): R \rightarrow R^n, a\le t \le b$ where $n=2,3$ as appropriate.

It took me a while to work out how to evaluate the integrand along the path within my function.  Things that worked fine on the command line failed when embedded into a batch file to which I passed functions as arguments.  I ended up using subst, one variable at a time.  I’d like to be able to do this in a single command which can detect whether we’re in 2 or 3 dimensions so that I don’t need separate commands.

For now, here’s what I came up with along with some illustrative examples taken from Paul’s online math notes, that show how to call these new commands I, I2 and I3.

/* path integral of a scalar integrand f(x,y) on path r(t) in R^2, t from a to b */
I(f,r,t,a,b):=block(
[f1,f2,dr,Iout],
f1:subst(x=r,f),
f2:subst(y=r,f1),
dr:sqrt(diff(r,t).diff(r,t)),
Iout: integrate(f2*dr,t,a,b),
Iout
);
/* path integral of a vector integrand F(x,y) on path r(t) in R^2, t from a to b */
I2(H,r,t,a,b):=block(
[H1,H2,I],
H1:subst(x=r,H),
H2:subst(y=r,H1),
I: integrate( H2.diff(r,t),t,a,b),
I
);
/* path integral of a vector integrand F(x,y,z) on path r(t) in R^3, t from a to b */
I3(H,r,t,a,b):=block(
[H1,H2,H3,I],
H1:subst(x=r,H),
H2:subst(y=r,H1),
H3:subst(z=r,H2),
I: integrate( H3.diff(r,t),t,a,b),
I
); Here’s an update:  a related maxima function for evaluating a complex integral $\int_\Gamma f(z) dz$

where $f: C \rightarrow C$ and the curve $\Gamma$ is given by $r: R \rightarrow C$.

/* path integral of a complex integrand f(z): C --> C, on path z(t): R --> C, t from a to b */
IC(f,r,t,a,b):=block(
[f1,dz,Iout],
f1:subst(z=r,f),
dz:diff(r,t),
Iout: integrate(f1*dz,t,a,b),
Iout
); ## :=, ”(), define and div, grad, curl

I recently posted about : and :=  for defining functional expressions.  I’m starting to enjoy these emoji-like constructions 😉

This is another  colon-equals post.  This time for defining functions involving the maxima differentiation command diff.

Notice below that if we define a function with :=, the naive use of :=diff doesn’t produce a derivative with the expected results upon evaluation. In fact, it’s a good thing that :=diff works like that.  The error with fp(3) above comes from the fact that we’ve actually defined an operator that differentiates the function with respect to the argument we pass…in the case above, differentiating with respect to the symbol u makes sense, while differentiating with respect to the constant 3 doesn’t.

So how to make the derivative function do what we want?  Two ways, that are subtly different, in ways I’m not completely sure of.  More about that when I learn more :-).

First is define, Also you can use    ”()       quote-quote with parens around the whole right hand side: I used define to write functions for vector valued 3D curves in an earlier post.   In figuring this out, I also learned that the :=diff form is really useful.  Below are three little functions in which I use :=diff to define the vector calculus operators grad, div and curl.  Notice that we pass the function f as an argument, and the :=diff form allows Maxima to differentiate them behind the scenes and return the results of the grad, div, and curl operators as you’d expect. These versions of div, grad and curl behave differently, and for me more as expected, than the functions of those names included in the Maxima vect package.  You can download the .mac file here.

/* Three Maxima functions for the multivariable calculus operators  grad, div, and curl
TheMaximaList.org, 2016
*/

grad(f,x,y,z):=[diff(f,x),diff(f,y),diff(f,z)]$div(f,x,y,z):=diff(f,x)+diff(f,y)+diff(f,z)$

curl(f,x,y,z):=[ diff(f,y)-diff(f,z),
diff(f,z)-diff(f,x),
diff(f,x)-diff(f,y) ]$Here is a screenshot showing how to call these functions: ## Curvature, T, N, & B A classic topic in multivariable calculus involves the study of a vector valued function ${\bf r}(t)=\langle x(t),y(t),z(t) \rangle$ using the three canonical unit vectors — the tangent vector ${\bf T}(t)$, the normal vector ${\bf N}(t)$, and the Binormal vector ${\bf B}(t)$ — and the scalar curvature $\kappa(t)$. Here are maxima functions that compute these, called unitT, unitN, unitB, and curvature. For a vector valued function ${\bf r}(t)$, these are called as T(t):=unitT(r(t),t); You can download the .mac file here. /* unitT computes the unit tangent vector for a vector valued function of a scalar variable r(t)=[x(t),y(t),z(t)] */ unitT(r,t):= block([rp,rpn,T], define(rp(t),diff(r,t)), define(rpn(t),sqrt(rp(t).rp(t))), define(T(t),rp(t)/rpn(t)), trigsimp(T(t)) )$

/* unitN computes the unit normal vector for a vector valued function
of a scalar variable r(t)=[x(t),y(t),z(t)]
unitN requires unitT */

unitN(r,t):=
block([T,Tp,Tpn,N],
define(T(t),unitT(r,t)),
define(Tp(t),diff(T(t),t)),
define(Tpn(t),sqrt(Tp(t).Tp(t))),
define(N(t),Tp(t)/Tpn(t)),
trigsimp(N(t))
)$/* unitB computes the unit normal vector for a vector valued function of a scalar variable r(t)=[x(t),y(t),z(t)] unitB requires unitT and unitN */ unitB(r,t):= block([T,N,B], define(T(t),unitT(r,t)), define(N(t),unitN(r,t)), define(B(t),[T(t)*N(t)-T(t)*N(t), T(t)*N(t)-T(t)*N(t), T(t)*N(t)-T(t)*N(t)]), trigsimp(B(t)) )$

/* curvature computes the curvature
curvature requires unitT */

curvature(r,t):=
block([T,Tdot,rdot,K],
define(T(t),unitT(r,t)),
define(Tdot(t),diff(T(t),t)),
define(rdot(t),diff(r,t)),
define(K(t),trigsimp(sqrt(Tdot(t).Tdot(t)/rdot(t).rdot(t)))),
K(t)
)\$

## A surface, a tangent plane, a normal line

I set out to do a visualization that is basic to the multivariable calculus classroom:  plot a surface, a tangent plane, and a normal line.  I didn’t do it on the first try…or the second.

I had to learn some things about the draw3d functionality in Maxima and wxMaxima.  Here’s a great resource by Wilhelm Haager.  In the end I’m delighted at the amazing flexibility of that command, but still scratching my head a little about how this would appear to an otherwise uninitiated beginner to Maxima.

Here’s the html export of my session.

## Multivariable Optimization in Maxima

I’ve been working on a few problems from multivariable calculus, with and without the method of Lagrange multipliers.  I’ve learned a lot about the solve command, and also become much more comfortable with the amazingly flexible plotting command wxdraw3d. The calling sequence of wxdraw3d looks a little daunting compared to wxplot3d, but the added flexibility — especially the ability to superimpose several plots on the same set of 3D axes — is really brilliant!

Here is the HTML export from my wxMaxima session.  You can get to the .wxmx file from a link at the bottom of that page.

## Limits for functions of two variables

The Maxima limit command is limited (ha ha) to functions of a single variable.  We can use Maxima to approach the issue just as we do by hand computation:  reduce to single variable limits by considering that the vector variable (x,y) approaches the limit point (a,b) along paths of the form (x, y(x)).  Here’s a nice example from my Multivariable Calculus Class