My .octaverc

Since I mentioned my ~/.octaverc file a couple of posts ago, I might as well show you the whole thing. It’s not much.

The ~/.octaverc file is one of those dotfiles so beloved by Unix users. It’s a set of Octave commands that are run at the beginning of every session to customize the environment to you liking. It’s just one of four possible octaverc files that Octave looks for when starting up, but the other, which are documented here, tend to be used less because they’re applied either too broadly or too narrowly.

Here it is:

 1:  PS1(">>> ")
2:  PS2("... ")
3:
4:  function retval = atan2d(y, x)
5:    retval=atan2(y,x)*180/pi;
6:  endfunction
7:
8:  function retval = comb(n,m)
9:    retval = bincoeff(n,m);
10:  endfunction
11:
12:  function retval = perm(n,m)
13:    retval = bincoeff(n,m)*factorial(m);
14:  endfunction


The first two lines change the prompts to match those in a Python interactive session. I discussed my reasons for doing that earlier.

Lines 4-6 define an analog to the regular atan2 function. As you might expect from the trailing d, it returns the arctangent in degrees (as opposed to radians) of y/x. This function fills in an odd gap in Octave: there’s a built-in d version of every trig and inverse trig function except atan. This fills the gap.

The comb function in Lines 8-10 is there simply because when I need to know the number of combinations of n things taken m at a time, I find it easier to remember a function named comb than a function named bincoeff. So I defined a synonym.

The perm function in Lines 12-14 is just slightly more complicated than a synonym. By multiplying the binary coefficient by m!, I get the number of permutations of n items taken m at a time.

That’s it. Told you it wasn’t much.