Wednesday, January 25, 2012

Making MATLAB figures prettier

Changing the default line style (e.g. for printing in black-and-white):
set(0,'DefaultAxesLineStyleOrder',{'-','--',':'})
set(0,'DefaultAxesColorOrder',[0 0 0])

For dotted lines exported to .eps:
http://www.mathworks.com/matlabcentral/fileexchange/15743-fix-dashed-and-dotted-lines-in-eps-export
Usage:
print -depsc myfigure.eps
fix_dottedline('myfigure.eps')

More to come...

Tuesday, January 17, 2012

Mathematica for MATLAB users

I plan on expanding this post later; for now it's just a place to put this very useful link:

http://meng6.net/pages/matlab_mathematica_equivalent_commands/

Clear all:
ClearAll["Global`*"]

Defining a matrix: A = [1 2 ; 3 4]
A = {{1, 2}, {3, 4}}

This gives you something horrendous:
Integrate[ 1/(x + 1)^2 , {x , y, 1} 
But this gives you the nice expression that you probably wanted:
Simplify[Integrate[ 1/(x + 1)^2 , {x , y, 1} ], {y > 0 , y < 1}]


Wednesday, January 11, 2012

Regex in TextPad

Just spent far too much time trying to figure out regular expressions in TextPad. Here's a good reference:

http://johnbokma.com/textpad/textpad-reference.pdf

The specific things that were holding me up:
  1. Go to Preferences->Editor and check "Use POSIX regular expression syntax" so you don't have to escape your parentheses etc.
  2. Enclose tagged expressions (the things that you'll refer to in your replace string with \1, \2, etc) in parentheses

Latex - more commands

I've been doing 3 problem sets/week in LaTeX for the last several weeks; here are some more tips to follow up on my previous post:

Making your own functions:
\newcommand{\norm}[1]{\left\Vert #1 \right\Vert}
\DeclareMathOperator*{\argmin}{arg\,min}
The * puts the subscript below the operator. To stack subscripts:
\min_{\substack{ X>0 \\ Z \\ W=W^* }}

Different vector formats
Underline, with the line crossing descenders (as in gjpqy):
\usepackage{soul}
\setuldepth{abcdef} % sets ul depth based on letters w/o descenders
\newcommand{\vecu}[1]{\text{\ul{$#1$}}\xspace}
Bold:
\newcommand{\vecb}[1]{\ensuremath{\boldsymbol{#1}}\xspace}
And one more layer of shortcut/indirection (overwrites the caron diacritic)
\renewcommand{\v}[1]{\vect{#1}}

Shortcuts that I've found useful:
\newcommand{\reals}{\ensuremath{\mathbb{R}}\xspace}
\def \ba#1\ea{\begin{align*}#1\end{align*}}
\newcommand{\ii}{^{-1}}
\newcommand{\intii}{\int_{-\infty}^{\infty}}

Matrix formatting
check out these posts from Stefan Kottwitz's excellent TeXblog

A cool trick to turn + - = into alignment marks (e.g. for systems of linear equations)
http://tex.stackexchange.com/questions/6965/multicol-layout-for-systems-of-linear-equations

Cool stuff with figures
http://en.wikibooks.org/wiki/LaTeX/Floats,_Figures_and_Captions

MATLAB code
Get the mcode package, which configures the listings package use with MATLAB. The demo is pretty self-explanatory, and the package works great!

Miscellaneous:

Accent marks:
http://en.wikibooks.org/wiki/LaTeX/Accents

Found this while researching this post and learned a bunch of new things:
http://www.math.uiuc.edu/~hildebr/tex/basics.html
For example, use \eqref to put parentheses around the equation number.

To reduce vertical spacing around section headings: \usepackage[compact]{titlesec}

Cursive lowercase l, as in l2: \ell