maxima

Engineering + Mathematics, Programming

maxima

Unfortunately, I have been having difficulties with getting \(latex\) rendering inside code blocks. When using wxmaxima, the output from each line formats beautifully in latex, but when transferred to this blog the pretty format disappears. Hopefully I can resolve this for future posts…

I’ve recently been looking at the tools I have at my disposal for symbolic math and graphing. Disappointingly, I came up with a rather sparse list. My biggest want is to be able to solve equations symbolically (rather than numerically) and to quickly plot the result of symbolic functions. Currently, I tend to do all of the former manually (not a bad thing) and the latter with excel.

A side note; recently I’ve been finding excel absolutely indaquate to the kind of workflow and tasks that I want to be doing. I think this can be summarized by the following:

  • Lack of data strcture
  • Weak function library
  • Constant need for ‘work-arounds’ for data manipulations
  • Normalizing data? Either do it manually or set up some complicated pivot-table + reference helper tables. A great way to turn one data set into three!
  • Combining lists? Do it manually.
  • I could go on…

At university I used matlab + maple in my engineering degree. Both have the functionality that I’m after, but not for the price and the hassle of licensing software.

I dabbled for a very short while with Sage, but found it weirdly difficult. I’ll certainly revisit it again later, I’m not really sure how to explain my aversion to it.

So I landed on learning some Maxima. Maxima has very old, deep roots. Originated in the ’60s, open sourced in 1998, and still being actively developed. Definitely ticks the boxes for me.

A simple example that I wanted try was to plot some pressure/quantity curves for underground ventilation. The below was generated in html by wxmaxima. I really like interactively building a workbook, with inline images, in wxmaxima. This is a nice, quick, workflow that encourages trial and error.

When we’re using maxima, lines begining with (%in) are input lines, and (%on) are output lines, where n is the line number. We can use either of these references later in the code.

(%i1)	_p: R*q^2;
(%o1)	R*q^2
(%i2)	pr_n : _p, R=[0.01, 0.02, 0.03, 0.04];
(%o2)	[0.01*q^2,0.02*q^2,0.03*q^2,0.04*q^2]

(%i3)	wxplot2d(pr_n, [q, 0, 60], 
	    [xlabel, "Quantity (m^3/s)"], 
	    [ylabel, "Pressure (pa)"]
	);
Output from line %i3

Line 1 creates an expression with the two symbols R and q. This is the equation p=R*q^2. The second line of input creates an array of expressions, substituting in R=0.01, 0.02…etc. We collect this into the variable pr_n. We could write this as

pr_n : [pr1, pr2, pr3, pr4] : _p, R=[0.01, 0.02, 0.03, 0.04] 

if we wanted to keep a reference to each of the individual expressions.

The third line of input plots each of the expressions in terms of q over the range 0 to 60. It also sets labels for the two axes.

Nice one.

I’m quite happy with how that looks. In three simple lines of code we’ve done quite a bit. Next post I’ll have a look at a process for plotting a fan curve on to the same graph (or maybe a couple of fan curves). This will include sourcing data from a .csv file, plotting the discrete data and fitting a curve. A cursory glance at the curve fitting routines that maxima has indicates that the curve fitting should be more accurate than excel for my twin 45kW contra rotating CC1004.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.