## Surface Integrals and Stokes Theorem in Maxima

In an earlier post I detailed the Maxima functions contained  the MATH214 package for use in my multivariable calculus class.  The package at that link has now been updated with some further integration utilities:  integrate2() and integrate3() for double and triple integrals and integrateSurf() for surface integrals of vector fields in 3D.  I’ve posted examples with applications to Green’s  Theorem and Gauss’s Theorem.

Here’s a test drive of the surface integration function using a Stokes theorem example I found on the web:

Verify Stokes theorem for the surface S described by the paraboloid z=16-x^2-y^2 for z>=0

and the vector field

F =3yi+4zj-6xk

First the path integral of the vector field around the circular boundary of the surface using integratePathv3() from the MATH214 package And also the surface integral using integrateSurf().  Notice that in the order of integration we specify in integrateSurf(),  (first  y then x) the surface normal vector computed with cross() in that same variable order points inward—the negative orientation.  We reverse the direction with an extra negative inside the surface integral. Although they are included in the MATH214 package, here are the  functions used above:

integrateSurf(F,S,uu,aa,bb,vv,cc,dd):=block(
[F2],
F2:psubst([x=S,y=S,z=S],F),
integrate(integrate(trigsimp(F2.cross(diff(S,uu),diff(S,vv))),uu,aa,bb),vv,cc,dd));

cross(_u,_v):=[_u*_v-_u*_v,_u*_v-_u*_v,_u*_v-_u*_v]$curl(f,x,y,z):=[ 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) ]$
integratePathv3(H,r,t,a,b):=block(
[H3],
H3:psubst([x=r,y=r,z=r],H),
integrate( trigsimp(H3.diff(r,t)),t,a,b)
);

## An improved Maxima function for inverse Laplace transform

Maxima has a fairly serviceable Laplace transform utility built-in.  Here’s an example from the popular ordinary differential equations book by Blanchard, Devaney and Hall: Trouble arises when we look at discontinuous forcing functions, which is especially sad because it seems to me that’s what makes it worthwhile to spend time with Laplace transforms.  In particular, the inverse transform function ilt() fails on the Heaviside Function and Dirac Delta, even though the built-in laplace() treats them correctly: So, I’ve written an alternative inverse Laplace function laplaceInv() that fixes that problem: Here are a few differential equation solutions to show how the new function behaves:

A second-order linear equation with a constant forcing function that vanishes at $t=7$  A second-order equation with two impulsive forces:  ## Popularity of CAS programming languages: Maxima, Maple, Mathematica

A few months ago, inspired by the PYPL PopularitY of Programming Language,  I compared Google trends data for the 3M of CAS software:  Maxima, Maple, and Mathematica based searches of the form “<language> tutorial”.  The result was that Maxima seems to be slowly increasing in popularity  with about 20% of the interest in the 3M.

Today I saw another popularity metric: The TIOBE index.  Using their methodology of Google trends data for the search string <language> + programming, I have these  results for the proportion of searches among the 3M: ## An undocumented synonym for diff() in Maxima

Today, a student turned in some Maxima work for my class. I discovered he had successfully used the command derivative() in place of diff() with seemingly identical results.  I verified that the same thing works in several versions of Maxima I have installed on my windows computer.  Who knew? ## Legend Position in Maxima Plots

Here’s something I just learned and want to share with others and record for my use the next time I need to do this and have already forgotten!

The position and appearance of the figure legend in Maxima plots drawn with plot() (by setting gnuplot_preamble) and in draw() (by setting user_preamble),  can be manipulated to any of the gnuplot options listed here.

Here are some examples:   ## logarc

In the back of my calculus book there is a table of famous integrals.  Here’s integral number 21 in that table: From Maxima integrate(), I get What’s going on?

Both forms give a workable antiderivative for the original integrand: Furthermore, we believe that both forms are correct because of this helpful identity for hyperbolic sine: ${\rm asinh}(z)=\ln(z+\sqrt{1+z^2}).$

Turns out (thanks to a Barton Willis for pointing me in the right direction) there’s a variable logarc that we can set to make Maxima return the logarithmic form instead of hyperbolic sine: I haven’t yet encountered cases where this would be a bad idea in general, but I’ll update this if I do.

## logabs

In the first week of my differential equations course, we study methods of direct integration and separation of variables.  I like to emphasize that the absolute values can lend an extra degree of generality to solutions with antiderivatives of the form $\int \frac{1}{u}\;du = \ln |u|+ C.$

As an example, for the initial value problem $y' = \frac{x}{1-x^2}$, $y(0)=1$,

it is convenient for treating all possible initial conditions ( $x \ne \pm 1$) in one step to use the antiderivative $y = -\frac{1}{2} \ln | 1-x^2 | + C.$

However, Maxima omits the absolute values. For this case, we could consider only the needed interval $-1, but still…

Turns out we can set the Maxima variable logabs to make integrate() include absolute values in cases like this: But then later in the course, I saw that logabs also impacts the Ordinary Differential Equation solver ode2().  I encountered an example for which Maxima, in particular solve() applied to expressions involving absolute value,  didn’t do what I wanted with logabs:true

For the logistic equation $\frac{dP}{dt} = kP\left ( 1-\frac{P}{P_c} \right )$, $P(0)=P_0$

we expect that by separating variables we can obtain the solution $P(t) = \frac{P_0 P_c}{(P_c-P_0)e^{-kt}+ P_0}.$

Here’s what happens when we use ode2() with and without logabs:true:  ## Student Projects in Maxima Vol 1, Num 4: ODE Systems for Epidemiological Models

Student Projects in Maxima is an online project to disseminate work by undergraduate students using Maxima to reproduce published results in the sciences and social sciences.

Volume 1, Number 4 (2017) is devoted to Systems of Ordinary Differential Equations for SIR models in epidemiology.

Contents:

Emenheiser, Anna, Virus Dynamics and Drug Therapy

Radermacher, Erin, A Model of the 2014 Ebola Outbreak

Rafai, Sagar, Analysis of Communicable Disease Models

## Student Projects in Maxima Vol 1, Num 3: ODE Systems for Interacting Population Models

Student Projects in Maxima is an online project to disseminate work by undergraduate students using Maxima to reproduce published results in the sciences and social sciences.

Volume 1, Number 3 (2017) is devoted to Systems of Ordinary Differential Equations for non-chaotic predator-prey and other interacting population models

Contents:

Bhullar, Abhjeet,  Lions, Wildebeest and Zebras

Goodin Aunic, Parasitic Nematodes in Grouse

DeFore, Brandon, Breeding Suppression in Predator-Prey

Jerez, Emilio, Predator-Prey with Hawk and Dove Tactics

Bontrager, Eric, Predator-Prey with Prey Switching

Beatty, Ethan, Analysis of Logistic Growth Models

Rice, Gabriel, Pharmacokinetic Mechanism of Ethanol-Benzodiazepine Interactions

Wile, Jessica, Ebola in Western Lowlands Gorillas

Bailey, John,  Kinetic Modeling for Interconnected Reactions

Piet, Joe, Elephant and Tree Population Dynamics

Kim, Judy, A Model for West Nile Virus

Kamalaldin, Kamalaldin, Infected Prey in Polluted Environment

Park, Kayla, Ratio-Dependent Predator Prey Model

Lundy, Liam, Predator Prey in a Single Species with Cannibalism

Orwin, Michael, Interactions of Model Neurons

Schultz, Pete, Photosynthetic Oscillations

Wadhwa, Raoul, Dynamics in an Inflammation Model

Del Olmo, Ricardo, Population Growth and Technological Change

Network Model of Cocaine Traffic in Spain Edited

Kill, Sean, A Logistic Model with Varying Carrying Capacity

McFadden-Keesling, Sophia,  Predator Prey Model with a Refuge

Samson, Tanush,  Lions and Wildebeest Model

Morales, Zach,  Game Theory Models

## Student Projects in Maxima Vol 1, Num 1: Systems of ODEs and Chaos

Student Projects in Maxima is an online project to disseminate work by undergraduate students using Maxima to reproduce published results in the sciences and social sciences.

Volume 1, Number 1 (2017) is devoted to Chaotic Systems of Ordinary Differential Equations.

Contents:

Thornburg, Eric, Simple Pendulum and Chaos

Bhimani, Kevin, Chaos in a 3-Species Food Chain

York, Lily, A Lattice Model of Epilepsy

Andrews, Steven, 3D Chaotic Model

Rutledge, Tim,  A Model of Neuronal Bursting

## Student Projects in Maxima Vol 1, Num 2: Systems of ODEs with Impulses and Switching Functions

Student Projects in Maxima is an online project to disseminate work by undergraduate students using Maxima to reproduce published results in the sciences and social sciences.

Volume 1, Number 2 (2017) is devoted to Systems of Ordinary Differential Equations with time-dependent forcing terms, non-continuous inputs, and forcing terms that require knowledge of a past state of the system.

Contents:

Chumley, Qynce, An Office Heating and Cooling Model

Williams, Nick, Baseball Pitch Dynamics

Rizzolo, Skylar, BAC Model for alcohol consumption

Barth, Eric, A model of bladder bacteria proliferation in prostate disease

Barth, Eric, A Model of Pulse Vaccination Strategyi