Endolith (owner)

Revisions

gist: 219815 Download_button fork
public
Description:
Maxima shortcuts for audio and electronics
Public Clone URL: git://gist.github.com/219815.git
Embed All Files: show embed
readme.txt #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
Shortcuts for doing audio/electronics calculations in Maxima. This loads
automatically at startup if placed in
C:\Program Files\Maxima-5.19.2\share\maxima\5.19.2\share
or ~/.maxima/maxima-init.mac, for instance.
 
|| 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
(http://www.my-tool.com/mathematics/maximaphp/doc/maxima_71.html) 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 disabled it:
 
Incorrect syntax: K is not a prefix operator
maxima-init.mac #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
/* 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. ***");