From: <jd...@us...> - 2007-10-26 19:44:09
|
Revision: 4022 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=4022&view=rev Author: jdh2358 Date: 2007-10-26 12:44:07 -0700 (Fri, 26 Oct 2007) Log Message: ----------- added some more workbook files Added Paths: ----------- trunk/py4science/workbook/glass_dots.tex trunk/py4science/workbook/intro_linalg.tex trunk/py4science/workbook/intro_sigproc.tex Added: trunk/py4science/workbook/glass_dots.tex =================================================================== --- trunk/py4science/workbook/glass_dots.tex (rev 0) +++ trunk/py4science/workbook/glass_dots.tex 2007-10-26 19:44:07 UTC (rev 4022) @@ -0,0 +1,52 @@ +\section{Glass Moir\'e Patterns} +\label{sec:glass_patterns} + +When a random dot pattern is scaled, rotated, and superimposed over +the original dots, interesting visual patterns known as Glass Patterns +emerge\footnote{L. Glass. 'Moir\'e effect from random dots' Nature 223, + 578580 (1969).} In this exercise, we generate random dot fields +using numpy's uniform distribution function, and apply +transformations to the random dot field using a scale $\mathbf{S}$ +and rotation $\mathbf{R}$ matrix $\mathbf{X_2} = \mathbf{S} \mathbf{R} +\mathbf{X_1}$. + +If the scale and rotation factors are small, the transformation is +analogous to a single step in the numerical solution of a 2D ODE, and +the plot of both $\mathbf{X_1}$ and $\mathbf{X_2}$ will reveal the +structure of the vecotr field flow around the fixed point (the +invariant under the transformation); see for example the +\textit{stable focus}, aka \textit{spiral}, in +Figure~\ref{fig:glass_dots1}. + +The eigenvalues of the tranformation matrix $\mathbf{M} = +\mathbf{S}\mathbf{R}$ determine the type of fix point: +\textit{center}, \textit{stable focus}, \textit{saddle node}, +etc\dots. For example, if the two eigenvalues are real but differing +in signs, the fixed point is a \textit{saddle node}. If the real +parts of both eigenvalues are negative and the eigenvalues are +complex, the fixed point is a \textit{stable focus}. The complex part +of the eigenvalue determines whether there is any rotation in the +matrix transformation, so another way to look at this is to break out +the scaling and rotation components of the transformation +$\textbf{M}$. If there is a rotation component, then the fixed point +will be a \textit{center} or a \textit{focus}. If the scaling +components are both one, the rotation will be a \textit{center}, if +they are both less than one (contraction), it will be a \textit{stable + focus}. Likewise, if there is no rotation component, the fixed +point will be a \textit{node}, and the scaling components will +determine the type of node. If both are less than one, we have a +\textit{stable node}, if one is greater than one and the other less +than one, we have a \textit{saddle node}. + +\lstinputlisting[label=code:glass_dots1_skel,caption={IGNORED}]{skel/glass_dots1_skel.py} + + + +\begin{center}% +\begin{figure} +\begin{centering}\includegraphics[width=4in]{fig/glass_dots1}\par\end{centering} + + +\caption{\label{fig:glass_dots1}Glass pattern showing a stable focus} +\end{figure} +\par\end{center} Added: trunk/py4science/workbook/intro_linalg.tex =================================================================== --- trunk/py4science/workbook/intro_linalg.tex (rev 0) +++ trunk/py4science/workbook/intro_linalg.tex 2007-10-26 19:44:07 UTC (rev 4022) @@ -0,0 +1,49 @@ +Like matlab, numpy and scipy have support for fast linear algebra +built upon the highly optimized LAPACK, BLAS and ATLAS fortran linear +algebra libraries. Unlike Matlab, in which everything is a matrix or +vector, and the '*' operator always means matrix multiple, the default +object in numpy is an \texttt{array}, and the '*' operator on arrays means +element-wise multiplication. + +Instead, numpy provides a \texttt{matrix} class if you want to do +standard matrix-matrix multiplication with the '*' operator, or the +\texttt{dot} function if you want to do matrix multiplies with plain +arrays. The basic linear algebra functionality is found in +\texttt{numpy.linalg} + +\begin{lstlisting} +In [1]: import numpy as npy +In [2]: import numpy.linalg as linalg + +# X and Y are arrays +In [3]: X = npy.random.rand(3,3) +In [4]: Y = npy.random.rand(3,3) + +# * operator is element wise multiplication, not matrix matrix +In [5]: print X*Y +[[ 0.00973215 0.18086148 0.05539387] + [ 0.00817516 0.63354021 0.2017993 ] + [ 0.34287698 0.25788149 0.15508982]] + +# the dot function will use optimized LAPACK to do matrix-matix +# multiply +In [6]: print npy.dot(X, Y) +[[ 0.10670678 0.68340331 0.39236388] + [ 0.27840642 1.14561885 0.62192324] + [ 0.48192134 1.32314856 0.51188578]] + +# the matrix class will create matrix objects that support matrix +# multiplication with * +In [7]: Xm = npy.matrix(X) +In [8]: Ym = npy.matrix(Y) +In [9]: print Xm*Ym +[[ 0.10670678 0.68340331 0.39236388] + [ 0.27840642 1.14561885 0.62192324] + [ 0.48192134 1.32314856 0.51188578]] + +# the linalg module provides functions to compute eigenvalues, +# determinants, etc. See help(linalg) for more info +In [10]: print linalg.eigvals(X) +[ 1.46131600+0.j 0.46329211+0.16501143j 0.46329211-0.16501143j] + +\end{lstlisting} Added: trunk/py4science/workbook/intro_sigproc.tex =================================================================== --- trunk/py4science/workbook/intro_sigproc.tex (rev 0) +++ trunk/py4science/workbook/intro_sigproc.tex 2007-10-26 19:44:07 UTC (rev 4022) @@ -0,0 +1,15 @@ +\texttt{numpy} and \texttt{scipy} provide many of the essential tools +for digital signal processing. \texttt{scipy.signal} provides basic +tools for digital filter design and filtering (eg Butterworth +filters), a linear systems toolkit, standard waveforms such as square +waves, and saw tooth functions, and some basic wavelet functionality. +\texttt{scipy.fftpack} provides a suite of tools for Fourier domain +analysis, including 1D, 2D, and ND discrete fourier transform and +inverse functions, in addition to other tools such as analytic signal +representations via the Hilbert trasformation (\texttt{numpy.fft} also +provides basic FFT functions). \texttt{pylab} provides Matlab +compatible functions for computing and plotting standard time series +analyses, such as historgrams (\texttt{hist}), auto and cross +correlations (\texttt{acorr} and \texttt{xcorr}), power spectra and +coherence spectra (\texttt{psd}, \texttt{csd}, \texttt{cohere} and +\texttt{specgram}. This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |