## Wednesday, January 30, 2013

### "Handwrite" LaTeX Equations

I've been a big fan and user of deTeXify, which recognizes handwritten symbols and spits out the appropriate LaTeX tags.

Now, this site takes it one step further (via Ramanan on Facebook). You can write entire equations by hand; the program produces LaTeX (and MathML if needed) markup for the whole enchilada.

## Friday, January 25, 2013

### Correlation and Causation

Saw this funny chart on FlowingData:

which reminded me of "Correlation with causation = science; correlation without causation = superstition."

Here are some more correlation-causation comics.

## Thursday, January 24, 2013

### A TikZ video

TikZ is among the newer toys (new as in "new to me") I have been playing with since the summer of last year.

Here is a video which demonstrates the use of some nice TikZ libraries

## Friday, January 18, 2013

### Molecular Weight Distributions and Size Exclusion Chromatography: Part 2

This is a followup to this post.

In this post, I thought I'd illustrate how a particular distribution looks like when seen through different lenses: N(M), W(M), and w(log M). For concreteness, let us pick a particular generalized exponential function (GEX), which can model a wide variety of empirical distributions as W(M):

$W(M) = \frac{m t^{\frac{k+1}{m}}}{\Gamma \left(\frac{k+1}{m}\right)} M^k e^{-t M^m}$

with m = 0.5, k = 1.5, and t = 0.005.

 Blue Curve is W(M) and Red Curve is N(M)
I can get N(M) by considering N(M) = W(M)/M and figuring out the normalization constant. Here, it turns out to be:

$N(M) = \frac{m t^{k/m}}{\Gamma \left(\frac{k}{m}\right)} M^{k-1}e^{-t M^m}$

It is biased towards smaller molecular weights. In this particular example, the number-averaged and weight-averaged molecular weights turn out to be 480K and 1.2M, respectively. Also note that the numbers on the y-axis are "smallish". This is forced by the normalization constraint,

$\int_{0}^{\infty} N(M) dM = \int_{0}^{\infty} W(M) dM = 1,$

since the numbers on the x-axis are largish.

We take the W(M) curve and multiply it by 2.303 * M to get w(log M). On the x-axis we plot log M, as:

## Wednesday, January 16, 2013

### Compile Programs in a Browser

IDEOne is a nice IDE for compiling short code fragments in a variety of languages.

I like it, because one of the classes I teach this semester (applied computational science) is language-agnostic, and I have people using all sorts of languages and dialects. This may potentially allow me grade homework easily.

Check it out.

## Friday, January 11, 2013

### writeLaTeX: Compile LaTeX in a Browser and Collaborate

Just found out about writeLaTeX (via TeXBlog), which lets you write LaTeX "code" and compile it without requiring any software download. The best part is that it is collaborative, which means that multiple people can work on the same document seamlessly.

• Effortless Sharing – Every document you create has a secret link. Just send it to your co-authors, and they can review, comment and edit.
• Create Beautiful Documents Together – writeLaTeX synchronizes changes from all authors transparently, so everyone always has the latest version.
• Not Just Papers – Make amazing presentations with the beamer package! The preview helps with complicated tables, figures and graphs.
• Real-time Preview – writeLaTeX compiles your document in the background, so you can see the results right away – great for learning quickly!
• Find Errors Fast – writeLaTeX shows you errors & warnings as you go, so you can catch them early, and you don't have to find them in the LaTeX log.
• LaTeX in the Cloud – Edit online from anywhere and on any device. There's no software to install, and no sign-up required.
Sounds exciting!

## Wednesday, January 9, 2013

### Molecular Weight Distributions and Size Exclusion Chromatography: Part 1

Size Exclusion Chromatography (SEC) is a commonly used technique to separate molecules dissolved in a solvent on the basis of their size. A sample containing molecules of various sizes is injected at one end of a special SEC column, and monitored at the other end using one or more special detectors.

As an analogy it is useful to think of the column as an obstacle course (a 110 meter hurdle race). Somewhat counter-intuitively, the big fat molecules finish  first, and the small nimble ones finish last. The reason why this happens is the same reason why the tortoise finished first. Despite being slower, he did not pause to examine and explore each nook and cranny.

You can imagine that SEC is a popular technique to get the molecular weight distribution (MWD) of polydisperse polymers. Because of the way in which the calibration process and detectors work, the resulting MWD is usually reported in a somewhat "funky units" of w(log M) versus log M, which looks something like the following.
Note 1: The area under the curve, as reported, is unity.
Note 2: Throughout this discussion, "log" refers to log-base-10, and "ln" refers to log-base-e. In SEC it is more common to use base-10, although as I will show shortly, base-e is more "natural".

Okay, so how is the SEC MWD w(log M) related to quantities we know better such as the number distribution N(M) and the weight distribution W(M)?

To recap, N(M) dM tells us the fraction of molecules with molecular weight between M and M+dM, and W(M) dM tells us the weight fraction of the molecules with molecular weight between M and M+dM. These distributions are normalized which means,

$\int_{0}^{\infty} N(M) dM = \int_{0}^{\infty} W(M) dM = 1$

The first moments of N(M) and W(M) are the number-averaged and weight-averaged molecular weights.

$M_n = \int_{0}^{\infty} M N(M) dM$
$M_w = \int_{0}^{\infty} M W(M) dM$

As you know or expect, N(M) and W(M) contain the same information, and they can be transformed into one other.

$W(M) = \frac{M N(M)}{\int_{0}^{\infty} M N(M) dM} = \frac{M N(M)}{M_n}$

The integral in the denominator ensures the normalization of W(M). The brother of the SEC MWD w(log M) turns out to be closely related to the "next moment"

$w(\ln M) \propto M W(M),$

except that it's normalization is not

$\int w(\ln M) dM = 1,$

but rather,

$\int_{0}^{\infty} w(\ln M) d \ln M = 1.$

This is automatically satisfied for w(ln M) = M W(M), since

$\int_{0}^{\infty} w(\ln M) d \ln M = \int_{0}^{\infty} M W(M) \frac{dM}{M} = \int_{0}^{\infty} W(M) dM.$

What about w(log M)? Aren't we more interested in that whole shebang?

Sure, no problem. We will find out that w(log M) and w(ln M) are just a constant (2.303) apart.

$w(\log M) = c M W(M),$

where c is a constant, and work backwards from the normalization (as in the plot above!)

$\int_{0}^{\infty} w(\log M) d \log M = 1.$

This implies

$\int_{0}^{\infty} c M W(M) \frac{dM}{2.303 M} = 1.$

This implies c = 2.303, and w(log M) = 2.303 w(ln M) = 2.303 M W(M).

We will apply this to a particular problem in the next post.

## Monday, January 7, 2013

### TeX Directory Structure or Where to Install Packages?

If you are a regular TeX user, there are many good reasons to understand and exploit the TeX directory structure (TDS). Let me offer some:

• You download a package from CTAN (or somewhere else). This could be a style file, for example. Is there some central place you could put it, so that it is in the "path" (so that you can avoid making multiple copies of the same style file in all your working directories)?
• You make a bibliography style file to suit a journal's requirements (using custom-bib). Can you put this in the "same" central place?
• You have a bibliography (bib) file with all your references. Can you put this in the path too? And can you do that without completely cluttering that central place?
• You have an account that is administered by a university or department, and the TeX installation is common to all users. Can you make sure that the .sty, .bst, .bib files that we talked about above do not get wiped off, when the systems administrator decides to upgrade the TeX installation?

If you use TDS, the answer is yes. The good news is that this works independent of the OS platform.

The first thing is to find out where this place is. You can do that by simply typing the following in a terminal.

kpsewhich -var-value=TEXMFHOME

On my Mac this is ~/Library/texmf, and on my Linux desktop it is ~/texmf.

If such a directory does not already exist, you can create it (mkdir texmf) at the above location. You then make sub-directories. The important ones are:

bibtex directory
- bst sub-directory (put bst files here)
- bib sub-directory (put bib files here)
tex directory
- latex sub-directory (put packages here)
doc directory
put doc files from packages installed in the tex directory here.

You can make further sub-directories.

For example, you can make a "tools" directory within texmf/tex/latex/tools and put, for example, the tools package files here (tex and sty), and move the corresponding doc files to the texmf/doc folder.

In newer systems you don't even have to run texhash or mktexlsr to "update" the path if you do this.

## Thursday, January 3, 2013

1. Where multiplication and division is the same (via Wild About Math).

2. Let me Google that for you. As an example let me google "Florida State University" for you.

3. Jared Diamond on the controversial topic of "Best practices for raising kids..."

4. Beautiful microscopy pictures (I don't know if they are scientifically important). And while we are talking pictures, here are some awesome animal pictures.

### Numerical Differentiation using Mathematica: Redux

While I was demonstrating this Mathematica script in class, I noticed there was an obvious error that had escaped into the wild. In particular, when I tried to get the center-difference approximation to the second derivative via AppDeriv[3, 2], I got the following:

Notice the "zero" truncation error for the second formula. That should have tipped me off (if I had done any testing, duh). The other errors are also incorrect. It can be fixed relatively easily by the following code.

AppDeriv[m_, n_] := Module[{points, IP, nthDeriv, e1},
points = Table[{x0 + i h, Subscript[f, i]}, {i, 0, m - 1}];
IP = InterpolatingPolynomial[points, x];
nthDeriv = D[IP, {x, n}];
e1 = D[F[X[x]]* Apply[Times,
(x - Table[{x0 + i h}, {i, 0, m - 1}])], {x, n}];
Formula = TableForm[
Table[{Subsuperscript[f, i, n], nthDeriv /. x -> (x0 + i h),
O Superscript[h, Exponent[e1[[1]] /.
x -> (x0 + i h), h]]}, {i,0, m - 1}] // Simplify ]]

Here is my Mathematica screenshot with the new code. It at least seems to fix the problem above.