A maxima function to replicate MATLAB diff() and an efficiency comparison

I needed a function to compute a list containing the difference between adjacent entries in another list, as diff() does for an array in MATLAB.

I first wrote  something using makelist() and found it very slow for large lists.  I then rewrote the function using rest() and found it much faster:

differ

 

Advertisement

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?

diffderivative