# Setting Variables Element-wise in a Matrix in Mathematica

#### February 2 2016 in Mathematica, Programming | Tags: | Author: Christopher Rackauckas

This is the latest entry on tip, tricks, and hacks in Mathematica. In my latest problem I need to solve for the components of many matrices using optimization algorithms. Mathematica does not allow one to straight pass matrices into the algorithms, so one has to perform the algorithms on variables that stand in for the components. This is what I did with the matrix , solving for . That was all fine and dandy until I needed to set some of those matrices to constants. I could do a bunch of set commands all lined up, i.e.

A011 = 2; A021 = 1.4; ...

But that would be inelegant and hard to ... READ MORE

# Simple Parallel Optimization in Mathematica

#### February 2 2016 in Mathematica | Tags: optimization, parallel | Author: Christopher Rackauckas

A quick search on Google did not get hits for a standard method of parallelizing NMaximize and NMinimize, so I wanted to share how I did it.

My implementation is a simple use of a Map-Reduce type of parallelism. What this means is that we map the same problem out to N many processes, and when they finish they each give one result, and we apply a reduction function to reduce the N results to 1. So what we will do is map the NMaximize function to each of N cores, where they will each solve it on a random seed. From there, each process will return what it found as the minimum, and we will take the minimum of these minimums as our best estimate of the global minimums.

Notice that this is not optimal in all cases: for ... READ MORE

# Why is Mathematica Stopping My Long Calculation?

#### January 30 2016 in Mathematica, Programming | Tags: | Author: Christopher Rackauckas

You set it all up, you know it's going to take a few days, and you run it. You check it a few hours later, it's all good! The next morning... there are no cells computing still?

Mathematica's documentation isn't that helpful for what just happened. If you were using a function like FullSimplify, there are time limits on it. However, it will give you an error/warning if it hits the time limit, so if you ended up with a blank screen with no calculations, that's not it.

This happened to me. I found out that the hidden culprit (for me) was Mathematica's history tracking. The fix is simple, add the following code to the top of your file:

$HistoryLength = 10;

What's happening is that Mathematica saves its entire command history by default. This is ... READ MORE