## Archive for August, 2016

### (Slightly) Faster way to compute number of unique elements in matlab matrix

Wednesday, August 31st, 2016

The standard way to compute the number of unique entries in a matlab matrix A is:

numel(unique(A))


If our entries are positive integers, we can try to do the same thing using sparse with:

nnz(sparse(A(:),1,1,size(A,1),1))


but actually this is slower.

I don’t see a way to avoid a sort. I came up with this,

sum(diff(sort(F(:)))~=0)+1


As far as I can tell, this will work for matrices that don’t have infs and nans. It’s slightly faster than number(unique(A)). I have a feeling I’m only winning anything here because I’m avoiding overhead within unique

### Eitan Grinspun’s “How to host a visit”

Thursday, August 25th, 2016

Eitan has prepared a google doc on hosting visitors to the lab that I find very useful. It contains a detailed list (some unique to Columbia) of things you should do to host a visitor and when you should do them.

### Real-time LaTeX in browser

Tuesday, August 23rd, 2016

A long time ago, I made a little web app that allowed you to submit Latex code to a server, the server would run pdflatex and then send back the pdf to be rendered on the page.

Nowadays MathJax can render LaTeX equations in the browser. I found http://www.texrendr.com that let’s you interactively write formulae, but it’s restricted to a single equation. There’s also the LaTeXit standalone app, but you have to keep hitting “typeset”. This isn’t so useful if you’re trying to quickly type math during a Skype call.

So I wrote a little program to run in the browser:

http://www.cs.toronto.edu/~jacobson/latex.html

You can also fork the git gist

### option click on volume menu bar item to change sound devices

Friday, August 19th, 2016

I find myself often switching the microphone and speaker devices on my mac. I usually go all the way through System Preferences > Sound, but I stumbled upon a much faster route.

Normally if you click on the volume menu item at the top of the screen you get a little volume slider:

If you hold OPTION while you click you see a device selection menu:

### Energy optimization, calculus of variations, Euler Lagrange equations in Maple

Tuesday, August 16th, 2016

Here’s a simple demonstration of how to solve an energy functional optimization symbolically using Maple.

Suppose we’d like to minimize the 1D Dirichlet energy over the unit line segment:

min  1/2 * f'(t)^2
f
subject to: f(0) = 0, f(1) = 1


we know that the solution is given by solving the differential equation:

f''(t) = 0, f(0) = 0, f(1) = 1


and we know that solution to be

f(t) = t


How do we go about verifying this in Maple:

with(VariationalCalculus):
E := diff(f(t),t)^2:
L := EulerLagrange(E,t,f(t)):


so far this will output:

        L := {-2*diff(diff(x(t),t),t), -diff(x(t),t)^2 = K[2], 2*diff(x(t),t) = K[1]}


Finally solve with the boundary conditions using:

dsolve({L[1],f(0)=0,f(1)=1});


which will output

         t(t) = t


### Are you using libigl?

Wednesday, August 3rd, 2016

I would love to gather up some information about who out there is using libigl. Drop me a line if you or your university/institution/company is.