In MATLAB, you can find the indices of array entries that match a user-supplied condition with the function find()
Here’s a similar function in Maxima. This makes liberal use of the functions sublist_indices(), lambda(), and several functions from the stringproc package: sequal(), eval_string(), and simplode(). Oh, and also the shameless hack of using ascii(32) as the space character 🙂
Here are some examples. The code is included at the bottom.
if sequal(oo,"=") or sequal(oo,">") or sequal(oo,">=") or sequal(oo,"<") or sequal(oo,"<=") or sequal(oo,"#") then
if sequal(oo,"and") or sequal(oo,"or") then(
I grew up with MATLAB, where extracting a subset of a vector V was easy as feeding a vector of indices into a vector. For example entries i thru j could be had with V(i:j) and an more complicated index scheme could be accomplished with a vector of indices i_index and then V(i_index).
In Maxima, first(), last(), firstn(), rest(), and most generally makelist() allows for all that and more but with a little more cumbersome calling protocols. Here are one-liners that achieve something like the two canonical MATLAB examples above:
In MATLAB, I occasionally have need for the plotyy() command for making a plot of two different functions with widely varying scales.
Turns out Maxima draw has an equivalent functionality by setting the option yaxis_secondary:
Here’s the documentation.
In MATLAB, pause
interrupts execution of a loop until the user strikes a key, and pause(<n>)
pauses for <n>
seconds before resuming execution.
Here’s my attempt at a pause() function for Maxima that works in a similar way to MATLAB. It uses Maxima’s read() to stop everything and wait for user input, and it uses the lisp function sleep to stop for a fixed number of seconds.
**note that a lisp function
can be called inside Maxima as
I’m not happy that in order to resume after the pause, the user needs to enter a valid character (space or nothing results in an error) followed by CTRL-SHIFT. I hope to either figure something else out or even better hear suggestions from other Maxima users!
if tsecs=0 then
read("Execution Paused...enter any character then CTRL-ENTER")
disp(sconcat("paused for ", tsecs," seconds")),
call this either as
or, for a three second pause
**Update** I didn’t find it it in documentation for quite a while, but there is a built-in Maxima function matrix_size() in the package linearalgebra that does what this little one-liner does**
I really wanted a Maxima function that works something like MATLAB size() to easily determine the number of rows and columns for a matrix In Maxima, length(M) gives the number of rows, and so length(transpose(M)) gives the number of columns. I put those together in a little widget matsize() that returns the list [m,n] for an matrix