Skip to content

Instantly share code, notes, and snippets.

@endolith
Created October 27, 2009 18:48
Show Gist options
  • Select an option

  • Save endolith/219815 to your computer and use it in GitHub Desktop.

Select an option

Save endolith/219815 to your computer and use it in GitHub Desktop.
Maxima shortcuts for audio and electronics

Shortcuts for doing audio/electronics calculations in Maxima. This loads automatically at startup if placed in a directory like this:

  • C:\Documents and Settings\User Name\maxima\maxima-init.mac (XP)
  • C:\Users\User Name\maxima\maxima-init.mac (Windows 7)
  • ~/.maxima/maxima-init.mac (Ubuntu)

|| infix binding power is set to happen after multiplication, but before addition.
I think it might be best if it happened before division, but * and / are both 120, so I'm not messing with that until I understand it better. In other words:

  • a * b || c = (a * b) || c
  • a / b || c = a / (b || c)
  • a + b || c = a + (b || c)

I added multipliers like k and M as an experiment. The unit package would seem to be the standard way to do this, but it doesn't exactly work for quick calculations. I'd have to set up abbrevations for things like "mA", "uF", "kohm" etc anyway, and then it still wouldn't work:

(%i1) ((20*kiloohm||5*kiloohm)+6.8*kiloohm) || ((20*kiloohm||5*kiloohm)+6.8*kiloohm);
* long pause *
(%o1) Maxima encountered a Lisp error:
 Error in COND [or a callee]: Invocation history stack overflow.
Automatically continuing.
To reenable the Lisp debugger set *debugger-hook* to nil.

Much simpler:

(%i1) ((20k||5k)+6.8k) || ((20k||5k)+6.8k);
(%o1) 5899.375156210947

but I disabled it:

Incorrect syntax: K is not a prefix operator
/* Decibel conversion and inverse */
db(x) := float(20 * log(abs(x)) / log(10));
idb(x) := float(10^(x / 20));
/* For calculating components in parallel */
infix("||", 119, 119)$ "||"(x, y) := x * y / (x + y);
/* log(x) is always ambiguous from one language to the next. Now it's not. */
log10(x) := log(x) / log(10);
log2(x) := log(x) / log(2);
ln(x) := log(x);
/* SI multiples */
/* This conflicts with the "unit" package, which is better in some ways, but not in others... */
/* Disabled because they break stuff
postfix("p", 120)$ "p"(x) := x / 1000000000000;
postfix("n", 120)$ "n"(x) := x / 1000000000;
postfix("u", 120)$ "u"(x) := x / 1000000;
postfix("m", 120)$ "m"(x) := x / 1000;
postfix("k", 120)$ "k"(x) := 1000 * x;
postfix("M", 120)$ "M"(x) := 1000000 * x;
postfix("G", 120)$ "G"(x) := 1000000000 * x; */
/* for unit package:
infix(" in ")$ " in "(x,y):=convert(x,y); */
print("*** Audio electronics shortcuts (maxima-init.mac) have been loaded. ***");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment