Two Maxima Functions for Riemann Sums

Two early attempts at programming Maxima functions.  I’d love to hear your comments about how to make these work better.  Many thanks to the online community from whom I learned how to get this far!

The script is given at the bottom of this post.  Copy and paste into a file (in your working directory) called Riemann.mac, and then load into Maxima using



/* Two Maxima functions for introductory integral calculus
(c) 2016,  */

/* RiemannSum
fn is the function to be integrated on the interval [a,b]
n rectangles
opt specifies:
0: left endpoints
1: midpoints
2: right endpoints

xx(i,n):= a+(i+opt/2)*(b-a)/n,
s: sum(ev(fn,x=xx(i,n)),i,0,n-1)*(b-a)/n,


/* RiemannRectangles to Draw rectangles
fn is the function to be integrated:
on the interval [a,b]
n rectangles
opt specifies:
0: left endpoints
1: midpoints
2: right endpoints


xi(i,n):= a+i*(b-a)/n,
xx(i,n):= a+(i+opt/2)*(b-a)/n,
rects(n):=makelist(rectangle([xi(k,n),0], [xi(k+1,n),ev(fn,x=xx(k,n))]),k,0,n-1),
append([xrange=[a-(b-a)/4, b+(b-a)/4],color=blue],
[transparent=true, explicit(fn,x,a, b)]


Root of a nonlinear equation, as the last step of an ODE solution

What better use for a computer algebra system than a problem whose solution you know intuitively, and for which the paper-and-pencil work feels too daunting to start?  Here’s a problem that exploits what we know about the solutions of damped driven oscillators, making use of the usual ODE capabilities in Maxima, together with a nonlinear solve with find-root at the end.

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

For starters…

The MaximaList: A reason for being

A first post on a new blog ought to do some explaining about motivations and reason-to-exist, and here is mine:  After using and teaching with R, I am increasingly convinced that the availability of a powerful, free, widely-used software tool provides a link for students and professionals between training and practice that unties us from traditional institution-level constraints.  It’s fine to learn statistics using SPSS in college, but unless you go to work at another big institution that owns an SPSS license, you’re faced with (a) convincing them to buy one, or (b) learning a new system from scratch —  a start-up process so formidable that your hard-earned training fades from disuse.  Likewise with Maple and Mathematica for symbolic computation, and MATLAB for numerics.  For statistics, the R language and the portable graphical user interface RStudio provides us with a tool that we can bring with us on our own machines wherever our work takes us, and a community of users that can and does support users at all levels of sophistication.  The tight integration of R Markdown document preparation in RStudio has opened up many possibilities and prepared our students to really make productive use of their statistical training in their careers that span the range of professional fields.

For the last twenty years, I have carried out an annual ritual, making the rounds of free alternatives to MATLAB that are portable and easily-installed on all widely used operating systems.  It is only in the last few years with FreeMat  that I’ve been able to bring students on a large scale to the point that they can learn to use the power of a language like MATLAB in a not-just-in-the-computer-lab way.  “Can I install this on my Mac?” is the question I have to answer with an easy “yes” before I would ever consider integrating a software package into my courses.  That is happily now the case with all the packages I’ve mentioned here.  Add to that the fact that MATLAB is both a language and a proprietary software package allows students to use these free-ware packages while setting the stage for productive work throughout their careers because the’ve learned that widely-used language.

And now Maxima.  I’m relatively new to the program but experienced in the framework:

  • Find a software solution that works for users at all levels of technical expertise and identically on all popular operating systems
  • Build the use of that software into the teaching, learning, and professional workflow
  • Integrate document preparation at every stage so that students and professionals don’t just learn to perform calculations but also see the processes of computation and  effective presentation of their work  as a single thing.

With the graphical user interface wxMaxima, this is all possible.  The MaximaList is dedicated to adding value to the community by advancing those three aims.