From: <fer...@us...> - 2008-10-19 03:52:03
|
Revision: 6258 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=6258&view=rev Author: fer_perez Date: 2008-10-19 03:51:56 +0000 (Sun, 19 Oct 2008) Log Message: ----------- Major updates to workbook. - Made the basemap figures smaller (they were too big and made the compilation really slow). - Changed the ratner figure from png to jpb (saved 90% in size) - Removed all lyx files, we're now using pure latex. - Added scripts for various useful tasks. Modified Paths: -------------- trunk/py4science/workbook/Makefile trunk/py4science/workbook/basemap.tex trunk/py4science/workbook/fig/basemap1.png trunk/py4science/workbook/fig/basemap2.png trunk/py4science/workbook/fig/basemap3.png trunk/py4science/workbook/fig/basemap4.png trunk/py4science/workbook/fig/basemap5.png trunk/py4science/workbook/main.tex trunk/py4science/workbook/wordfreqs.tex Added Paths: ----------- trunk/py4science/workbook/problems_soln/ trunk/py4science/workbook/problems_soln/basemap1.py trunk/py4science/workbook/problems_soln/basemap2.py trunk/py4science/workbook/problems_soln/basemap3.py trunk/py4science/workbook/problems_soln/basemap4.py trunk/py4science/workbook/problems_soln/basemap5.py trunk/py4science/workbook/problems_soln/bessel.py trunk/py4science/workbook/problems_soln/convolution_demo.py trunk/py4science/workbook/problems_soln/fft_imdenoise.py trunk/py4science/workbook/problems_soln/glass_dots1.py trunk/py4science/workbook/problems_soln/lotka_volterra.py trunk/py4science/workbook/problems_soln/noisy_sine.py trunk/py4science/workbook/problems_soln/qsort.py trunk/py4science/workbook/problems_soln/quad_newton.py trunk/py4science/workbook/problems_soln/stats_descriptives.py trunk/py4science/workbook/problems_soln/stats_distributions.py trunk/py4science/workbook/problems_soln/stock_records.py trunk/py4science/workbook/problems_soln/trapezoid.py trunk/py4science/workbook/problems_soln/wallis_pi.py trunk/py4science/workbook/problems_soln/wordfreqs.py trunk/py4science/workbook/update_problems.py Removed Paths: ------------- trunk/py4science/workbook/intro.lyx trunk/py4science/workbook/main.lyx trunk/py4science/workbook/qsort.lyx trunk/py4science/workbook/quad_newton.lyx trunk/py4science/workbook/trapezoid.lyx trunk/py4science/workbook/wallis_pi.lyx trunk/py4science/workbook/wordfreqs.lyx Modified: trunk/py4science/workbook/Makefile =================================================================== --- trunk/py4science/workbook/Makefile 2008-10-19 03:49:27 UTC (rev 6257) +++ trunk/py4science/workbook/Makefile 2008-10-19 03:51:56 UTC (rev 6258) @@ -9,25 +9,27 @@ SKEL_SRC = workbook_skeletons.aux workbook_skeletons.bbl \ workbook_skeletons.tex $(TEXFILES) -SOL_SRC = $(subst _skeletons,_solved,$(SKEL_SRC)) +SOLN_SRC = $(subst _skeletons,_solutions,$(SKEL_SRC)) # programs PDFTEX = pdflatex -file-line-error FASTPDFTEX = pdflatex -file-line-error -draftmode -halt-on-error # convenience shorthand for targets -sol: workbook_solved.pdf +sol: workbook_solutions.pdf skel: workbook_skeletons.pdf -all: sol skel +all: soln skel # actual targets -workbook_solved.pdf: $(SOL_SRC) +workbook_solutions.pdf: $(SOLN_SRC) + ./update_problems.py rm -f problems - ln -sf problems_solved problems - $(PDFTEX) workbook_solved - $(PDFTEX) workbook_solved + ln -sf problems_soln problems + $(PDFTEX) workbook_solutions + $(PDFTEX) workbook_solutions workbook_skeletons.pdf: $(SKEL_SRC) + ./update_problems.py rm -f problems ln -sf problems_skel problems $(PDFTEX) workbook_skeletons @@ -35,14 +37,14 @@ workbook_skeletons.tex: ln -sf main.tex workbook_skeletons.tex -workbook_solved.tex: - ln -sf main.tex workbook_solved.tex +workbook_solutions.tex: + ln -sf main.tex workbook_solutions.tex clean: - rm -f *~ *.aux *.log *.toc *.out *.bbl *.blg + rm -f *~ *.aux *.log *.toc *.out *.bbl *.blg *.fmt distclean: clean - rm -f workbook_solved.pdf workbook_skeletons.pdf + rm -f workbook_solutions.pdf workbook_skeletons.pdf # Basic rules empty := Modified: trunk/py4science/workbook/basemap.tex =================================================================== --- trunk/py4science/workbook/basemap.tex 2008-10-19 03:49:27 UTC (rev 6257) +++ trunk/py4science/workbook/basemap.tex 2008-10-19 03:51:56 UTC (rev 6258) @@ -33,7 +33,7 @@ to Figure 1. \begin{figure}[h] -\includegraphics[scale=0.75]{fig/basemap1} +\includegraphics[width=4in]{fig/basemap1} \caption{A map created by specifying the latitudes and longitudes of the four corners.} @@ -64,7 +64,7 @@ This should produce something similar to Figure 2. \begin{figure}[h] -\includegraphics[scale=0.75]{fig/basemap3} +\includegraphics[width=4in]{fig/basemap3} \caption{Drawing the locations of two cities, and connecting them along a great circle.} @@ -84,7 +84,7 @@ Running this script should produce a plot that looks like Figure 3. \begin{figure}[h] -\includegraphics[scale=0.75]{fig/basemap4} +\includegraphics[width=4in]{fig/basemap4} \caption{Drawing labelled meridians and parallels on the map (a graticule grid).} @@ -114,7 +114,7 @@ The resulting plot should look like Figure 4. \begin{figure}[h] -\includegraphics[scale=0.75]{fig/basemap5} +\includegraphics[width=4in]{fig/basemap5} \caption{Sea surface temperature on a global mollweide projection.} Modified: trunk/py4science/workbook/fig/basemap1.png =================================================================== (Binary files differ) Modified: trunk/py4science/workbook/fig/basemap2.png =================================================================== (Binary files differ) Modified: trunk/py4science/workbook/fig/basemap3.png =================================================================== (Binary files differ) Modified: trunk/py4science/workbook/fig/basemap4.png =================================================================== (Binary files differ) Modified: trunk/py4science/workbook/fig/basemap5.png =================================================================== (Binary files differ) Deleted: trunk/py4science/workbook/intro.lyx =================================================================== --- trunk/py4science/workbook/intro.lyx 2008-10-19 03:49:27 UTC (rev 6257) +++ trunk/py4science/workbook/intro.lyx 2008-10-19 03:51:56 UTC (rev 6258) @@ -1,158 +0,0 @@ -#LyX 1.4.3 created this file. For more info see http://www.lyx.org/ -\lyxformat 245 -\begin_document -\begin_header -\textclass amsbook -\begin_preamble -\input{preamble.tex} -\end_preamble -\language english -\inputencoding auto -\fontscheme default -\graphics default -\paperfontsize default -\spacing single -\papersize default -\use_geometry true -\use_amsmath 1 -\cite_engine basic -\use_bibtopic false -\paperorientation portrait -\leftmargin 1.3in -\topmargin 1in -\rightmargin 1.3in -\bottommargin 1in -\secnumdepth 3 -\tocdepth 3 -\paragraph_separation indent -\defskip medskip -\quotes_language english -\papercolumns 1 -\papersides 2 -\paperpagestyle default -\tracking_changes false -\output_changes false -\end_header - -\begin_body - -\begin_layout Standard -This document contains a set of small problems, drawn from many different - fields, meant to illustrate commonly useful techniques for using Python - in scientific computing. -\end_layout - -\begin_layout Standard -All problems are presented in a similar fashion: the task is explained including - any necessary mathematical background and a `code skeleton' is provided - that is meant to serve as a starting point for the solution of the exercise. - In some cases, some example output of the expected solution, figures or - additional hints may be provided as well. - -\end_layout - -\begin_layout Standard -The accompanying source download for this workbook contains the complete - solutions, which are not part of this document for the sake of brevity. -\end_layout - -\begin_layout Standard -For several examples, the provided skeleton contains pre-written tests which - validate the correctness of the expected answers. - When you have completed the exercise successfully, you should be able to - run it from within IPython and see something like this (illustrated using - a trapezoidal rule problem, whose solution is in the file -\family typewriter -trapezoid.py -\family default -): -\end_layout - -\begin_layout Standard -\begin_inset ERT -status open - -\begin_layout Standard - - -\backslash -begin{lstlisting} -\end_layout - -\begin_layout Standard - -In [7]: run trapezoid.py -\end_layout - -\begin_layout Standard - -.... -\end_layout - -\begin_layout Standard - ----------------------------------------------------------------------- -\end_layout - -\begin_layout Standard - -Ran 4 tests in 0.003s -\end_layout - -\begin_layout Standard - -\end_layout - -\begin_layout Standard - -OK -\end_layout - -\begin_layout Standard - - -\backslash -end{lstlisting} -\end_layout - -\end_inset - - -\end_layout - -\begin_layout Standard -This message tells you that 4 automatic tests were successfully executed. - The idea of including automatic tests in your code is a common one in modern - software development, and Python includes in its standard library two modules - for automatic testing, with slightly different functionality: -\family typewriter -unittest -\family default - and -\family typewriter -doctest -\family default -. - These tests were written using the -\family typewriter -unittest -\family default - system, whose complete documentation can be found here: -\begin_inset LatexCommand \htmlurl{http://docs.python.org/lib/module-unittest.html} - -\end_inset - -. - -\end_layout - -\begin_layout Standard -Other exercises will illustrate the use of the -\family typewriter -doctest -\family default - system, since it provides complementary functionality. -\end_layout - -\end_body -\end_document Deleted: trunk/py4science/workbook/main.lyx =================================================================== --- trunk/py4science/workbook/main.lyx 2008-10-19 03:49:27 UTC (rev 6257) +++ trunk/py4science/workbook/main.lyx 2008-10-19 03:51:56 UTC (rev 6258) @@ -1,166 +0,0 @@ -#LyX 1.4.3 created this file. For more info see http://www.lyx.org/ -\lyxformat 245 -\begin_document -\begin_header -\textclass amsbook -\begin_preamble -\input{preamble.tex} -\end_preamble -\language english -\inputencoding auto -\fontscheme default -\graphics default -\paperfontsize default -\spacing single -\papersize letterpaper -\use_geometry true -\use_amsmath 2 -\cite_engine basic -\use_bibtopic false -\paperorientation portrait -\leftmargin 1.3in -\topmargin 1in -\rightmargin 1.3in -\bottommargin 1in -\secnumdepth 3 -\tocdepth 3 -\paragraph_separation indent -\defskip medskip -\quotes_language english -\papercolumns 1 -\papersides 2 -\paperpagestyle headings -\tracking_changes false -\output_changes true -\end_header - -\begin_body - -\begin_layout Title -\begin_inset ERT -status collapsed - -\begin_layout Standard - - -\backslash -vspace{3cm} -\end_layout - -\end_inset - -Practical Scientific Computing -\newline -in Python -\newline -A Workbook -\end_layout - -\begin_layout Author -\begin_inset ERT -status collapsed - -\begin_layout Standard - - -\backslash -vspace{1cm} -\end_layout - -\end_inset - -John D. - Hunter -\newline -Fernando P\xE9rez -\begin_inset ERT -status collapsed - -\begin_layout Standard - - -\backslash -vspace{1cm} -\end_layout - -\end_inset - - -\end_layout - -\begin_layout Standard -\begin_inset LatexCommand \tableofcontents{} - -\end_inset - - -\end_layout - -\begin_layout Chapter -Introduction -\end_layout - -\begin_layout Standard -\begin_inset Include \input{intro.lyx} -preview false - -\end_inset - - -\end_layout - -\begin_layout Chapter -Simple non-numerical problems -\end_layout - -\begin_layout Standard -\begin_inset Include \input{qsort.lyx} -preview false - -\end_inset - - -\end_layout - -\begin_layout Standard -\begin_inset Include \input{wordfreqs.lyx} -preview false - -\end_inset - - -\end_layout - -\begin_layout Chapter -Elementary Numerics -\end_layout - -\begin_layout Standard -\begin_inset Include \input{wallis_pi.lyx} -preview false - -\end_inset - - -\end_layout - -\begin_layout Standard -\begin_inset Include \input{trapezoid.lyx} -preview false - -\end_inset - - -\end_layout - -\begin_layout Standard -\begin_inset Include \input{quad_newton.lyx} -preview false - -\end_inset - - -\end_layout - -\end_body -\end_document Modified: trunk/py4science/workbook/main.tex =================================================================== --- trunk/py4science/workbook/main.tex 2008-10-19 03:49:27 UTC (rev 6257) +++ trunk/py4science/workbook/main.tex 2008-10-19 03:51:56 UTC (rev 6258) @@ -112,6 +112,7 @@ \input{wallis_pi.tex} \input{trapezoid.tex} \input{quad_newton.tex} +\input{bessel.tex} \chapter{Linear algebra} \input{intro_linalg.tex} Added: trunk/py4science/workbook/problems_soln/basemap1.py =================================================================== --- trunk/py4science/workbook/problems_soln/basemap1.py (rev 0) +++ trunk/py4science/workbook/problems_soln/basemap1.py 2008-10-19 03:51:56 UTC (rev 6258) @@ -0,0 +1 @@ +link ../../examples/soln/basemap1_soln.py \ No newline at end of file Property changes on: trunk/py4science/workbook/problems_soln/basemap1.py ___________________________________________________________________ Added: svn:special + * Added: trunk/py4science/workbook/problems_soln/basemap2.py =================================================================== --- trunk/py4science/workbook/problems_soln/basemap2.py (rev 0) +++ trunk/py4science/workbook/problems_soln/basemap2.py 2008-10-19 03:51:56 UTC (rev 6258) @@ -0,0 +1 @@ +link ../../examples/soln/basemap2_soln.py \ No newline at end of file Property changes on: trunk/py4science/workbook/problems_soln/basemap2.py ___________________________________________________________________ Added: svn:special + * Added: trunk/py4science/workbook/problems_soln/basemap3.py =================================================================== --- trunk/py4science/workbook/problems_soln/basemap3.py (rev 0) +++ trunk/py4science/workbook/problems_soln/basemap3.py 2008-10-19 03:51:56 UTC (rev 6258) @@ -0,0 +1 @@ +link ../../examples/soln/basemap3_soln.py \ No newline at end of file Property changes on: trunk/py4science/workbook/problems_soln/basemap3.py ___________________________________________________________________ Added: svn:special + * Added: trunk/py4science/workbook/problems_soln/basemap4.py =================================================================== --- trunk/py4science/workbook/problems_soln/basemap4.py (rev 0) +++ trunk/py4science/workbook/problems_soln/basemap4.py 2008-10-19 03:51:56 UTC (rev 6258) @@ -0,0 +1 @@ +link ../../examples/soln/basemap4_soln.py \ No newline at end of file Property changes on: trunk/py4science/workbook/problems_soln/basemap4.py ___________________________________________________________________ Added: svn:special + * Added: trunk/py4science/workbook/problems_soln/basemap5.py =================================================================== --- trunk/py4science/workbook/problems_soln/basemap5.py (rev 0) +++ trunk/py4science/workbook/problems_soln/basemap5.py 2008-10-19 03:51:56 UTC (rev 6258) @@ -0,0 +1 @@ +link ../../examples/soln/basemap5_soln.py \ No newline at end of file Property changes on: trunk/py4science/workbook/problems_soln/basemap5.py ___________________________________________________________________ Added: svn:special + * Added: trunk/py4science/workbook/problems_soln/bessel.py =================================================================== --- trunk/py4science/workbook/problems_soln/bessel.py (rev 0) +++ trunk/py4science/workbook/problems_soln/bessel.py 2008-10-19 03:51:56 UTC (rev 6258) @@ -0,0 +1 @@ +link ../../examples/soln/bessel_soln.py \ No newline at end of file Property changes on: trunk/py4science/workbook/problems_soln/bessel.py ___________________________________________________________________ Added: svn:special + * Added: trunk/py4science/workbook/problems_soln/convolution_demo.py =================================================================== --- trunk/py4science/workbook/problems_soln/convolution_demo.py (rev 0) +++ trunk/py4science/workbook/problems_soln/convolution_demo.py 2008-10-19 03:51:56 UTC (rev 6258) @@ -0,0 +1 @@ +link ../../examples/soln/convolution_demo_soln.py \ No newline at end of file Property changes on: trunk/py4science/workbook/problems_soln/convolution_demo.py ___________________________________________________________________ Added: svn:special + * Added: trunk/py4science/workbook/problems_soln/fft_imdenoise.py =================================================================== --- trunk/py4science/workbook/problems_soln/fft_imdenoise.py (rev 0) +++ trunk/py4science/workbook/problems_soln/fft_imdenoise.py 2008-10-19 03:51:56 UTC (rev 6258) @@ -0,0 +1 @@ +link ../../examples/soln/fft_imdenoise_soln.py \ No newline at end of file Property changes on: trunk/py4science/workbook/problems_soln/fft_imdenoise.py ___________________________________________________________________ Added: svn:special + * Added: trunk/py4science/workbook/problems_soln/glass_dots1.py =================================================================== --- trunk/py4science/workbook/problems_soln/glass_dots1.py (rev 0) +++ trunk/py4science/workbook/problems_soln/glass_dots1.py 2008-10-19 03:51:56 UTC (rev 6258) @@ -0,0 +1 @@ +link ../../examples/soln/glass_dots1_soln.py \ No newline at end of file Property changes on: trunk/py4science/workbook/problems_soln/glass_dots1.py ___________________________________________________________________ Added: svn:special + * Added: trunk/py4science/workbook/problems_soln/lotka_volterra.py =================================================================== --- trunk/py4science/workbook/problems_soln/lotka_volterra.py (rev 0) +++ trunk/py4science/workbook/problems_soln/lotka_volterra.py 2008-10-19 03:51:56 UTC (rev 6258) @@ -0,0 +1 @@ +link ../../examples/soln/lotka_volterra_soln.py \ No newline at end of file Property changes on: trunk/py4science/workbook/problems_soln/lotka_volterra.py ___________________________________________________________________ Added: svn:special + * Added: trunk/py4science/workbook/problems_soln/noisy_sine.py =================================================================== --- trunk/py4science/workbook/problems_soln/noisy_sine.py (rev 0) +++ trunk/py4science/workbook/problems_soln/noisy_sine.py 2008-10-19 03:51:56 UTC (rev 6258) @@ -0,0 +1 @@ +link ../../examples/soln/noisy_sine_soln.py \ No newline at end of file Property changes on: trunk/py4science/workbook/problems_soln/noisy_sine.py ___________________________________________________________________ Added: svn:special + * Added: trunk/py4science/workbook/problems_soln/qsort.py =================================================================== --- trunk/py4science/workbook/problems_soln/qsort.py (rev 0) +++ trunk/py4science/workbook/problems_soln/qsort.py 2008-10-19 03:51:56 UTC (rev 6258) @@ -0,0 +1 @@ +link ../../examples/soln/qsort_soln.py \ No newline at end of file Property changes on: trunk/py4science/workbook/problems_soln/qsort.py ___________________________________________________________________ Added: svn:special + * Added: trunk/py4science/workbook/problems_soln/quad_newton.py =================================================================== --- trunk/py4science/workbook/problems_soln/quad_newton.py (rev 0) +++ trunk/py4science/workbook/problems_soln/quad_newton.py 2008-10-19 03:51:56 UTC (rev 6258) @@ -0,0 +1 @@ +link ../../examples/soln/quad_newton_soln.py \ No newline at end of file Property changes on: trunk/py4science/workbook/problems_soln/quad_newton.py ___________________________________________________________________ Added: svn:special + * Added: trunk/py4science/workbook/problems_soln/stats_descriptives.py =================================================================== --- trunk/py4science/workbook/problems_soln/stats_descriptives.py (rev 0) +++ trunk/py4science/workbook/problems_soln/stats_descriptives.py 2008-10-19 03:51:56 UTC (rev 6258) @@ -0,0 +1 @@ +link ../../examples/soln/stats_descriptives_soln.py \ No newline at end of file Property changes on: trunk/py4science/workbook/problems_soln/stats_descriptives.py ___________________________________________________________________ Added: svn:special + * Added: trunk/py4science/workbook/problems_soln/stats_distributions.py =================================================================== --- trunk/py4science/workbook/problems_soln/stats_distributions.py (rev 0) +++ trunk/py4science/workbook/problems_soln/stats_distributions.py 2008-10-19 03:51:56 UTC (rev 6258) @@ -0,0 +1 @@ +link ../../examples/soln/stats_distributions_soln.py \ No newline at end of file Property changes on: trunk/py4science/workbook/problems_soln/stats_distributions.py ___________________________________________________________________ Added: svn:special + * Added: trunk/py4science/workbook/problems_soln/stock_records.py =================================================================== --- trunk/py4science/workbook/problems_soln/stock_records.py (rev 0) +++ trunk/py4science/workbook/problems_soln/stock_records.py 2008-10-19 03:51:56 UTC (rev 6258) @@ -0,0 +1 @@ +link ../../examples/soln/stock_records_soln.py \ No newline at end of file Property changes on: trunk/py4science/workbook/problems_soln/stock_records.py ___________________________________________________________________ Added: svn:special + * Added: trunk/py4science/workbook/problems_soln/trapezoid.py =================================================================== --- trunk/py4science/workbook/problems_soln/trapezoid.py (rev 0) +++ trunk/py4science/workbook/problems_soln/trapezoid.py 2008-10-19 03:51:56 UTC (rev 6258) @@ -0,0 +1 @@ +link ../../examples/soln/trapezoid_soln.py \ No newline at end of file Property changes on: trunk/py4science/workbook/problems_soln/trapezoid.py ___________________________________________________________________ Added: svn:special + * Added: trunk/py4science/workbook/problems_soln/wallis_pi.py =================================================================== --- trunk/py4science/workbook/problems_soln/wallis_pi.py (rev 0) +++ trunk/py4science/workbook/problems_soln/wallis_pi.py 2008-10-19 03:51:56 UTC (rev 6258) @@ -0,0 +1 @@ +link ../../examples/soln/wallis_pi_soln.py \ No newline at end of file Property changes on: trunk/py4science/workbook/problems_soln/wallis_pi.py ___________________________________________________________________ Added: svn:special + * Added: trunk/py4science/workbook/problems_soln/wordfreqs.py =================================================================== --- trunk/py4science/workbook/problems_soln/wordfreqs.py (rev 0) +++ trunk/py4science/workbook/problems_soln/wordfreqs.py 2008-10-19 03:51:56 UTC (rev 6258) @@ -0,0 +1 @@ +link ../../examples/soln/wordfreqs_soln.py \ No newline at end of file Property changes on: trunk/py4science/workbook/problems_soln/wordfreqs.py ___________________________________________________________________ Added: svn:special + * Deleted: trunk/py4science/workbook/qsort.lyx =================================================================== --- trunk/py4science/workbook/qsort.lyx 2008-10-19 03:49:27 UTC (rev 6257) +++ trunk/py4science/workbook/qsort.lyx 2008-10-19 03:51:56 UTC (rev 6258) @@ -1,188 +0,0 @@ -#LyX 1.4.3 created this file. For more info see http://www.lyx.org/ -\lyxformat 245 -\begin_document -\begin_header -\textclass amsbook -\begin_preamble -\input{preamble.tex} -\end_preamble -\language english -\inputencoding auto -\fontscheme default -\graphics default -\paperfontsize default -\spacing single -\papersize default -\use_geometry true -\use_amsmath 1 -\cite_engine basic -\use_bibtopic false -\paperorientation portrait -\leftmargin 1.3in -\topmargin 1in -\rightmargin 1.3in -\bottommargin 1in -\secnumdepth 3 -\tocdepth 3 -\paragraph_separation indent -\defskip medskip -\quotes_language english -\papercolumns 1 -\papersides 2 -\paperpagestyle default -\tracking_changes false -\output_changes false -\end_header - -\begin_body - -\begin_layout Section -Sorting quickly with QuickSort -\end_layout - -\begin_layout Standard -Quicksort is one of the best known, and probably the simplest, fast algorithm - for sorting -\begin_inset Formula $n$ -\end_inset - - items. - It is fast in the sense that it requires on average -\begin_inset Formula $\mathcal{O}(n\log n)$ -\end_inset - - comparisons instead of -\begin_inset Formula $\mathcal{O}(n^{2})$ -\end_inset - -, although a naive implementation does have quadratic worst-case behavior. -\end_layout - -\begin_layout Standard -The algorithm uses a simple divide and conquer strategy, and its implementation - is naturally recursive. - Its basic steps are: -\end_layout - -\begin_layout Enumerate -Pick an element from the list, called the pivot -\begin_inset Formula $p$ -\end_inset - - (any choice works). -\end_layout - -\begin_layout Enumerate -Select from the rest of the list those elements smaller and those greater - than the pivot, and store them in separate lists -\begin_inset Formula $S$ -\end_inset - - and -\begin_inset Formula $G$ -\end_inset - -. -\end_layout - -\begin_layout Enumerate -Recursively apply the algorithm -\family typewriter - -\family default -to -\begin_inset Formula $S$ -\end_inset - - and -\begin_inset Formula $G$ -\end_inset - -. - The final result can be written as -\begin_inset Formula $\sigma(S)+[p]+\sigma(G)$ -\end_inset - -, where -\begin_inset Formula $\sigma$ -\end_inset - - represents the sorting operation, -\begin_inset Formula $+$ -\end_inset - - indicates list concatenation and -\begin_inset Formula $[p]$ -\end_inset - - is the list containing the pivot as its single element. -\end_layout - -\begin_layout Standard -The listing\InsetSpace ~ - -\begin_inset LatexCommand \ref{code:qsort_skel} - -\end_inset - - contains a skeleton with no implementation but with tests already written - (in the form of -\emph on -unit tests -\emph default -, as described in the introduction). -\end_layout - -\begin_layout Standard -\begin_inset ERT -status open - -\begin_layout Standard - - -\backslash -lstinputlisting[label=code:qsort_skel,caption={IGNORED}]{skel/qsort_skel.py} -\end_layout - -\end_inset - - -\end_layout - -\begin_layout Subsection* -Hints -\end_layout - -\begin_layout Itemize -Python has no particular syntactic requirements for implementing recursion, - but it does have a maximum recursion depth. - This value can be queried via the function -\family typewriter -sys.getrecursionlimit() -\family default -, and it can be changed with -\family typewriter -sys.setrecursionlimit(new_value) -\family default -. - -\end_layout - -\begin_layout Itemize -Like in all recursive problems, don't forget to implement an exit condition! -\end_layout - -\begin_layout Itemize -If -\family typewriter -L -\family default - is a list, the call -\family typewriter -len(L) -\family default - provides its length. -\end_layout - -\end_body -\end_document Deleted: trunk/py4science/workbook/quad_newton.lyx =================================================================== --- trunk/py4science/workbook/quad_newton.lyx 2008-10-19 03:49:27 UTC (rev 6257) +++ trunk/py4science/workbook/quad_newton.lyx 2008-10-19 03:51:56 UTC (rev 6258) @@ -1,151 +0,0 @@ -#LyX 1.4.3 created this file. For more info see http://www.lyx.org/ -\lyxformat 245 -\begin_document -\begin_header -\textclass amsbook -\begin_preamble -\input{preamble.tex} -\end_preamble -\language english -\inputencoding auto -\fontscheme default -\graphics default -\paperfontsize default -\spacing single -\papersize default -\use_geometry true -\use_amsmath 1 -\cite_engine basic -\use_bibtopic false -\paperorientation portrait -\leftmargin 1.3in -\topmargin 1in -\rightmargin 1.3in -\bottommargin 1in -\secnumdepth 3 -\tocdepth 3 -\paragraph_separation indent -\defskip medskip -\quotes_language english -\papercolumns 1 -\papersides 2 -\paperpagestyle default -\tracking_changes false -\output_changes false -\end_header - -\begin_body - -\begin_layout Section -Newton's method -\end_layout - -\begin_layout Standard -Consider the problem of solving for -\begin_inset Formula $t$ -\end_inset - - in -\begin_inset Formula \begin{equation} -\int_{o}^{t}f(s)ds=u\end{equation} - -\end_inset - - where -\begin_inset Formula $f(s)$ -\end_inset - - is a monotonically increasing function of -\begin_inset Formula $s$ -\end_inset - - and -\begin_inset Formula $u>0$ -\end_inset - -. -\end_layout - -\begin_layout Standard -This problem can be simply solved if seen as a root finding question. - Let -\begin_inset Formula \begin{equation} -g(t)=\int_{o}^{t}f(s)ds-u,\end{equation} - -\end_inset - -then we just need to find the root for -\begin_inset Formula $g(t),$ -\end_inset - - which is guaranteed to be unique given the conditions above. - -\end_layout - -\begin_layout Standard -The SciPy library includes an optimization package that contains a Newton-Raphso -n solver called -\family typewriter -scipy.optimize.newton. - -\family default - This solver can optionally take a known derivative for the function whose - roots are being sought, and in this case the derivative is simply -\begin_inset Formula \begin{equation} -\frac{dg(t)}{dt}=f(t).\end{equation} - -\end_inset - - -\end_layout - -\begin_layout Standard -For this exercise, implement the solution for the test function -\begin_inset Formula \[ -f(t)=t\sin^{2}(t),\] - -\end_inset - - using -\begin_inset Formula \[ -u=\frac{1}{4}.\] - -\end_inset - - -\end_layout - -\begin_layout Standard -The listing\InsetSpace ~ - -\begin_inset LatexCommand \ref{code:quad_newton_skel} - -\end_inset - - contains a skeleton that includes for comparison the correct numerical - value. -\end_layout - -\begin_layout Standard -\begin_inset ERT -status open - -\begin_layout Standard - - -\backslash -lstinputlisting[label=code:quad_newton_skel,caption={IGNORED}]{skel/quad_newton_ -skel.py} -\end_layout - -\end_inset - - -\end_layout - -\begin_layout Standard - -\end_layout - -\end_body -\end_document Deleted: trunk/py4science/workbook/trapezoid.lyx =================================================================== --- trunk/py4science/workbook/trapezoid.lyx 2008-10-19 03:49:27 UTC (rev 6257) +++ trunk/py4science/workbook/trapezoid.lyx 2008-10-19 03:51:56 UTC (rev 6258) @@ -1,233 +0,0 @@ -#LyX 1.4.3 created this file. For more info see http://www.lyx.org/ -\lyxformat 245 -\begin_document -\begin_header -\textclass amsbook -\begin_preamble -\input{preamble.tex} -\end_preamble -\language english -\inputencoding auto -\fontscheme default -\graphics default -\paperfontsize default -\spacing single -\papersize default -\use_geometry true -\use_amsmath 1 -\cite_engine basic -\use_bibtopic false -\paperorientation portrait -\leftmargin 1.3in -\topmargin 1in -\rightmargin 1.3in -\bottommargin 1in -\secnumdepth 3 -\tocdepth 3 -\paragraph_separation indent -\defskip medskip -\quotes_language english -\papercolumns 1 -\papersides 2 -\paperpagestyle default -\tracking_changes false -\output_changes false -\end_header - -\begin_body - -\begin_layout Section -Trapezoidal rule -\end_layout - -\begin_layout Standard -In this exercise, you are tasked with implementing the simple trapezoid - rule formula for numerical integration. - If we want to compute the definite integral -\begin_inset Formula \begin{equation} -\int_{a}^{b}f(x)dx\end{equation} - -\end_inset - -we can partition the integration interval -\begin_inset Formula $[a,b]$ -\end_inset - - into smaller subintervals, and approximate the area under the curve for - each subinterval by the area of the trapezoid created by linearly interpolating - between the two function values at each end of the subinterval. - This is graphically illustrated in Figure\InsetSpace ~ - -\begin_inset LatexCommand \ref{fig:trapezoid} - -\end_inset - -, where the blue line represents the function -\begin_inset Formula $f(x)$ -\end_inset - - and the red line represents the successive linear segments. -\end_layout - -\begin_layout Standard -The area under -\begin_inset Formula $f(x)$ -\end_inset - - (the value of the definite integral) can thus be approximated as the sum - of the areas of all these trapezoids. - If we denote by -\begin_inset Formula $x_{i}$ -\end_inset - - ( -\begin_inset Formula $i=0,\ldots,n,$ -\end_inset - - with -\begin_inset Formula $x_{0}=a$ -\end_inset - - and -\begin_inset Formula $x_{n}=b$ -\end_inset - -) the abscissas where the function is sampled, then -\begin_inset Formula \begin{equation} -\int_{a}^{b}f(x)dx\approx\frac{1}{2}\sum_{i=1}^{n}\left(x_{i}-x_{i-1}\right)\left(f(x_{i})+f(x_{i+1})\right).\label{eq:trapzf}\end{equation} - -\end_inset - -The common case of using equally spaced abscissas with spacing -\begin_inset Formula $h=(b-a)/n$ -\end_inset - - reads simply -\begin_inset Formula \begin{equation} -\int_{a}^{b}f(x)dx\approx\frac{h}{2}\sum_{i=1}^{n}\left(f(x_{i})+f(x_{i+1})\right).\label{eq:trapzf2}\end{equation} - -\end_inset - -One frequently receives the function values already precomputed, -\begin_inset Formula $y_{i}=f(x_{i}),$ -\end_inset - - so equation\InsetSpace ~ -( -\begin_inset LatexCommand \ref{eq:trapzf} - -\end_inset - -) becomes -\begin_inset Formula \begin{equation} -\int_{a}^{b}f(x)dx\approx\frac{1}{2}\sum_{i=1}^{n}\left(x_{i}-x_{i-1}\right)\left(y_{i}+y_{i-1}\right).\label{eq:trapz}\end{equation} - -\end_inset - - -\end_layout - -\begin_layout Standard -\begin_inset Float figure -wide false -sideways false -status open - -\begin_layout Standard -\align center -\begin_inset Graphics - filename fig/Composite_trapezoidal_rule_illustration.png - lyxscale 10 - width 3in - -\end_inset - - -\end_layout - -\begin_layout Caption -\begin_inset LatexCommand \label{fig:trapezoid} - -\end_inset - -Illustration of the composite trapezoidal rule with a non-uniform grid (Image - credit: Wikipedia). -\end_layout - -\end_inset - - -\end_layout - -\begin_layout Standard -Listing\InsetSpace ~ - -\begin_inset LatexCommand \ref{code:trapezoid_skel} - -\end_inset - - contains a skeleton for this problem, written in the form of two incomplete - functions and a set of automatic tests (in the form of -\emph on -unit tests -\emph default -, as described in the introduction). -\end_layout - -\begin_layout Standard -\begin_inset ERT -status open - -\begin_layout Standard - - -\backslash -lstinputlisting[label=code:trapezoid_skel,caption={IGNORED}]{skel/trapezoid_skel. -py} -\end_layout - -\end_inset - - -\end_layout - -\begin_layout Standard -In this exercise, you'll need to write two functions, -\family typewriter -trapz -\family default - and -\family typewriter -trapzf -\family default -. - -\family typewriter -trapz -\family default - applies the trapezoid formula to pre-computed values, implementing equation\InsetSpace ~ -( -\begin_inset LatexCommand \ref{eq:trapz} - -\end_inset - -), while -\family typewriter -trapzf -\family default - takes a function -\begin_inset Formula $f$ -\end_inset - - as input, as well as the total number of samples to evaluate, and computes - eq.\InsetSpace ~ -( -\begin_inset LatexCommand \ref{eq:trapzf2} - -\end_inset - -). -\end_layout - -\end_body -\end_document Added: trunk/py4science/workbook/update_problems.py =================================================================== --- trunk/py4science/workbook/update_problems.py (rev 0) +++ trunk/py4science/workbook/update_problems.py 2008-10-19 03:51:56 UTC (rev 6258) @@ -0,0 +1,35 @@ +#!/usr/bin/env python +"""Update the problems (skeletons and solutions) relative to their source. + +""" +import os + +from glob import glob +from os import system as sh + +from IPython.genutils import target_outdated + +# Constants +SRC_DIR = '../examples' +UPDATE = './mkskel.py' + + +if __name__ == '__main__': + + problems = [f for f in os.listdir('problems') if f.endswith('.py')] + + os.chdir(SRC_DIR) + to_update = [] + for f in problems: + skel = os.path.join('skel',f.replace('.py','_skel.py')) + soln = os.path.join('soln',f.replace('.py','_soln.py')) + src = [f] + if target_outdated(skel,src) or target_outdated(soln,src): + to_update.append(f) + + if to_update: + targets = ' '.join(to_update) + print 'Updating the following problems:\n',targets + sh('%s %s' % (UPDATE,targets)) + else: + print 'All targets up to date, nothing to do.' Property changes on: trunk/py4science/workbook/update_problems.py ___________________________________________________________________ Added: svn:executable + * Deleted: trunk/py4science/workbook/wallis_pi.lyx =================================================================== --- trunk/py4science/workbook/wallis_pi.lyx 2008-10-19 03:49:27 UTC (rev 6257) +++ trunk/py4science/workbook/wallis_pi.lyx 2008-10-19 03:51:56 UTC (rev 6258) @@ -1,137 +0,0 @@ -#LyX 1.4.3 created this file. For more info see http://www.lyx.org/ -\lyxformat 245 -\begin_document -\begin_header -\textclass amsbook -\begin_preamble -\input{preamble.tex} -\end_preamble -\language english -\inputencoding auto -\fontscheme default -\graphics default -\paperfontsize default -\spacing single -\papersize default -\use_geometry true -\use_amsmath 1 -\cite_engine basic -\use_bibtopic false -\paperorientation portrait -\leftmargin 1.3in -\topmargin 1in -\rightmargin 1.3in -\bottommargin 1in -\secnumdepth 3 -\tocdepth 3 -\paragraph_separation indent -\defskip medskip -\quotes_language english -\papercolumns 1 -\papersides 2 -\paperpagestyle default -\tracking_changes false -\output_changes false -\end_header - -\begin_body - -\begin_layout Section -Wallis' slow road to -\begin_inset Formula $\pi$ -\end_inset - - -\end_layout - -\begin_layout Standard -Wallis' formula is an infinite product that converges (slowly) to -\begin_inset Formula $\pi$ -\end_inset - -: -\begin_inset Formula \begin{equation} -\pi=\prod_{i=1}^{\infty}\frac{4i^{2}}{4i^{2}-1}.\end{equation} - -\end_inset - - -\end_layout - -\begin_layout Standard -The listing\InsetSpace ~ - -\begin_inset LatexCommand \ref{code:wallis_pi_skel} - -\end_inset - - contains a skeleton with no implementation but with some plotting commands - already inserted, so that you can visualize the convergence rate of this - formula as more terms are kept. -\end_layout - -\begin_layout Standard -\begin_inset ERT -status open - -\begin_layout Standard - - -\backslash -lstinputlisting[label=code:wallis_pi_skel,caption={IGNORED}]{skel/wallis_pi_skel. -py} -\end_layout - -\end_inset - - -\end_layout - -\begin_layout Standard -After running the script successfully, you should obtain a plot similar - to Figure\InsetSpace ~ - -\begin_inset LatexCommand \ref{fig:wallis_pi} - -\end_inset - -. -\end_layout - -\begin_layout Standard -\align center -\begin_inset Float figure -wide false -sideways false -status open - -\begin_layout Standard -\align center -\begin_inset Graphics - filename fig/wallis_pi_convergence.eps - width 4in - -\end_inset - - -\end_layout - -\begin_layout Caption -\begin_inset LatexCommand \label{fig:wallis_pi} - -\end_inset - -Convergence rate for Wallis' infinite product approximation to -\begin_inset Formula $\pi.$ -\end_inset - - -\end_layout - -\end_inset - - -\end_layout - -\end_body -\end_document Deleted: trunk/py4science/workbook/wordfreqs.lyx =================================================================== --- trunk/py4science/workbook/wordfreqs.lyx 2008-10-19 03:49:27 UTC (rev 6257) +++ trunk/py4science/workbook/wordfreqs.lyx 2008-10-19 03:51:56 UTC (rev 6258) @@ -1,245 +0,0 @@ -#LyX 1.4.3 created this file. For more info see http://www.lyx.org/ -\lyxformat 245 -\begin_document -\begin_header -\textclass amsbook -\begin_preamble -\input{preamble.tex} -\end_preamble -\language english -\inputencoding auto -\fontscheme default -\graphics default -\paperfontsize default -\spacing single -\papersize default -\use_geometry true -\use_amsmath 1 -\cite_engine basic -\use_bibtopic false -\paperorientation portrait -\leftmargin 1.3in -\topmargin 1in -\rightmargin 1.3in -\bottommargin 1in -\secnumdepth 3 -\tocdepth 3 -\paragraph_separation indent -\defskip medskip -\quotes_language english -\papercolumns 1 -\papersides 2 -\paperpagestyle default -\tracking_changes false -\output_changes false -\end_header - -\begin_body - -\begin_layout Section -Dictionaries for counting words -\end_layout - -\begin_layout Standard -A common task in text processing is to produce a count of word frequencies. - While NumPy has a builtin histogram function for doing numerical histograms, - it won't work out of the box for couting discrete items, since it is a - binning histogram for a range of real values. -\end_layout - -\begin_layout Standard -But the Python language provides very powerful string manipulation capabilities, - as well as a very flexible and efficiently implemented builtin data type, - the -\emph on -dictionary -\emph default -, that makes this task a very simple one. -\end_layout - -\begin_layout Standard -In this problem, you will need to count the frequencies of all the words - contained in a compressed text file supplied as input. - -\end_layout - -\begin_layout Standard -The listing\InsetSpace ~ - -\begin_inset LatexCommand \ref{code:wordfreqs_skel} - -\end_inset - - contains a skeleton for this problem, with -\family typewriter -XXX -\family default - marking various places that are incomplete. - -\end_layout - -\begin_layout Standard -\begin_inset ERT -status open - -\begin_layout Standard - - -\backslash -lstinputlisting[label=code:wordfreqs_skel,caption={IGNORED}]{skel/wordfreqs_skel. -py} -\end_layout - -\end_inset - - -\end_layout - -\begin_layout Subsection* -Hints -\end_layout - -\begin_layout Itemize -The -\family typewriter -print_vk -\family default -function is already provided for you as a simple way to summarize your results. -\end_layout - -\begin_layout Itemize -You will need to read the compressed file -\family typewriter -HISTORY.gz -\family default -. - Python has facilities to do this without having to manually uncompress - it. -\end_layout - -\begin_layout Itemize -Consider `words' simply the result of splitting the input text into a list, - using any form of whitespace as a separator. - This is obviously a very na\xEFve definition of `word', but it shall suffice - for the purposes of this exercise. -\end_layout - -\begin_layout Itemize -Python strings have a -\family typewriter -.split() -\family default - method that allows for very flexible splitting. - You can easily get more details on it in IPython: -\end_layout - -\begin_layout Standard -\begin_inset ERT -status open - -\begin_layout Standard - - -\backslash -begin{lstlisting} -\end_layout - -\begin_layout Standard - -In [2]: a = 'somestring' -\end_layout - -\begin_layout Standard - -\end_layout - -\begin_layout Standard - -In [3]: a.split? -\end_layout - -\begin_layout Standard - -Type: builtin_function_or_method -\end_layout - -\begin_layout Standard - -Base Class: <type 'builtin_function_or_method'> -\end_layout - -\begin_layout Standard - -Namespace: Interactive -\end_layout - -\begin_layout Standard - -Docstring: -\end_layout - -\begin_layout Standard - - S.split([sep [,maxsplit]]) -> list of strings -\end_layout - -\begin_layout Standard - -\end_layout - -\begin_layout Standard - - Return a list of the words in the string S, using sep as the -\end_layout - -\begin_layout Standard - - delimiter string. - If maxsplit is given, at most maxsplit -\end_layout - -\begin_layout Standard - - splits are done. - If sep is not specified or is None, any -\end_layout - -\begin_layout Standard - - whitespace string is a separator. -\end_layout - -\begin_layout Standard - - -\backslash -end{lstlisting} -\end_layout - -\end_inset - - -\end_layout - -\begin_layout Standard -The complete set of methods of Python strings can be viewed by hitting the - TAB key in IPython after typing ` -\family typewriter -a. -\family default -', and each of them can be similarly queried with the ` -\family typewriter -? -\family default -' operator as above. - For more details on Python strings and their companion sequence types, - see -\begin_inset LatexCommand \htmlurl{http://docs.python.org/lib/typesseq.html} - -\end_inset - -. -\end_layout - -\end_body -\end_document Modified: trunk/py4science/workbook/wordfreqs.tex =================================================================== --- trunk/py4science/workbook/wordfreqs.tex 2008-10-19 03:49:27 UTC (rev 6257) +++ trunk/py4science/workbook/wordfreqs.tex 2008-10-19 03:51:56 UTC (rev 6258) @@ -54,4 +54,5 @@ the TAB key in IPython after typing `\texttt{a.}', and each of them can be similarly queried with the `\texttt{?}' operator as above. For more details on Python strings and their companion sequence types, -see \url{http://docs.python.org/lib/typesseq.html}. +see +\url{http://docs.python.org/library/stdtypes.html#sequence-types-str-unicode-list-tuple-buffer-xrange}. This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |