Import big files/arrays with mathematica

For some reason, the current implementation of Import for the type Table (tabular data) is quite memory – inefficient. Below I’ve made an attempt to remedy this situation somewhat, while still reusing Mathematica’s high-level importing capabilities (through ImportString). For sparse tables, a separate solution is presented, which can lead to very significant memory savings. General … Read more

How do I label different curves in Mathematica?

There’s some nice code that allows you to do this dynamically in an answer to How to annotate multiple datasets in ListPlots. There’s also a LabelPlot command defined in the Technical Note Labeling Curves in Plots Of course, if you don’t have too many images to make, then it’s not hard to manually add the … Read more

Mathematica: How to clear the cache for a symbol, i.e. Unset pattern-free DownValues

I’ve made similar functions in the past (but I can’t remember where). Does the following code do all that you need? ClearCache[f_] := DownValues[f] = DeleteCases[DownValues[f], _?(FreeQ[First[#], Pattern] &)] This maybe should be extended to UpValues and SubValues. And the Head of f restricted to Symbol.

Plot using With versus Plot using Block (Mathematica)

Your question is not so much about Plot as it is about how the scoping constructs work. The main confusion here is due to the differences between lexical and dynamic scoping. And the main culprit is this definition: f[x_] := (vmax x)/(km + x) The problem with it is that it makes f implicitly depend … Read more

The best way to construct a function with memory

Let’s assume our slow function has the signature f[x, y]. Pure In-memory Approach If you are satisfied with an in-memory cache, the simplest thing to do would be to use memoization: Clear@fmem fmem[x_, y_] := fmem[x, y] = f[x, y] This adds a definition to itself every time it is called with a combination of … Read more

Preventing avalanche of runtime errors in Mathematica

As others have pointed out, there are three ways to deal with errors in a consistent manner: correctly typing parameters and setting up conditions under which your functions will run, dealing correctly and consistently with errors generated, and simplifying your methodology to apply these steps. As Samsdram pointed out, correctly typing your functions will help … Read more

Customizing Mathematica shortcuts

Here is a nice article. Also, FROM HERE (unchecked) Question: How do I modify the front end to add new keyboard shortcuts? Answer: (mathgroup May 2005, trevor baca:) I’ve been mucking around in KeyEventTranslations.tr setting up keyboard shortcuts recently and i’ve learned that front end tokens are pretty cool. this wolfram page gives pretty good … Read more