% positive part
>> P=[1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0;
1, 1, 0, 1, 0, 0, 0, 1, 1, 1, 0, 1;
1, 1, 1, 0, 1, 0, 0, 0, 1, 1, 1, 0; 
1, 0, 1, 1, 0, 1, 0, 0, 0, 1, 1, 1; 
1, 1, 0, 1, 1, 0, 1, 0, 0, 0, 1, 1; 
1, 1, 1, 0, 1, 1, 0, 1, 0, 0, 0, 1; 
1, 1, 1, 1, 0, 1, 1, 0, 1, 0, 0, 0; 
1, 0, 1, 1, 1, 0, 1, 1, 0, 1, 0, 0; 
1, 0, 0, 1, 1, 1, 0, 1, 1, 0, 1, 0; 
1, 0, 0, 0, 1, 1, 1, 0, 1, 1, 0, 1; 
1, 1, 0, 0, 0, 1, 1, 1, 0, 1, 1, 0; 
1, 0, 1, 0, 0, 0, 1, 1, 1, 0, 1, 1]; 

% negative part
>> N = [0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1;
0, 0, 1, 0, 1, 1, 1, 0, 0, 0, 1, 0;
0, 0, 0, 1, 0, 1, 1, 1, 0, 0, 0, 1;
0, 1, 0, 0, 1, 0, 1, 1, 1, 0, 0, 0;
0, 0, 1, 0, 0, 1, 0, 1, 1, 1, 0, 0;
0, 0, 0, 1, 0, 0, 1, 0, 1, 1, 1, 0;
0, 0, 0, 0, 1, 0, 0, 1, 0, 1, 1, 1;
0, 1, 0, 0, 0, 1, 0, 0, 1, 0, 1, 1;
0, 1, 1, 0, 0, 0, 1, 0, 0, 1, 0, 1;
0, 1, 1, 1, 0, 0, 0, 1, 0, 0, 1, 0;
0, 0, 1, 1, 1, 0, 0, 0, 1, 0, 0, 1;
0, 1, 0, 1, 1, 1, 0, 0, 0, 1, 0, 0];

% zero matrix
>> Z = zeros(size(N)(1));

% an signed adjacency matrix of a complete bipartite graph
>> H = [Z, P-N; P'-N', Z];

% eigenvalues of a signed adjacency matrix
>> eig(H)
ans =

  -3.4641
  -3.4641
  -3.4641
  -3.4641
  -3.4641
  -3.4641
  -3.4641
  -3.4641
  -3.4641
  -3.4641
  -3.4641
  -3.4641
   3.4641
   3.4641
   3.4641
   3.4641
   3.4641
   3.4641
   3.4641
   3.4641
   3.4641
   3.4641
   3.4641
   3.4641

% check that it's a sqrt(12)
>> 3.4641^2
ans =  12.000

% the leading principal sub-matrix of size 12
>> A12 = eig(H(1:12, 1:12)), size(A12)
A12 =

   0
   0
   0
   0
   0
   0
   0
   0
   0
   0
   0
   0

ans =

   12    1

% the leading principal sub-matrix of size 13
>> A13 = eig(H(1:13, 1:13)), size(A13)
A13 =

  -3.46410
   0.00000
   0.00000
   0.00000
   0.00000
   0.00000
   0.00000
   0.00000
   0.00000
   0.00000
   0.00000
   0.00000
   3.46410

ans =

   13    1

% the leading principal sub-matrix of size 14
>> A14 = eig(H(1:14, 1:14)), size(A14)
A14 =

  -3.4641e+00
  -3.4641e+00
  -2.2869e-16
  -5.1835e-17
  -3.1072e-32
  -9.8437e-33
  -9.1270e-34
  -1.6678e-48
   6.7204e-34
   2.6380e-33
   5.5511e-17
   1.0011e-16
   3.4641e+00
   3.4641e+00

ans =

   14    1

% the leading principal sub-matrix of size 15
>> A15 = eig(H(1:15, 1:15)), size(A15)
A15 =

  -3.4641e+00
  -3.4641e+00
  -3.4641e+00
  -1.2569e-16
  -5.2487e-17
  -2.7846e-17
   8.3967e-19
   2.9178e-17
   1.3011e-16
   2.6577e-16
   6.1994e-16
   7.9764e-16
   3.4641e+00
   3.4641e+00
   3.4641e+00

ans =

   15    1

% the leading principal sub-matrix of size 16
>> A16 = eig(H(1:16, 1:16)), size(A16)
A16 =

  -3.4641e+00
  -3.4641e+00
  -3.4641e+00
  -3.4641e+00
  -4.8088e-16
  -3.2142e-16
  -1.4036e-16
   1.4234e-17
   1.1284e-16
   2.6229e-16
   4.1426e-16
   4.6066e-16
   3.4641e+00
   3.4641e+00
   3.4641e+00
   3.4641e+00

ans =

   16    1
Comments Off on Lifts, eigenvalues and Hadamard matrices
#!/usr/bin/env python

class Fibo:
	"Class-based Fibonacci recursion"
	def __init__(self, n):
		if n == 1:
			self.value = 1
		elif n == 2:
			self.value = 1
		else:
			A = Fibo(n-1)
			B = Fibo(n-2)
			self.value = A.value + B.value
	def __repr__(self):
		return str(self.value)

if __name__ == "__main__":
	print Fibo(1)
	print Fibo(2)
	print Fibo(3)
	print Fibo(4)
	print Fibo(5)
	print Fibo(6)
	print Fibo(7)
	print Fibo(8)
	print Fibo(9)
	print Fibo(10)
Comments Off on Fibonacci Recursion implemented by Python class
>> A=[1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0;
1, 1, 0, 1, 0, 0, 0, 1, 1, 1, 0, 1;
1, 1, 1, 0, 1, 0, 0, 0, 1, 1, 1, 0; 
1, 0, 1, 1, 0, 1, 0, 0, 0, 1, 1, 1; 
1, 1, 0, 1, 1, 0, 1, 0, 0, 0, 1, 1; 
1, 1, 1, 0, 1, 1, 0, 1, 0, 0, 0, 1; 
1, 1, 1, 1, 0, 1, 1, 0, 1, 0, 0, 0; 
1, 0, 1, 1, 1, 0, 1, 1, 0, 1, 0, 0; 
1, 0, 0, 1, 1, 1, 0, 1, 1, 0, 1, 0; 
1, 0, 0, 0, 1, 1, 1, 0, 1, 1, 0, 1; 
1, 1, 0, 0, 0, 1, 1, 1, 0, 1, 1, 0; 
1, 0, 1, 0, 0, 0, 1, 1, 1, 0, 1, 1]; 

>> B = [0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1;
0, 0, 1, 0, 1, 1, 1, 0, 0, 0, 1, 0;
0, 0, 0, 1, 0, 1, 1, 1, 0, 0, 0, 1;
0, 1, 0, 0, 1, 0, 1, 1, 1, 0, 0, 0;
0, 0, 1, 0, 0, 1, 0, 1, 1, 1, 0, 0;
0, 0, 0, 1, 0, 0, 1, 0, 1, 1, 1, 0;
0, 0, 0, 0, 1, 0, 0, 1, 0, 1, 1, 1;
0, 1, 0, 0, 0, 1, 0, 0, 1, 0, 1, 1;
0, 1, 1, 0, 0, 0, 1, 0, 0, 1, 0, 1;
0, 1, 1, 1, 0, 0, 0, 1, 0, 0, 1, 0;
0, 0, 1, 1, 1, 0, 0, 0, 1, 0, 0, 1;
0, 1, 0, 1, 1, 1, 0, 0, 0, 1, 0, 0;]

>> G = [Z A Z B;A' Z B' Z;Z B Z A;B' Z A' Z];

>> eig(G)

ans =

  -12.0000
   -3.4641
   -3.4641
   -3.4641
   -3.4641
   -3.4641
   -3.4641
   -3.4641
   -3.4641
   -3.4641
   -3.4641
   -3.4641
   -3.4641
   -0.0000
   -0.0000
   -0.0000
   -0.0000
   -0.0000
   -0.0000
   -0.0000
   -0.0000
   -0.0000
   -0.0000
    0.0000
    0.0000
    0.0000
    0.0000
    0.0000
    0.0000
    0.0000
    0.0000
    0.0000
    0.0000
    0.0000
    0.0000
    3.4641
    3.4641
    3.4641
    3.4641
    3.4641
    3.4641
    3.4641
    3.4641
    3.4641
    3.4641
    3.4641
    3.4641
   12.0000

>> % 3.4641^2 = 12
>> A = [1 1 1 1; 1 1 0 0;1 0 1 0; 1 0 0 1];
>> B = [0 0 0 0; 0 0 1 1;0 1 0 1; 0 1 1 0];

>> (A-B)*(A-B)'

ans =

     4     0     0     0
     0     4     0     0
     0     0     4     0
     0     0     0     4

>> >> G = [Z A Z B;A' Z B' Z;Z B Z A;B' Z A' Z];

>> eig(G)

ans =

   -4.0000
   -2.0000
   -2.0000
   -2.0000
   -2.0000
   -0.0000
   -0.0000
   -0.0000
    0.0000
    0.0000
    0.0000
    2.0000
    2.0000
    2.0000
    2.0000
    4.0000
Comments Off on Spectrum of Hadamard Graphs

doc

\documentclass{article}

\usepackage[papersize={5.2in, 1.6in}, text={5in, 1.4in}]{geometry}

% for choosing the proper font encoding
\usepackage[T1]{fontenc}
% for proper encoding
\usepackage[utf8]{inputenc}
% enhanced font Latin Modern
\usepackage{lmodern}
% multi-language support
\usepackage[english]{babel}
% for inline and display quotations.
\usepackage[autostyle]{csquotes}

\usepackage{doi}
\usepackage[ocgcolorlinks,pdfusetitle]{hyperref}
\usepackage[
  backend=biber,
  style=alphabetic,
  citestyle=alphabetic,
  backref=true]{biblatex}

%%%
\usepackage{filecontents}  
\begin{filecontents}{bib.bib}
@article{black1973,
  author = {Black, Fishcer and Scholes, Myron},
  doi = {10.1086/260062},
  journal = {Journal of political economy},
  number = 3,
  pages = {637--654},
  publisher = {UChicago Press},
  title = {The pricing of options and corporate liabilities},
  volume = 81,
  year = 1973
}
\end{filecontents}

\addbibresource{bib.bib}

\begin{document}
Lorem ipsum dolor sit amet, consectetuer adipiscing elit
\cite{black1973}.
Ut purus elit, vestibulum ut, placerat ac, adipiscing vitae, felis.

\printbibliography

\end{document}
Comments Off on BibLaTeX + backref + biber + doi

test

\documentclass[10pt]{article}

% for smallper page
\usepackage[papersize={4.2in, 1.4in}, text={4in, 1.3in}]{geometry}
% for fancy math
\usepackage{amsmath}

% rank operator
\DeclareMathOperator*{\rank}{rank}

% Matrix transpose
\newcommand{\trans}[1]{\ensuremath{{#1}^\top}}

% for extra space at the end of abbreviation
\usepackage{xspace}

% positive semi-definite
\newcommand{\psd}{\textsc{psd}\xspace}

% boldface uppercase letters for matrices
\newcommand{\Abf}{\ensuremath{\mathbf A}}
\newcommand{\Bbf}{\ensuremath{\mathbf B}}

% boldface lowercase letters for vectors
\newcommand{\xbf}{\ensuremath{\mathbf x}}

% for math blackboard font
\usepackage{amssymb}
% set of real numbers
\newcommand{\Rbb}{\ensuremath{\mathbb R}}

\usepackage{palatino}
\usepackage[sc]{mathpazo}

\begin{document}
\noindent
For any real symmetric matrcies $\Abf$ such that $\rank(\Abf_{n\times n})=r$,
the following statements are equivalent
and any one of them can serve as the definition of
\emph{positive semi-definite} (\psd) matrices.
\begin{itemize}
  \item $\trans\xbf \Abf\xbf \geq 0$ for any non-zero vector
    $\xbf\in\Rbb^{n\times 1}$.
    \hfill\refstepcounter{equation}\textup{(\theequation)}%
  \item All the $n$ eigenvalues of $\Abf$ are non-negative.
    \hfill\refstepcounter{equation}\textup{(\theequation)}%
  \item $\Abf=\trans\Bbf \Bbf$ for some $\Bbf$ with $\rank(\Bbf)=r$.
    \hfill\refstepcounter{equation}\textup{(\theequation)}%
\end{itemize}

\end{document}
Comments Off on Equation numbering in itemized list

doc

\documentclass{beamer}
\usepackage{hyperref}
\setbeamertemplate{theorems}[numbered]
\usetheme{CambridgeUS}

\begin{document}
\begin{frame}
  \frametitle{Test}
  \begin{theorem}[Fermat's Last Theorem]
    $x^n + y^n = z^n$.
    \label{thm:fermat}
  \end{theorem}
  As shown in Theorem \ref{thm:fermat}...

  \begin{example}
    Here goes an example!
  \end{example}

  \begin{theorem}
    $e^{i\pi} + 1 = 0$
  \end{theorem}

  \begin{corollary}
    Corollary!
  \end{corollary}
\end{frame}

\end{document}
Comments Off on Beamer theorem numbering

boldface

\documentclass{minimal}
% for smallper page
\usepackage[papersize={2.6in, 1.2in}, text={2.6in, 1.2in}]{geometry}
% for fancy math
\usepackage{amsmath}

% Greek letter lowercase boldface
\newcommand{\alphabf}{\ensuremath{\boldsymbol{\alpha}}}
\newcommand{\betabf}{\ensuremath{\boldsymbol{\beta}}}
\newcommand{\gammabf}{\ensuremath{\boldsymbol{\gamma}}}
\newcommand{\deltabf}{\ensuremath{\boldsymbol{\delta}}}
\newcommand{\epsbf}{\ensuremath{\boldsymbol{\epsilon}}}
\newcommand{\epsilonbf}{\ensuremath{\boldsymbol{\epsilon}}}
\newcommand{\zetabf}{\ensuremath{\boldsymbol{\zeta}}}
\newcommand{\etabf}{\ensuremath{\boldsymbol{\eta}}}
\newcommand{\thetabf}{\ensuremath{\boldsymbol{\theta}}}
\newcommand{\iotabf}{\ensuremath{\boldsymbol{\iota}}}
\newcommand{\kappabf}{\ensuremath{\boldsymbol{\kappa}}}
\newcommand{\lambdabf}{\ensuremath{\boldsymbol{\lambda}}}
\newcommand{\mubf}{\ensuremath{\boldsymbol{\mu}}}
\newcommand{\nubf}{\ensuremath{\boldsymbol{\nu}}}
\newcommand{\xibf}{\ensuremath{\boldsymbol{\xi}}}
\newcommand{\pibf}{\ensuremath{\boldsymbol{\pi}}}
\newcommand{\rhobf}{\ensuremath{\boldsymbol{\rho}}}
\newcommand{\sigmabf}{\ensuremath{\boldsymbol{\sigma}}}
\newcommand{\taubf}{\ensuremath{\boldsymbol{\tau}}}
\newcommand{\upsilonbf}{\ensuremath{\boldsymbol{\upsilon}}}
\newcommand{\phibf}{\ensuremath{\boldsymbol{\phi}}}
\newcommand{\chibf}{\ensuremath{\boldsymbol{\chi}}}
\newcommand{\psibf}{\ensuremath{\boldsymbol{\psi}}}
\newcommand{\omegabf}{\ensuremath{\boldsymbol{\omega}}}

% Greek letter uppercase boldface
\newcommand{\Gammabf}{\ensuremath{\boldsymbol{\Gamma}}}
\newcommand{\Deltabf}{\ensuremath{\boldsymbol{\Delta}}}
\newcommand{\Thetabf}{\ensuremath{\boldsymbol{\Theta}}}
\newcommand{\Lambdabf}{\ensuremath{\boldsymbol{\Lambda}}}
\newcommand{\Xibf}{\ensuremath{\boldsymbol{\Xi}}}
\newcommand{\Pibf}{\ensuremath{\boldsymbol{\Pi}}}
\newcommand{\Sigmabf}{\ensuremath{\boldsymbol{\Sigma}}}
\newcommand{\Upsilonbf}{\ensuremath{\boldsymbol{\Upsilon}}}
\newcommand{\Phibf}{\ensuremath{\boldsymbol{\Phi}}}
\newcommand{\Psibf}{\ensuremath{\boldsymbol{\Psi}}}
\newcommand{\Omegabf}{\ensuremath{\boldsymbol{\Omega}}}

\begin{document}
\begin{equation*}
\alphabf
\betabf
\gammabf
\deltabf
\epsbf
\epsilonbf
\zetabf
\etabf
\thetabf
\iotabf
\kappabf
\lambdabf
\mubf
\nubf
\xibf
\pibf
\rhobf
\sigmabf
\taubf
\upsilonbf
\phibf
\chibf
\psibf
\omegabf
\end{equation*}

\begin{equation*}
\Gammabf
\Deltabf
\Thetabf
\Lambdabf
\Xibf
\Pibf
\Sigmabf
\Upsilonbf
\Phibf
\Psibf
\Omegabf
\end{equation*}
\end{document}
Comments Off on Math Greek Letters Boldface

dante

\documentclass{article}

\usepackage[papersize={80mm, 80mm}, text={75mm, 70mm}]{geometry}

\usepackage{verse}
\newcommand{\attrib}[1]{\nopagebreak{\raggedleft\footnotesize #1\par}}

\usepackage{fontspec,xltxtra}
\newcommand{\old}[1]{%
  \fontspec[Alternate=1,Ligatures={Common,Rare}]%
  {Hoefler Text}\fontsize{12pt}{12pt}\selectfont #1}%

\begin{document}
\thispagestyle{empty}

\old
\itshape
\settowidth{\versewidth}{Ahi quanto a dir qual era \`e cosa dura}
\begin{verse}[\versewidth]
Nel mezzo del cammin di nostra vita \\
mi ritrovai per una selva oscura, \\
ch\'e la diritta via era smarrita. \\
\vspace{3mm}

Ahi quanto a dir qual era \`e cosa dura \\
esta selva selvaggia e aspra e forte \\
che nel pensier rinova la paura! \\
\vspace{3mm}

Tant'\`e amara che poco \`e pi\`u morte; \\
ma per trattar del ben ch'i' vi trovai, \\
dir\`o de l'altre cose ch'i' v'ho scorte. \\
\end{verse}
\attrib{\textit{Divina Commedia, Inferno, Canto I, 1-9}}
\attrib{Dante Alighieri}
\end{document}
Comments Off on Divina Commedia, Inferno, Canto I, 1-9

compressed.sensing

\documentclass{standalone}

\usepackage{tikz}

\begin{document}
  \begin{tikzpicture}
    \tikzstyle{abox} = [rectangle, thick, text centered ,
    text width=3.5cm, minimum height=1cm,
    top color=white, bottom color=blue!30, draw=blue!40]
    \tikzstyle{xbox} = [rectangle, thick, text centered ,
    text width=.3cm, minimum height=3.5cm,
    top color=white, bottom color=red!30, draw=red!40]
    \tikzstyle{bbox} = [rectangle, thick, text centered ,
    text width=.3cm, minimum height=1cm,
    top color=white, bottom color=green!30, draw=green!40]
    
    \coordinate (A) at (0cm, 0cm);
    \coordinate (X) at (3cm, 0cm);
    \coordinate (E) at (4cm, 0cm);
    \coordinate (B) at (5.2cm, 0cm);

    % measurement
    \node [abox] (ABox) at (A) {$\mathbf{A}$};
    \node [left]  at (ABox.west)  {$\scriptstyle m$};
    \node [below] at (ABox.south) {$\scriptstyle n$};
    \node [yshift=-2.5cm] at (A) {measurement};

    % input
    \node [xbox] (XBox) at (X) {$\mathbf{x}$};
    \node [left]  at (XBox.west)  {$\scriptstyle n$};
    \node [below] at (XBox.south) {$\scriptstyle 1$};
    \node [yshift=-2.5cm] at (X) {input};

    % equal
    \node at (E) {=};

    % observation
    \node [bbox] (BBox) at (B) {$\mathbf{b}$};
    \node [left]  at (BBox.west)  {$\scriptstyle m$};
    \node [below] at (BBox.south) {$\scriptstyle 1$};
    \node [yshift=-2.5cm] at (B) {observation};
  \end{tikzpicture}
\end{document}
Comments Off on Compressed Sensing

matrix

\documentclass[12pt]{article}

\usepackage[papersize={35mm, 45mm}, text={30mm, 40mm}]{geometry}
\usepackage{concrete}
\usepackage{amsmath}

\DeclareMathOperator*{\AAbf}{\ensuremath{\mathbf{A}}}
\DeclareMathOperator*{\xxbf}{\ensuremath{\mathbf{x}}}
\DeclareMathOperator*{\bbbf}{\ensuremath{\mathbf{b}}}

\begin{document}
\begin{equation*}
\AAbf_{\scriptscriptstyle m\times n} \medspace
\xxbf_{\scriptscriptstyle n\times 1} =
\bbbf_{\scriptscriptstyle m\times 1}
\end{equation*}

\begin{equation*}
\AAbf_{m\times n} \medspace
\xxbf_{n\times 1} =
\bbbf_{m\times 1}
\end{equation*}

\end{document}
Comments Off on LaTeX Matrix with dimensions