author | Madhusudan.C.S <madhusudancs@gmail.com> |
Wed, 07 Oct 2009 00:43:37 +0530 | |
changeset 46 | 63704b5650f1 |
parent 44 | dd3b9995dc87 |
child 66 | 523f788d2147 |
permissions | -rw-r--r-- |
3 | 1 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
2 |
% Tutorial slides on Python. |
|
3 |
% |
|
4 |
% Author: Prabhu Ramachandran <prabhu at aero.iitb.ac.in> |
|
46
63704b5650f1
Changed the copyright and Institute for all the sessions.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
44
diff
changeset
|
5 |
% Copyright (c) 2005-2009, Prabhu Ramachandran |
3 | 6 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
7 |
||
8 |
\documentclass[14pt,compress]{beamer} |
|
9 |
%\documentclass[draft]{beamer} |
|
10 |
%\documentclass[compress,handout]{beamer} |
|
11 |
%\usepackage{pgfpages} |
|
12 |
%\pgfpagesuselayout{2 on 1}[a4paper,border shrink=5mm] |
|
13 |
||
14 |
% Modified from: generic-ornate-15min-45min.de.tex |
|
15 |
\mode<presentation> |
|
16 |
{ |
|
17 |
\usetheme{Warsaw} |
|
18 |
\useoutertheme{split} |
|
19 |
\setbeamercovered{transparent} |
|
20 |
} |
|
21 |
||
22 |
\usepackage[english]{babel} |
|
23 |
\usepackage[latin1]{inputenc} |
|
24 |
%\usepackage{times} |
|
25 |
\usepackage[T1]{fontenc} |
|
26 |
||
27 |
% Taken from Fernando's slides. |
|
28 |
\usepackage{ae,aecompl} |
|
29 |
\usepackage{mathpazo,courier,euler} |
|
30 |
\usepackage[scaled=.95]{helvet} |
|
31 |
||
32 |
\definecolor{darkgreen}{rgb}{0,0.5,0} |
|
33 |
||
34 |
\usepackage{listings} |
|
35 |
\lstset{language=Python, |
|
36 |
basicstyle=\ttfamily\bfseries, |
|
37 |
commentstyle=\color{red}\itshape, |
|
38 |
stringstyle=\color{darkgreen}, |
|
39 |
showstringspaces=false, |
|
40 |
keywordstyle=\color{blue}\bfseries} |
|
41 |
||
42 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
43 |
% Macros |
|
44 |
\setbeamercolor{emphbar}{bg=blue!20, fg=black} |
|
45 |
\newcommand{\emphbar}[1] |
|
46 |
{\begin{beamercolorbox}[rounded=true]{emphbar} |
|
47 |
{#1} |
|
48 |
\end{beamercolorbox} |
|
49 |
} |
|
50 |
\newcounter{time} |
|
51 |
\setcounter{time}{0} |
|
52 |
\newcommand{\inctime}[1]{\addtocounter{time}{#1}{\tiny \thetime\ m}} |
|
53 |
||
20 | 54 |
\newcommand{\typ}[1]{\lstinline{#1}} |
3 | 55 |
|
56 |
\newcommand{\kwrd}[1]{ \texttt{\textbf{\color{blue}{#1}}} } |
|
57 |
||
58 |
%%% This is from Fernando's setup. |
|
59 |
% \usepackage{color} |
|
60 |
% \definecolor{orange}{cmyk}{0,0.4,0.8,0.2} |
|
61 |
% % Use and configure listings package for nicely formatted code |
|
62 |
% \usepackage{listings} |
|
63 |
% \lstset{ |
|
64 |
% language=Python, |
|
65 |
% basicstyle=\small\ttfamily, |
|
66 |
% commentstyle=\ttfamily\color{blue}, |
|
67 |
% stringstyle=\ttfamily\color{orange}, |
|
68 |
% showstringspaces=false, |
|
69 |
% breaklines=true, |
|
70 |
% postbreak = \space\dots |
|
71 |
% } |
|
72 |
||
73 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
74 |
% Title page |
|
75 |
\title[]{Matrices and Arrays\\ \& \\2D Plotting} |
|
76 |
||
20 | 77 |
\author[FOSSEE Team] {Asokan Pichai\\Prabhu Ramachandran} |
3 | 78 |
|
46
63704b5650f1
Changed the copyright and Institute for all the sessions.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
44
diff
changeset
|
79 |
\institute[IIT Bombay] {Department of Aerospace Engineering\\IIT Bombay} |
3 | 80 |
\date[] {11, October 2009} |
81 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
82 |
||
83 |
%\pgfdeclareimage[height=0.75cm]{iitmlogo}{iitmlogo} |
|
84 |
%\logo{\pgfuseimage{iitmlogo}} |
|
85 |
||
86 |
||
87 |
%% Delete this, if you do not want the table of contents to pop up at |
|
88 |
%% the beginning of each subsection: |
|
89 |
\AtBeginSubsection[] |
|
90 |
{ |
|
91 |
\begin{frame}<beamer> |
|
92 |
\frametitle{Outline} |
|
93 |
\tableofcontents[currentsection,currentsubsection] |
|
94 |
\end{frame} |
|
95 |
} |
|
96 |
||
97 |
\AtBeginSection[] |
|
98 |
{ |
|
99 |
\begin{frame}<beamer> |
|
100 |
\frametitle{Outline} |
|
101 |
\tableofcontents[currentsection,currentsubsection] |
|
102 |
\end{frame} |
|
103 |
} |
|
104 |
||
105 |
% If you wish to uncover everything in a step-wise fashion, uncomment |
|
106 |
% the following command: |
|
107 |
%\beamerdefaultoverlayspecification{<+->} |
|
108 |
||
109 |
%\includeonlyframes{current,current1,current2,current3,current4,current5,current6} |
|
110 |
||
111 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
112 |
% DOCUMENT STARTS |
|
113 |
\begin{document} |
|
114 |
||
115 |
\begin{frame} |
|
116 |
\maketitle |
|
117 |
\end{frame} |
|
118 |
||
119 |
\begin{frame} |
|
120 |
\frametitle{Outline} |
|
121 |
\tableofcontents |
|
122 |
% You might wish to add the option [pausesections] |
|
123 |
\end{frame} |
|
124 |
||
125 |
\section{Matrices and Arrays} |
|
126 |
||
127 |
\subsection{Basic \typ{numpy} } |
|
128 |
||
129 |
\newcommand{\num}{\texttt{numpy}} |
|
130 |
||
131 |
\begin{frame} |
|
132 |
\frametitle{The \num\ module} |
|
133 |
\begin{itemize} |
|
134 |
\item Why? |
|
135 |
\item What: |
|
136 |
\begin{itemize} |
|
137 |
\item An efficient and powerful array type for various common data |
|
138 |
types |
|
139 |
\item Abstracts out the most commonly used standard operations on |
|
140 |
arrays |
|
141 |
\end{itemize} |
|
142 |
\end{itemize} |
|
143 |
\end{frame} |
|
144 |
||
145 |
\begin{frame}[fragile] |
|
146 |
\frametitle{Examples of \num} |
|
147 |
\begin{lstlisting} |
|
148 |
# Simple array math example |
|
149 |
>>> from numpy import * |
|
150 |
>>> a = array([1,2,3,4]) |
|
151 |
>>> b = array([2,3,4,5]) |
|
152 |
>>> a*2 + b + 1 # Basic math! |
|
153 |
array([5, 8, 11, 14]) |
|
154 |
# Pi and e are defined. |
|
155 |
>>> x = linspace(0.0, 10.0, 1000) |
|
156 |
>>> x *= 2*pi/10 # inplace. |
|
157 |
# apply functions to array. |
|
158 |
>>> y = sin(x) |
|
159 |
\end{lstlisting} |
|
4
e5047bcbb608
Moved Array Math, Creation slides around; Added time counters.
Puneeth Chaganti <punchagan@fossee.in>
parents:
3
diff
changeset
|
160 |
\inctime{5} |
3 | 161 |
\end{frame} |
162 |
||
163 |
\begin{frame} |
|
164 |
\frametitle{Basic concepts} |
|
165 |
\begin{itemize} |
|
166 |
\item fixed size (\typ{arr.size}); |
|
167 |
\item Same type (\typ{arr.dtype}) of data |
|
168 |
\item arbitrary dimensionality |
|
169 |
\item \typ{arr.shape}: size in each dimension |
|
170 |
\item \alert{Note:} \typ{len(arr) != arr.size} in general |
|
171 |
\item \alert{Note:} By default array operations are performed |
|
172 |
\alert{elementwise} |
|
173 |
\end{itemize} |
|
174 |
\end{frame} |
|
175 |
||
176 |
||
177 |
\begin{frame}[fragile] |
|
178 |
\frametitle{More examples of \num} |
|
179 |
\vspace*{-8pt} |
|
180 |
\begin{lstlisting} |
|
181 |
>>> x = array([1., 2, 3, 4]) |
|
182 |
>>> size(x) |
|
183 |
4 |
|
184 |
>>> x.dtype # What is a.dtype? |
|
185 |
dtype('float64') |
|
186 |
>>> x.shape |
|
187 |
(4,) |
|
188 |
>>> print rank(x), x.itemsize |
|
189 |
1 8 |
|
190 |
>>> x[0] = 10 |
|
191 |
>>> print x[0], x[-1] |
|
192 |
10.0 4.0 |
|
193 |
\end{lstlisting} |
|
194 |
\end{frame} |
|
195 |
||
196 |
\begin{frame}[fragile] |
|
197 |
\frametitle{Multi-dimensional arrays} |
|
198 |
\begin{lstlisting} |
|
199 |
>>> a = array([[ 0, 1, 2, 3], |
|
200 |
... [10,11,12,13]]) |
|
201 |
>>> a.shape # (rows, columns) |
|
202 |
(2, 4) |
|
203 |
# Accessing and setting values |
|
204 |
>>> a[1,3] |
|
205 |
13 |
|
206 |
>>> a[1,3] = -1 |
|
207 |
>>> a[1] # The second row |
|
208 |
array([10,11,12,-1]) |
|
209 |
||
210 |
\end{lstlisting} |
|
211 |
\end{frame} |
|
4
e5047bcbb608
Moved Array Math, Creation slides around; Added time counters.
Puneeth Chaganti <punchagan@fossee.in>
parents:
3
diff
changeset
|
212 |
\begin{frame}[fragile] |
e5047bcbb608
Moved Array Math, Creation slides around; Added time counters.
Puneeth Chaganti <punchagan@fossee.in>
parents:
3
diff
changeset
|
213 |
\frametitle{Array math} |
e5047bcbb608
Moved Array Math, Creation slides around; Added time counters.
Puneeth Chaganti <punchagan@fossee.in>
parents:
3
diff
changeset
|
214 |
\begin{itemize} |
e5047bcbb608
Moved Array Math, Creation slides around; Added time counters.
Puneeth Chaganti <punchagan@fossee.in>
parents:
3
diff
changeset
|
215 |
\item Basic \alert{elementwise} math (given two arrays \typ{a, b}): |
e5047bcbb608
Moved Array Math, Creation slides around; Added time counters.
Puneeth Chaganti <punchagan@fossee.in>
parents:
3
diff
changeset
|
216 |
\typ{+, -, *, /, \%} |
20 | 217 |
\item Inplace operators: \typ{a += b}, or \typ{add(a, b, a)} etc. |
218 |
\item \typ{sum(x, axis=0)}, |
|
219 |
\typ{product(x, axis=0)}, |
|
220 |
\typ{dot(a, bp)} |
|
221 |
\end{itemize} |
|
222 |
\end{frame} |
|
223 |
||
224 |
\begin{frame}[fragile] |
|
225 |
\frametitle{Array math cont.} |
|
226 |
\begin{itemize} |
|
4
e5047bcbb608
Moved Array Math, Creation slides around; Added time counters.
Puneeth Chaganti <punchagan@fossee.in>
parents:
3
diff
changeset
|
227 |
\item Logical operations: \typ{equal (==)}, \typ{not\_equal (!=)}, |
e5047bcbb608
Moved Array Math, Creation slides around; Added time counters.
Puneeth Chaganti <punchagan@fossee.in>
parents:
3
diff
changeset
|
228 |
\typ{less (<)}, \typ{greater (>)} etc. |
20 | 229 |
\item Trig and other functions: \typ{sin(x),} |
230 |
\typ{arcsin(x), sinh(x),} |
|
231 |
\typ{exp(x), sqrt(x)} etc. |
|
4
e5047bcbb608
Moved Array Math, Creation slides around; Added time counters.
Puneeth Chaganti <punchagan@fossee.in>
parents:
3
diff
changeset
|
232 |
\end{itemize} |
20 | 233 |
\inctime{10} |
4
e5047bcbb608
Moved Array Math, Creation slides around; Added time counters.
Puneeth Chaganti <punchagan@fossee.in>
parents:
3
diff
changeset
|
234 |
\end{frame} |
e5047bcbb608
Moved Array Math, Creation slides around; Added time counters.
Puneeth Chaganti <punchagan@fossee.in>
parents:
3
diff
changeset
|
235 |
|
e5047bcbb608
Moved Array Math, Creation slides around; Added time counters.
Puneeth Chaganti <punchagan@fossee.in>
parents:
3
diff
changeset
|
236 |
\subsection{Array Creation \& Slicing, Striding Arrays} |
e5047bcbb608
Moved Array Math, Creation slides around; Added time counters.
Puneeth Chaganti <punchagan@fossee.in>
parents:
3
diff
changeset
|
237 |
\begin{frame}[fragile] |
e5047bcbb608
Moved Array Math, Creation slides around; Added time counters.
Puneeth Chaganti <punchagan@fossee.in>
parents:
3
diff
changeset
|
238 |
\frametitle{Array creation functions} |
20 | 239 |
\begin {block}{\typ{array(object, dtype=None, ...)}} |
240 |
\begin{lstlisting} |
|
241 |
>>> array( [2,3,4] ) |
|
242 |
array([2, 3, 4]) |
|
243 |
\end{lstlisting} |
|
244 |
\end {block} |
|
245 |
\begin{block}{\typ{linspace(start, stop, num=50, ...)}} |
|
246 |
\begin{lstlisting} |
|
247 |
>>> linspace( 0, 2, 4 ) |
|
248 |
array([0.,0.6666667,1.3333333,2.]) |
|
249 |
\end{lstlisting} |
|
250 |
\end{block} |
|
4
e5047bcbb608
Moved Array Math, Creation slides around; Added time counters.
Puneeth Chaganti <punchagan@fossee.in>
parents:
3
diff
changeset
|
251 |
\begin{itemize} |
20 | 252 |
\item also try \typ{arange} command |
253 |
\end{itemize} |
|
254 |
\end{frame} |
|
255 |
||
256 |
\begin{frame}[fragile] |
|
257 |
\frametitle{Array creation functions cont.} |
|
258 |
\begin{itemize} |
|
259 |
\item \typ{ones(shape, dtype=None, ...)} |
|
260 |
\begin{lstlisting} |
|
261 |
>>>ones([2,2]) |
|
262 |
array([[ 1., 1.], |
|
263 |
[ 1., 1.]]) |
|
264 |
\end{lstlisting} |
|
265 |
\item \typ{identity(n)} |
|
266 |
\item \typ{ones\_like(x)} |
|
267 |
\begin{lstlisting} |
|
268 |
>>>a = array([[1,2,3],[4,5,6]]) |
|
269 |
>>>ones_like(a) |
|
270 |
array([[1, 1, 1], |
|
271 |
[1, 1, 1]]) |
|
272 |
\end{lstlisting} |
|
273 |
\item check out \typ{zeros, zeros\_like, empty} |
|
4
e5047bcbb608
Moved Array Math, Creation slides around; Added time counters.
Puneeth Chaganti <punchagan@fossee.in>
parents:
3
diff
changeset
|
274 |
\end{itemize} |
e5047bcbb608
Moved Array Math, Creation slides around; Added time counters.
Puneeth Chaganti <punchagan@fossee.in>
parents:
3
diff
changeset
|
275 |
\end{frame} |
3 | 276 |
|
277 |
\begin{frame}[fragile] |
|
278 |
\frametitle{Slicing arrays} |
|
279 |
\begin{lstlisting} |
|
280 |
>>> a = array([[1,2,3], [4,5,6], |
|
281 |
[7,8,9]]) |
|
282 |
>>> a[0,1:3] |
|
283 |
array([2, 3]) |
|
284 |
>>> a[1:,1:] |
|
285 |
array([[5, 6], |
|
286 |
[8, 9]]) |
|
287 |
>>> a[:,2] |
|
288 |
array([3, 6, 9]) |
|
9
2281002b579b
Edited Problem Sets - Added cobweb plot; Removed Koch.
Puneeth Chaganti <punchagan@fossee.in>
parents:
6
diff
changeset
|
289 |
>>> a[...,2] |
2281002b579b
Edited Problem Sets - Added cobweb plot; Removed Koch.
Puneeth Chaganti <punchagan@fossee.in>
parents:
6
diff
changeset
|
290 |
array([3, 6, 9]) |
3 | 291 |
\end{lstlisting} |
292 |
\end{frame} |
|
4
e5047bcbb608
Moved Array Math, Creation slides around; Added time counters.
Puneeth Chaganti <punchagan@fossee.in>
parents:
3
diff
changeset
|
293 |
|
3 | 294 |
\begin{frame}[fragile] |
295 |
\frametitle{Striding arrays} |
|
296 |
\begin{lstlisting} |
|
297 |
>>> a[0::2,0::2] |
|
298 |
array([[1, 3], |
|
299 |
[7, 9]]) |
|
300 |
# Slices are references to the |
|
301 |
# same memory! |
|
302 |
\end{lstlisting} |
|
303 |
\end{frame} |
|
304 |
||
305 |
\begin{frame}[fragile] |
|
4
e5047bcbb608
Moved Array Math, Creation slides around; Added time counters.
Puneeth Chaganti <punchagan@fossee.in>
parents:
3
diff
changeset
|
306 |
\frametitle{Random Numbers} |
e5047bcbb608
Moved Array Math, Creation slides around; Added time counters.
Puneeth Chaganti <punchagan@fossee.in>
parents:
3
diff
changeset
|
307 |
\begin{lstlisting} |
e5047bcbb608
Moved Array Math, Creation slides around; Added time counters.
Puneeth Chaganti <punchagan@fossee.in>
parents:
3
diff
changeset
|
308 |
>>> np.random.rand(3,2) |
e5047bcbb608
Moved Array Math, Creation slides around; Added time counters.
Puneeth Chaganti <punchagan@fossee.in>
parents:
3
diff
changeset
|
309 |
array([[ 0.96276665, 0.77174861], |
e5047bcbb608
Moved Array Math, Creation slides around; Added time counters.
Puneeth Chaganti <punchagan@fossee.in>
parents:
3
diff
changeset
|
310 |
[ 0.35138557, 0.61462271], |
e5047bcbb608
Moved Array Math, Creation slides around; Added time counters.
Puneeth Chaganti <punchagan@fossee.in>
parents:
3
diff
changeset
|
311 |
[ 0.16789255, 0.43848811]]) |
e5047bcbb608
Moved Array Math, Creation slides around; Added time counters.
Puneeth Chaganti <punchagan@fossee.in>
parents:
3
diff
changeset
|
312 |
>>> np.random.randint(1,100) |
e5047bcbb608
Moved Array Math, Creation slides around; Added time counters.
Puneeth Chaganti <punchagan@fossee.in>
parents:
3
diff
changeset
|
313 |
42 |
e5047bcbb608
Moved Array Math, Creation slides around; Added time counters.
Puneeth Chaganti <punchagan@fossee.in>
parents:
3
diff
changeset
|
314 |
\end{lstlisting} |
e5047bcbb608
Moved Array Math, Creation slides around; Added time counters.
Puneeth Chaganti <punchagan@fossee.in>
parents:
3
diff
changeset
|
315 |
\inctime{15} |
3 | 316 |
\end{frame} |
317 |
||
318 |
\begin{frame}[fragile] |
|
6
1f9492506ba2
Added a problem after initial numpy section in session1.
Puneeth Chaganti <punchagan@fossee.in>
parents:
4
diff
changeset
|
319 |
\frametitle{Problem Set} |
1f9492506ba2
Added a problem after initial numpy section in session1.
Puneeth Chaganti <punchagan@fossee.in>
parents:
4
diff
changeset
|
320 |
\begin{lstlisting} |
1f9492506ba2
Added a problem after initial numpy section in session1.
Puneeth Chaganti <punchagan@fossee.in>
parents:
4
diff
changeset
|
321 |
>>> from scipy import misc |
1f9492506ba2
Added a problem after initial numpy section in session1.
Puneeth Chaganti <punchagan@fossee.in>
parents:
4
diff
changeset
|
322 |
>>> A=misc.imread(name) |
1f9492506ba2
Added a problem after initial numpy section in session1.
Puneeth Chaganti <punchagan@fossee.in>
parents:
4
diff
changeset
|
323 |
>>> misc.imshow(A) |
1f9492506ba2
Added a problem after initial numpy section in session1.
Puneeth Chaganti <punchagan@fossee.in>
parents:
4
diff
changeset
|
324 |
\end{lstlisting} |
1f9492506ba2
Added a problem after initial numpy section in session1.
Puneeth Chaganti <punchagan@fossee.in>
parents:
4
diff
changeset
|
325 |
\begin{enumerate} |
1f9492506ba2
Added a problem after initial numpy section in session1.
Puneeth Chaganti <punchagan@fossee.in>
parents:
4
diff
changeset
|
326 |
\item Convert an RGB image to Grayscale. $ Y = 0.5R + 0.25G + 0.25B $ |
9
2281002b579b
Edited Problem Sets - Added cobweb plot; Removed Koch.
Puneeth Chaganti <punchagan@fossee.in>
parents:
6
diff
changeset
|
327 |
\item Scale the image to 50\% |
34
5218871f98f4
Edited image processing example.
Puneeth Chaganti <punchagan@fossee.in>
parents:
20
diff
changeset
|
328 |
\item Introduce some random noise |
5218871f98f4
Edited image processing example.
Puneeth Chaganti <punchagan@fossee.in>
parents:
20
diff
changeset
|
329 |
\item Smooth the image using a mean filter |
5218871f98f4
Edited image processing example.
Puneeth Chaganti <punchagan@fossee.in>
parents:
20
diff
changeset
|
330 |
\\\small{Take the mean of all the neighbouring elements} |
5218871f98f4
Edited image processing example.
Puneeth Chaganti <punchagan@fossee.in>
parents:
20
diff
changeset
|
331 |
\\\small{How fast can you do it?} |
6
1f9492506ba2
Added a problem after initial numpy section in session1.
Puneeth Chaganti <punchagan@fossee.in>
parents:
4
diff
changeset
|
332 |
\end{enumerate} |
4
e5047bcbb608
Moved Array Math, Creation slides around; Added time counters.
Puneeth Chaganti <punchagan@fossee.in>
parents:
3
diff
changeset
|
333 |
\inctime{15} |
3 | 334 |
\end{frame} |
4
e5047bcbb608
Moved Array Math, Creation slides around; Added time counters.
Puneeth Chaganti <punchagan@fossee.in>
parents:
3
diff
changeset
|
335 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
3 | 336 |
|
337 |
\section{2D Plotting} |
|
338 |
\subsection{Getting Started} |
|
339 |
||
340 |
\begin{frame} |
|
341 |
{IPython's \typ{pylab} mode} |
|
20 | 342 |
\begin{block}{Immediate use:} |
343 |
\typ{\$ ipython -pylab} |
|
344 |
\end{block} |
|
3 | 345 |
\begin{itemize} |
20 | 346 |
\item \typ{pylab}: convenient 2D plotting interface to MPL |
3 | 347 |
\item Imports all of pylab for you! |
348 |
\item Allows for interactive plotting |
|
349 |
\end{itemize} |
|
350 |
\end{frame} |
|
351 |
||
352 |
\begin{frame}[fragile] |
|
353 |
\frametitle{Basic 2D plotting} |
|
354 |
||
355 |
\begin{lstlisting} |
|
356 |
>>> x = linspace(0, 2*pi, 1000) |
|
357 |
>>> plot(x, sin(x)) |
|
358 |
>>> plot(x, sin(x), 'ro') |
|
359 |
>>> xlabel(r'$\chi$', color='g') |
|
360 |
# LaTeX markup! |
|
361 |
>>> ylabel(r'sin($\chi$)', color='r') |
|
362 |
>>> title('Simple figure', fontsize=20) |
|
363 |
>>> savefig('/tmp/test.eps') |
|
364 |
\end{lstlisting} |
|
365 |
\begin{itemize} |
|
366 |
\item Also: PNG, PDF, PS, EPS, SVG, PDF |
|
367 |
\end{itemize} |
|
12 | 368 |
\inctime{5} |
3 | 369 |
\end{frame} |
370 |
||
4
e5047bcbb608
Moved Array Math, Creation slides around; Added time counters.
Puneeth Chaganti <punchagan@fossee.in>
parents:
3
diff
changeset
|
371 |
\subsection{Plots - Lines, Labels and Legends} |
3 | 372 |
\begin{frame}[fragile] |
12 | 373 |
\frametitle{Tweaking plots} |
3 | 374 |
\begin{lstlisting} |
375 |
# Set properties of objects: |
|
376 |
>>> l, = plot(x, sin(x)) |
|
377 |
# Why "l,"? |
|
378 |
>>> setp(l, linewidth=2.0, color='r') |
|
379 |
>>> l.set_linewidth(2.0) |
|
380 |
>>> draw() # Redraw. |
|
20 | 381 |
>>> setp(l) # Print properties. |
3 | 382 |
>>> clf() # Clear figure. |
383 |
>>> close() # Close figure. |
|
384 |
\end{lstlisting} |
|
385 |
\end{frame} |
|
386 |
||
387 |
\begin{frame}[fragile] |
|
10 | 388 |
\frametitle{Working with text \ldots} |
7
adcc40e2bf70
Made changes in plotting section.
Shantanu <shantanu@fossee.in>
parents:
6
diff
changeset
|
389 |
%\begin{itemize} |
adcc40e2bf70
Made changes in plotting section.
Shantanu <shantanu@fossee.in>
parents:
6
diff
changeset
|
390 |
% \item We already saw LaTeX markup support! |
adcc40e2bf70
Made changes in plotting section.
Shantanu <shantanu@fossee.in>
parents:
6
diff
changeset
|
391 |
%\end{itemize} |
adcc40e2bf70
Made changes in plotting section.
Shantanu <shantanu@fossee.in>
parents:
6
diff
changeset
|
392 |
\begin{lstlisting} |
adcc40e2bf70
Made changes in plotting section.
Shantanu <shantanu@fossee.in>
parents:
6
diff
changeset
|
393 |
>>> w = arange(-2,2,.1) |
adcc40e2bf70
Made changes in plotting section.
Shantanu <shantanu@fossee.in>
parents:
6
diff
changeset
|
394 |
>>> plot(w,exp(-(w*w))*cos) |
adcc40e2bf70
Made changes in plotting section.
Shantanu <shantanu@fossee.in>
parents:
6
diff
changeset
|
395 |
>>> ylabel('$f(\omega)$') |
adcc40e2bf70
Made changes in plotting section.
Shantanu <shantanu@fossee.in>
parents:
6
diff
changeset
|
396 |
>>> xlabel('$\omega$') |
adcc40e2bf70
Made changes in plotting section.
Shantanu <shantanu@fossee.in>
parents:
6
diff
changeset
|
397 |
>>> title(r"$f(\omega)=e^{-\omega^2} |
adcc40e2bf70
Made changes in plotting section.
Shantanu <shantanu@fossee.in>
parents:
6
diff
changeset
|
398 |
cos({\omega^2})$") |
adcc40e2bf70
Made changes in plotting section.
Shantanu <shantanu@fossee.in>
parents:
6
diff
changeset
|
399 |
>>> annotate('maxima',xy=(0, 1), |
adcc40e2bf70
Made changes in plotting section.
Shantanu <shantanu@fossee.in>
parents:
6
diff
changeset
|
400 |
xytext=(1, 0.8), |
adcc40e2bf70
Made changes in plotting section.
Shantanu <shantanu@fossee.in>
parents:
6
diff
changeset
|
401 |
arrowprops=dict( |
adcc40e2bf70
Made changes in plotting section.
Shantanu <shantanu@fossee.in>
parents:
6
diff
changeset
|
402 |
facecolor='black', |
adcc40e2bf70
Made changes in plotting section.
Shantanu <shantanu@fossee.in>
parents:
6
diff
changeset
|
403 |
shrink=0.05)) |
adcc40e2bf70
Made changes in plotting section.
Shantanu <shantanu@fossee.in>
parents:
6
diff
changeset
|
404 |
\end{lstlisting} |
10 | 405 |
|
7
adcc40e2bf70
Made changes in plotting section.
Shantanu <shantanu@fossee.in>
parents:
6
diff
changeset
|
406 |
\end{frame} |
adcc40e2bf70
Made changes in plotting section.
Shantanu <shantanu@fossee.in>
parents:
6
diff
changeset
|
407 |
|
adcc40e2bf70
Made changes in plotting section.
Shantanu <shantanu@fossee.in>
parents:
6
diff
changeset
|
408 |
\begin{frame}[fragile] |
8 | 409 |
\frametitle{Legends} |
410 |
\begin{lstlisting} |
|
12 | 411 |
>>> x = linspace(0, 2*pi, 1000) |
8 | 412 |
>>> plot(x, cos(5*x), 'r--', |
413 |
label='cosine') |
|
414 |
>>> plot(x, sin(5*x), 'g--', |
|
415 |
label='sine') |
|
416 |
>>> legend() |
|
417 |
# Or use: |
|
418 |
>>> legend(['cosine', 'sine']) |
|
419 |
\end{lstlisting} |
|
420 |
\end{frame} |
|
421 |
||
422 |
\begin{frame}[fragile] |
|
3 | 423 |
\frametitle{Multiple figures} |
424 |
||
425 |
\begin{lstlisting} |
|
426 |
>>> figure(1) |
|
427 |
>>> plot(x, sin(x)) |
|
428 |
>>> figure(2) |
|
429 |
>>> plot(x, tanh(x)) |
|
430 |
>>> figure(1) |
|
431 |
>>> title('Easy as 1,2,3') |
|
432 |
\end{lstlisting} |
|
433 |
||
434 |
||
435 |
\end{frame} |
|
436 |
||
437 |
\begin{frame}[fragile] |
|
438 |
\frametitle{Note: \typ{pylab} in Python scripts} |
|
439 |
\begin{lstlisting} |
|
440 |
import pylab |
|
441 |
x = pylab.linspace(0, 20, 1000) |
|
442 |
pylab.plot(x, pylab.sin(x)) |
|
443 |
||
444 |
# Can also use: |
|
445 |
from pylab import linspace, sin, plot |
|
446 |
\end{lstlisting} |
|
12 | 447 |
\inctime{5} |
3 | 448 |
\end{frame} |
449 |
||
450 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
451 |
\subsection{Types of Plots} |
|
452 |
\begin{frame}[fragile] |
|
453 |
\frametitle{X-Y plot} |
|
454 |
\begin{columns} |
|
455 |
\column{0.5\textwidth} |
|
456 |
\hspace*{-0.5in} |
|
457 |
\includegraphics[height=2in, interpolate=true]{data/xyplot} |
|
458 |
\column{0.45\textwidth} |
|
459 |
\begin{block}{Example code} |
|
460 |
\tiny |
|
461 |
\begin{lstlisting} |
|
462 |
t1 = arange(0.0, 5.0, 0.1) |
|
463 |
t2 = arange(0.0, 5.0, 0.02) |
|
464 |
t3 = arange(0.0, 2.0, 0.01) |
|
465 |
subplot(211) |
|
466 |
plot(t1, cos(2*pi*t1)*exp(-t1), 'bo', |
|
467 |
t2, cos(2*pi*t2)*exp(-t2), 'k') |
|
468 |
grid(True) |
|
469 |
title('A tale of 2 subplots') |
|
470 |
ylabel('Damped') |
|
471 |
subplot(212) |
|
472 |
plot(t3, cos(2*pi*t3), 'r--') |
|
473 |
grid(True) |
|
474 |
xlabel('time (s)') |
|
475 |
ylabel('Undamped') |
|
476 |
\end{lstlisting} |
|
477 |
\end{block} |
|
478 |
\end{columns} |
|
479 |
\end{frame} |
|
480 |
||
481 |
\begin{frame}[fragile] \frametitle{Semi-log and log-log plots} |
|
482 |
\begin{columns} |
|
483 |
\column{0.5\textwidth} |
|
484 |
\hspace*{-0.5in} |
|
485 |
\includegraphics[height=2in, interpolate=true]{data/log} |
|
486 |
\column{0.45\textwidth} |
|
487 |
\begin{block}{Example code} |
|
488 |
\tiny |
|
489 |
\begin{lstlisting} |
|
490 |
dt = 0.01 |
|
491 |
t = arange(dt, 20.0, dt) |
|
492 |
subplot(311) |
|
493 |
semilogy(t, exp(-t/5.0)) |
|
494 |
ylabel('semilogy') |
|
495 |
grid(True) |
|
496 |
subplot(312) |
|
497 |
semilogx(t, sin(2*pi*t)) |
|
498 |
ylabel('semilogx') |
|
499 |
grid(True) |
|
500 |
# minor grid on too |
|
501 |
gca().xaxis.grid(True, which='minor') |
|
502 |
subplot(313) |
|
503 |
loglog(t, 20*exp(-t/10.0), basex=4) |
|
504 |
grid(True) |
|
505 |
ylabel('loglog base 4 on x') |
|
506 |
\end{lstlisting} |
|
507 |
\end{block} |
|
508 |
\end{columns} |
|
509 |
\end{frame} |
|
510 |
||
511 |
\begin{frame}[fragile] \frametitle{Errorbar} |
|
512 |
\begin{columns} |
|
513 |
\column{0.5\textwidth} |
|
514 |
\hspace*{-0.5in} |
|
515 |
\includegraphics[height=2in, interpolate=true]{data/errorbar} |
|
516 |
\column{0.45\textwidth} |
|
517 |
\begin{block}{Example code} |
|
518 |
\tiny |
|
519 |
\begin{lstlisting} |
|
520 |
t = arange(0.1, 4, 0.1) |
|
521 |
s = exp(-t) |
|
522 |
e = 0.1*abs(randn(len(s))) |
|
523 |
f = 0.1*abs(randn(len(s))) |
|
524 |
g = 2*e |
|
525 |
h = 2*f |
|
526 |
errorbar(t, s, [e,g], f, fmt='o') |
|
527 |
xlabel('Distance (m)') |
|
528 |
ylabel('Height (m)') |
|
529 |
title('Mean and standard error '\ |
|
530 |
'as a function of distance') |
|
531 |
\end{lstlisting} |
|
532 |
\end{block} |
|
533 |
\end{columns} |
|
534 |
\end{frame} |
|
535 |
||
536 |
\begin{frame}[fragile] \frametitle{Histogram} |
|
537 |
\begin{columns} |
|
538 |
\column{0.5\textwidth} |
|
539 |
\hspace*{-0.5in} |
|
540 |
\includegraphics[height=2in, interpolate=true]{data/histogram} |
|
541 |
\column{0.45\textwidth} |
|
542 |
\begin{block}{Example code} |
|
543 |
\tiny |
|
544 |
\begin{lstlisting} |
|
545 |
mu, sigma = 100, 15 |
|
546 |
x = mu + sigma*randn(10000) |
|
547 |
# the histogram of the data |
|
548 |
n, bins, patches = hist(x, 100, normed=1) |
|
549 |
# add a 'best fit' line |
|
550 |
y = normpdf( bins, mu, sigma) |
|
551 |
l = plot(bins, y, 'r--', linewidth=2) |
|
552 |
xlim(40, 160) |
|
553 |
xlabel('Smarts') |
|
554 |
ylabel('P') |
|
555 |
title(r'$\rm{IQ:}\/ \mu=100,\/ \sigma=15$') |
|
556 |
\end{lstlisting} |
|
557 |
\end{block} |
|
558 |
\end{columns} |
|
559 |
\end{frame} |
|
560 |
||
561 |
\begin{frame}[fragile] \frametitle{Bar charts} |
|
562 |
\begin{columns} |
|
563 |
\column{0.5\textwidth} |
|
564 |
\hspace*{-0.5in} |
|
565 |
\includegraphics[height=2in, interpolate=true]{data/barchart} |
|
566 |
\column{0.45\textwidth} |
|
567 |
\begin{block}{Example code} |
|
568 |
\tiny |
|
569 |
\begin{lstlisting} |
|
570 |
N = 5 |
|
571 |
menMeans = (20, 35, 30, 35, 27) |
|
572 |
menStd = ( 2, 3, 4, 1, 2) |
|
573 |
# the x locations for the groups |
|
574 |
ind = arange(N) |
|
575 |
# the width of the bars |
|
576 |
width = 0.35 |
|
577 |
p1 = bar(ind, menMeans, width, |
|
578 |
color='r', yerr=menStd) |
|
579 |
womenMeans = (25, 32, 34, 20, 25) |
|
580 |
womenStd = ( 3, 5, 2, 3, 3) |
|
581 |
p2 = bar(ind+width, womenMeans, width, |
|
582 |
color='y', yerr=womenStd) |
|
583 |
ylabel('Scores') |
|
584 |
title('Scores by group and gender') |
|
585 |
xticks(ind+width, |
|
586 |
('G1', 'G2', 'G3', 'G4', 'G5')) |
|
587 |
xlim(-width,len(ind)) |
|
588 |
yticks(arange(0,41,10)) |
|
589 |
legend((p1[0], p2[0]), |
|
590 |
('Men', 'Women'), shadow=True) |
|
591 |
\end{lstlisting} |
|
592 |
\end{block} |
|
593 |
\end{columns} |
|
594 |
\end{frame} |
|
595 |
||
596 |
\begin{frame}[fragile] \frametitle{Pie charts} |
|
597 |
\begin{columns} |
|
598 |
\column{0.5\textwidth} |
|
599 |
\hspace*{-0.4in} |
|
600 |
\includegraphics[height=2.0in, interpolate=true]{data/piechart} |
|
601 |
\column{0.45\textwidth} |
|
602 |
\begin{block}{Example code} |
|
603 |
\tiny |
|
604 |
\begin{lstlisting} |
|
605 |
# make a square figure and axes |
|
606 |
figure(1, figsize=(8,8)) |
|
607 |
ax = axes([0.1, 0.1, 0.8, 0.8]) |
|
608 |
labels = 'Frogs', 'Hogs', 'Dogs', 'Logs' |
|
609 |
fracs = [15,30,45, 10] |
|
610 |
explode=(0, 0.05, 0, 0) |
|
611 |
pie(fracs, explode=explode, labels=labels, |
|
612 |
autopct='%1.1f%%', shadow=True) |
|
613 |
title('Raining Hogs and Dogs', |
|
614 |
bbox={'facecolor':'0.8', 'pad':5}) |
|
615 |
\end{lstlisting} |
|
616 |
\end{block} |
|
617 |
\end{columns} |
|
618 |
\end{frame} |
|
619 |
||
620 |
\begin{frame}[fragile] \frametitle{Scatter plots} |
|
621 |
\begin{columns} |
|
622 |
\column{0.5\textwidth} |
|
623 |
\hspace*{-0.4in} |
|
624 |
\includegraphics[height=2in, interpolate=true]{data/scatter} |
|
625 |
\column{0.45\textwidth} |
|
626 |
\begin{block}{Example code} |
|
627 |
\tiny |
|
628 |
\begin{lstlisting} |
|
629 |
N = 30 |
|
630 |
x = 0.9*rand(N) |
|
631 |
y = 0.9*rand(N) |
|
632 |
# 0 to 10 point radiuses |
|
633 |
area = pi*(10 * rand(N))**2 |
|
634 |
volume = 400 + rand(N)*450 |
|
635 |
scatter(x,y,s=area, marker='o', c=volume, |
|
636 |
alpha=0.75) |
|
637 |
xlabel(r'$\Delta_i$', size='x-large') |
|
638 |
ylabel(r'$\Delta_{i+1}$', size='x-large') |
|
639 |
title(r'Volume and percent change') |
|
640 |
grid(True) |
|
641 |
colorbar() |
|
642 |
savefig('scatter') |
|
643 |
\end{lstlisting} |
|
644 |
\end{block} |
|
645 |
\end{columns} |
|
646 |
\end{frame} |
|
647 |
||
648 |
\begin{frame}[fragile] \frametitle{Polar} |
|
649 |
\begin{columns} |
|
650 |
\column{0.5\textwidth} |
|
651 |
\hspace*{-0.5in} |
|
652 |
\includegraphics[height=2in, interpolate=true]{data/polar} |
|
653 |
\column{0.45\textwidth} |
|
654 |
\begin{block}{Example code} |
|
655 |
\tiny |
|
656 |
\begin{lstlisting} |
|
657 |
figure(figsize=(8,8)) |
|
658 |
ax = axes([0.1, 0.1, 0.8, 0.8], |
|
659 |
polar=True, |
|
660 |
axisbg='#d5de9c') |
|
661 |
r = arange(0,1,0.001) |
|
662 |
theta = 2*2*pi*r |
|
663 |
polar(theta, r, color='#ee8d18', lw=3) |
|
664 |
# the radius of the grid labels |
|
665 |
setp(ax.thetagridlabels, y=1.075) |
|
4
e5047bcbb608
Moved Array Math, Creation slides around; Added time counters.
Puneeth Chaganti <punchagan@fossee.in>
parents:
3
diff
changeset
|
666 |
title(r'$\theta=4\pi r$', fontsize=20) |
3 | 667 |
\end{lstlisting} |
4
e5047bcbb608
Moved Array Math, Creation slides around; Added time counters.
Puneeth Chaganti <punchagan@fossee.in>
parents:
3
diff
changeset
|
668 |
|
3 | 669 |
\end{block} |
670 |
\end{columns} |
|
671 |
\end{frame} |
|
672 |
||
673 |
\begin{frame}[fragile] \frametitle{Contours} |
|
674 |
\begin{columns} |
|
675 |
\column{0.45\textwidth} |
|
676 |
\hspace*{-0.5in} |
|
677 |
\includegraphics[height=2in, interpolate=true]{data/contour} |
|
678 |
\column{0.525\textwidth} |
|
679 |
\begin{block}{Example code} |
|
680 |
\tiny |
|
681 |
\begin{lstlisting} |
|
682 |
x = arange(-3.0, 3.0, 0.025) |
|
683 |
y = arange(-2.0, 2.0, 0.025) |
|
684 |
X, Y = meshgrid(x, y) |
|
685 |
Z1 = bivariate_normal(X, Y, 1.0, 1.0, 0.0, 0.0) |
|
686 |
Z2 = bivariate_normal(X, Y, 1.5, 0.5, 1, 1) |
|
687 |
# difference of Gaussians |
|
688 |
Z = 10.0 * (Z2 - Z1) |
|
689 |
im = imshow(Z, interpolation='bilinear', |
|
690 |
origin='lower', |
|
691 |
cmap=cm.gray, extent=(-3,3,-2,2)) |
|
692 |
levels = arange(-1.2, 1.6, 0.2) |
|
693 |
# label every second level |
|
694 |
clabel(CS, levels[1::2], inline=1, |
|
695 |
fmt='%1.1f', fontsize=14) |
|
696 |
CS = contour(Z, levels, |
|
697 |
origin='lower', |
|
698 |
linewidths=2, |
|
699 |
extent=(-3,3,-2,2)) |
|
700 |
# make a colorbar for the contour lines |
|
701 |
CB = colorbar(CS, shrink=0.8, extend='both') |
|
702 |
title('Lines with colorbar') |
|
703 |
hot(); flag() |
|
704 |
\end{lstlisting} |
|
705 |
\end{block} |
|
706 |
\end{columns} |
|
707 |
\end{frame} |
|
708 |
||
709 |
\begin{frame}[fragile] \frametitle{Velocity vectors} |
|
710 |
\begin{columns} |
|
711 |
\column{0.5\textwidth} |
|
712 |
\hspace*{-0.5in} |
|
713 |
\includegraphics[height=2in, interpolate=true]{data/quiver} |
|
714 |
\column{0.45\textwidth} |
|
715 |
\begin{block}{Example code} |
|
716 |
\tiny |
|
717 |
\begin{lstlisting} |
|
718 |
X,Y = meshgrid(arange(0,2*pi,.2), |
|
719 |
arange(0,2*pi,.2) ) |
|
720 |
U = cos(X) |
|
721 |
V = sin(Y) |
|
722 |
Q = quiver(X[::3, ::3], Y[::3, ::3], |
|
723 |
U[::3, ::3], V[::3, ::3], |
|
724 |
color='r', units='x', |
|
725 |
linewidths=(2,), |
|
726 |
edgecolors=('k'), |
|
727 |
headaxislength=5 ) |
|
728 |
qk = quiverkey(Q, 0.5, 0.03, 1, '1 m/s', |
|
729 |
fontproperties= |
|
730 |
{'weight': 'bold'}) |
|
731 |
axis([-1, 7, -1, 7]) |
|
732 |
title('triangular head; scale '\ |
|
733 |
'with x view; black edges') |
|
734 |
\end{lstlisting} |
|
735 |
\end{block} |
|
736 |
\end{columns} |
|
737 |
\end{frame} |
|
738 |
||
739 |
\begin{frame}[fragile] \frametitle{Maps} |
|
8 | 740 |
\includegraphics[height=2.3in, interpolate=true]{data/plotmap} |
3 | 741 |
\begin{center} |
742 |
\tiny |
|
743 |
For details see \url{http://matplotlib.sourceforge.net/screenshots/plotmap.py} |
|
744 |
\end{center} |
|
12 | 745 |
\inctime{5} |
3 | 746 |
\end{frame} |
747 |
||
748 |
||
749 |
\begin{frame} |
|
750 |
\frametitle{More information} |
|
751 |
\begin{itemize} |
|
752 |
\item More information here: \url{http://matplotlib.sf.net} |
|
753 |
\item \url{http://matplotlib.sf.net/tutorial.html} |
|
754 |
\item \url{http://matplotlib.sf.net/screenshots.html} |
|
755 |
\end{itemize} |
|
756 |
\end{frame} |
|
757 |
||
758 |
\begin{frame} |
|
9
2281002b579b
Edited Problem Sets - Added cobweb plot; Removed Koch.
Puneeth Chaganti <punchagan@fossee.in>
parents:
6
diff
changeset
|
759 |
\frametitle{Problem Set} |
3 | 760 |
\begin{enumerate} |
20 | 761 |
\item Write a function that plots any regular n-gon given \typ{n}. |
3 | 762 |
\item Consider the logistic map, $f(x) = kx(1-x)$, plot it for |
20 | 763 |
$k=2.5, 3.5$ and $4$ in the same plot. |
3 | 764 |
\end{enumerate} |
765 |
\end{frame} |
|
766 |
||
9
2281002b579b
Edited Problem Sets - Added cobweb plot; Removed Koch.
Puneeth Chaganti <punchagan@fossee.in>
parents:
6
diff
changeset
|
767 |
\begin{frame}[fragile] |
2281002b579b
Edited Problem Sets - Added cobweb plot; Removed Koch.
Puneeth Chaganti <punchagan@fossee.in>
parents:
6
diff
changeset
|
768 |
\frametitle{Problem Set} |
2281002b579b
Edited Problem Sets - Added cobweb plot; Removed Koch.
Puneeth Chaganti <punchagan@fossee.in>
parents:
6
diff
changeset
|
769 |
\begin{columns} |
2281002b579b
Edited Problem Sets - Added cobweb plot; Removed Koch.
Puneeth Chaganti <punchagan@fossee.in>
parents:
6
diff
changeset
|
770 |
\column{0.6\textwidth} |
2281002b579b
Edited Problem Sets - Added cobweb plot; Removed Koch.
Puneeth Chaganti <punchagan@fossee.in>
parents:
6
diff
changeset
|
771 |
\small{ |
2281002b579b
Edited Problem Sets - Added cobweb plot; Removed Koch.
Puneeth Chaganti <punchagan@fossee.in>
parents:
6
diff
changeset
|
772 |
\begin{enumerate} |
3 | 773 |
\item Consider the iteration $x_{n+1} = f(x_n)$ where $f(x) = |
774 |
kx(1-x)$. Plot the successive iterates of this process. |
|
775 |
\item Plot this using a cobweb plot as follows: |
|
776 |
\begin{enumerate} |
|
777 |
\item Start at $(x_0, 0)$ |
|
778 |
\item Draw line to $(x_i, f(x_i))$; |
|
779 |
\item Set $x_{i+1} = f(x_i)$ |
|
780 |
\item Draw line to $(x_i, x_i)$ |
|
781 |
\item Repeat from 2 for as long as you want |
|
782 |
\end{enumerate} |
|
9
2281002b579b
Edited Problem Sets - Added cobweb plot; Removed Koch.
Puneeth Chaganti <punchagan@fossee.in>
parents:
6
diff
changeset
|
783 |
\end{enumerate}} |
2281002b579b
Edited Problem Sets - Added cobweb plot; Removed Koch.
Puneeth Chaganti <punchagan@fossee.in>
parents:
6
diff
changeset
|
784 |
\column{0.35\textwidth} |
2281002b579b
Edited Problem Sets - Added cobweb plot; Removed Koch.
Puneeth Chaganti <punchagan@fossee.in>
parents:
6
diff
changeset
|
785 |
\hspace*{-0.5in} |
2281002b579b
Edited Problem Sets - Added cobweb plot; Removed Koch.
Puneeth Chaganti <punchagan@fossee.in>
parents:
6
diff
changeset
|
786 |
\includegraphics[height=1.6in, interpolate=true]{data/cobweb} |
2281002b579b
Edited Problem Sets - Added cobweb plot; Removed Koch.
Puneeth Chaganti <punchagan@fossee.in>
parents:
6
diff
changeset
|
787 |
\end{columns} |
2281002b579b
Edited Problem Sets - Added cobweb plot; Removed Koch.
Puneeth Chaganti <punchagan@fossee.in>
parents:
6
diff
changeset
|
788 |
\inctime{20} |
3 | 789 |
\end{frame} |
790 |
\end{document} |