author | Puneeth Chaganti <punchagan@fossee.in> |
Sat, 03 Oct 2009 19:47:43 +0530 | |
changeset 10 | 84c3f600045f |
parent 9 | 2281002b579b |
parent 8 | 41bdf277c755 |
child 12 | 996fb264fbe2 |
permissions | -rw-r--r-- |
3 | 1 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
2 |
% Tutorial slides on Python. |
|
3 |
% |
|
4 |
% Author: Prabhu Ramachandran <prabhu at aero.iitb.ac.in> |
|
5 |
% Copyright (c) 2005-2008, Prabhu Ramachandran |
|
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 |
||
54 |
\newcommand{\typ}[1]{\texttt{#1}} |
|
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 |
||
77 |
\author[Asokan \& Prabhu] {Asokan Pichai\\Prabhu Ramachandran} |
|
78 |
||
79 |
\institute[FOSSEE] {FOSSEE Team} |
|
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{+, -, *, /, \%} |
e5047bcbb608
Moved Array Math, Creation slides around; Added time counters.
Puneeth Chaganti <punchagan@fossee.in>
parents:
3
diff
changeset
|
217 |
\item Inplace operators: \typ{a += b}, or \typ{add(a, b, |
e5047bcbb608
Moved Array Math, Creation slides around; Added time counters.
Puneeth Chaganti <punchagan@fossee.in>
parents:
3
diff
changeset
|
218 |
a)} etc. |
e5047bcbb608
Moved Array Math, Creation slides around; Added time counters.
Puneeth Chaganti <punchagan@fossee.in>
parents:
3
diff
changeset
|
219 |
\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
|
220 |
\typ{less (<)}, \typ{greater (>)} etc. |
e5047bcbb608
Moved Array Math, Creation slides around; Added time counters.
Puneeth Chaganti <punchagan@fossee.in>
parents:
3
diff
changeset
|
221 |
\item Trig and other functions: \typ{sin(x), arcsin(x), sinh(x), |
e5047bcbb608
Moved Array Math, Creation slides around; Added time counters.
Puneeth Chaganti <punchagan@fossee.in>
parents:
3
diff
changeset
|
222 |
exp(x), sqrt(x)} etc. |
9
2281002b579b
Edited Problem Sets - Added cobweb plot; Removed Koch.
Puneeth Chaganti <punchagan@fossee.in>
parents:
6
diff
changeset
|
223 |
\item \typ{sum(x, axis=0), product(x, axis=0), dot(a, bp)} \inctime{10} |
4
e5047bcbb608
Moved Array Math, Creation slides around; Added time counters.
Puneeth Chaganti <punchagan@fossee.in>
parents:
3
diff
changeset
|
224 |
\end{itemize} |
e5047bcbb608
Moved Array Math, Creation slides around; Added time counters.
Puneeth Chaganti <punchagan@fossee.in>
parents:
3
diff
changeset
|
225 |
\inctime{10} |
e5047bcbb608
Moved Array Math, Creation slides around; Added time counters.
Puneeth Chaganti <punchagan@fossee.in>
parents:
3
diff
changeset
|
226 |
\end{frame} |
e5047bcbb608
Moved Array Math, Creation slides around; Added time counters.
Puneeth Chaganti <punchagan@fossee.in>
parents:
3
diff
changeset
|
227 |
|
e5047bcbb608
Moved Array Math, Creation slides around; Added time counters.
Puneeth Chaganti <punchagan@fossee.in>
parents:
3
diff
changeset
|
228 |
\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
|
229 |
\begin{frame}[fragile] |
e5047bcbb608
Moved Array Math, Creation slides around; Added time counters.
Puneeth Chaganti <punchagan@fossee.in>
parents:
3
diff
changeset
|
230 |
\frametitle{Array creation functions} |
e5047bcbb608
Moved Array Math, Creation slides around; Added time counters.
Puneeth Chaganti <punchagan@fossee.in>
parents:
3
diff
changeset
|
231 |
\begin{itemize} |
e5047bcbb608
Moved Array Math, Creation slides around; Added time counters.
Puneeth Chaganti <punchagan@fossee.in>
parents:
3
diff
changeset
|
232 |
\item \typ{array(object, dtype=None, \ldots)} |
e5047bcbb608
Moved Array Math, Creation slides around; Added time counters.
Puneeth Chaganti <punchagan@fossee.in>
parents:
3
diff
changeset
|
233 |
\item \typ{arange(start, stop=None, step=1 \ldots)} |
e5047bcbb608
Moved Array Math, Creation slides around; Added time counters.
Puneeth Chaganti <punchagan@fossee.in>
parents:
3
diff
changeset
|
234 |
\item \typ{linspace(start, stop, num=50, \ldots)} |
e5047bcbb608
Moved Array Math, Creation slides around; Added time counters.
Puneeth Chaganti <punchagan@fossee.in>
parents:
3
diff
changeset
|
235 |
\item \typ{ones(shape, dtype=None, \ldots)} |
e5047bcbb608
Moved Array Math, Creation slides around; Added time counters.
Puneeth Chaganti <punchagan@fossee.in>
parents:
3
diff
changeset
|
236 |
\item \typ{zeros(shape, dtype=float,\ldots)} |
e5047bcbb608
Moved Array Math, Creation slides around; Added time counters.
Puneeth Chaganti <punchagan@fossee.in>
parents:
3
diff
changeset
|
237 |
\item \typ{identity(n)} |
e5047bcbb608
Moved Array Math, Creation slides around; Added time counters.
Puneeth Chaganti <punchagan@fossee.in>
parents:
3
diff
changeset
|
238 |
\item \typ{empty(shape, dtype=float,\ldots)} |
e5047bcbb608
Moved Array Math, Creation slides around; Added time counters.
Puneeth Chaganti <punchagan@fossee.in>
parents:
3
diff
changeset
|
239 |
\item \typ{ones\_like(x)}, |
e5047bcbb608
Moved Array Math, Creation slides around; Added time counters.
Puneeth Chaganti <punchagan@fossee.in>
parents:
3
diff
changeset
|
240 |
\item \typ{zeros\_like(x)}, \typ{empty\_like(x)} |
e5047bcbb608
Moved Array Math, Creation slides around; Added time counters.
Puneeth Chaganti <punchagan@fossee.in>
parents:
3
diff
changeset
|
241 |
\end{itemize} |
e5047bcbb608
Moved Array Math, Creation slides around; Added time counters.
Puneeth Chaganti <punchagan@fossee.in>
parents:
3
diff
changeset
|
242 |
\end{frame} |
3 | 243 |
|
244 |
\begin{frame}[fragile] |
|
245 |
\frametitle{Slicing arrays} |
|
246 |
\begin{lstlisting} |
|
247 |
>>> a = array([[1,2,3], [4,5,6], |
|
248 |
[7,8,9]]) |
|
249 |
>>> a[0,1:3] |
|
250 |
array([2, 3]) |
|
251 |
>>> a[1:,1:] |
|
252 |
array([[5, 6], |
|
253 |
[8, 9]]) |
|
254 |
>>> a[:,2] |
|
255 |
array([3, 6, 9]) |
|
9
2281002b579b
Edited Problem Sets - Added cobweb plot; Removed Koch.
Puneeth Chaganti <punchagan@fossee.in>
parents:
6
diff
changeset
|
256 |
>>> a[...,2] |
2281002b579b
Edited Problem Sets - Added cobweb plot; Removed Koch.
Puneeth Chaganti <punchagan@fossee.in>
parents:
6
diff
changeset
|
257 |
array([3, 6, 9]) |
3 | 258 |
\end{lstlisting} |
259 |
\end{frame} |
|
4
e5047bcbb608
Moved Array Math, Creation slides around; Added time counters.
Puneeth Chaganti <punchagan@fossee.in>
parents:
3
diff
changeset
|
260 |
|
3 | 261 |
\begin{frame}[fragile] |
262 |
\frametitle{Striding arrays} |
|
263 |
\begin{lstlisting} |
|
264 |
>>> a[0::2,0::2] |
|
265 |
array([[1, 3], |
|
266 |
[7, 9]]) |
|
267 |
# Slices are references to the |
|
268 |
# same memory! |
|
269 |
\end{lstlisting} |
|
270 |
\end{frame} |
|
271 |
||
272 |
\begin{frame}[fragile] |
|
4
e5047bcbb608
Moved Array Math, Creation slides around; Added time counters.
Puneeth Chaganti <punchagan@fossee.in>
parents:
3
diff
changeset
|
273 |
\frametitle{Random Numbers} |
e5047bcbb608
Moved Array Math, Creation slides around; Added time counters.
Puneeth Chaganti <punchagan@fossee.in>
parents:
3
diff
changeset
|
274 |
\begin{lstlisting} |
e5047bcbb608
Moved Array Math, Creation slides around; Added time counters.
Puneeth Chaganti <punchagan@fossee.in>
parents:
3
diff
changeset
|
275 |
>>> np.random.rand(3,2) |
e5047bcbb608
Moved Array Math, Creation slides around; Added time counters.
Puneeth Chaganti <punchagan@fossee.in>
parents:
3
diff
changeset
|
276 |
array([[ 0.96276665, 0.77174861], |
e5047bcbb608
Moved Array Math, Creation slides around; Added time counters.
Puneeth Chaganti <punchagan@fossee.in>
parents:
3
diff
changeset
|
277 |
[ 0.35138557, 0.61462271], |
e5047bcbb608
Moved Array Math, Creation slides around; Added time counters.
Puneeth Chaganti <punchagan@fossee.in>
parents:
3
diff
changeset
|
278 |
[ 0.16789255, 0.43848811]]) |
e5047bcbb608
Moved Array Math, Creation slides around; Added time counters.
Puneeth Chaganti <punchagan@fossee.in>
parents:
3
diff
changeset
|
279 |
>>> np.random.randint(1,100) |
e5047bcbb608
Moved Array Math, Creation slides around; Added time counters.
Puneeth Chaganti <punchagan@fossee.in>
parents:
3
diff
changeset
|
280 |
42 |
e5047bcbb608
Moved Array Math, Creation slides around; Added time counters.
Puneeth Chaganti <punchagan@fossee.in>
parents:
3
diff
changeset
|
281 |
\end{lstlisting} |
e5047bcbb608
Moved Array Math, Creation slides around; Added time counters.
Puneeth Chaganti <punchagan@fossee.in>
parents:
3
diff
changeset
|
282 |
\inctime{15} |
3 | 283 |
\end{frame} |
284 |
||
285 |
\begin{frame}[fragile] |
|
6
1f9492506ba2
Added a problem after initial numpy section in session1.
Puneeth Chaganti <punchagan@fossee.in>
parents:
4
diff
changeset
|
286 |
\frametitle{Problem Set} |
1f9492506ba2
Added a problem after initial numpy section in session1.
Puneeth Chaganti <punchagan@fossee.in>
parents:
4
diff
changeset
|
287 |
\begin{lstlisting} |
1f9492506ba2
Added a problem after initial numpy section in session1.
Puneeth Chaganti <punchagan@fossee.in>
parents:
4
diff
changeset
|
288 |
>>> from scipy import misc |
1f9492506ba2
Added a problem after initial numpy section in session1.
Puneeth Chaganti <punchagan@fossee.in>
parents:
4
diff
changeset
|
289 |
>>> A=misc.imread(name) |
1f9492506ba2
Added a problem after initial numpy section in session1.
Puneeth Chaganti <punchagan@fossee.in>
parents:
4
diff
changeset
|
290 |
>>> misc.imshow(A) |
1f9492506ba2
Added a problem after initial numpy section in session1.
Puneeth Chaganti <punchagan@fossee.in>
parents:
4
diff
changeset
|
291 |
\end{lstlisting} |
1f9492506ba2
Added a problem after initial numpy section in session1.
Puneeth Chaganti <punchagan@fossee.in>
parents:
4
diff
changeset
|
292 |
\begin{enumerate} |
1f9492506ba2
Added a problem after initial numpy section in session1.
Puneeth Chaganti <punchagan@fossee.in>
parents:
4
diff
changeset
|
293 |
\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
|
294 |
\item Scale the image to 50\% |
2281002b579b
Edited Problem Sets - Added cobweb plot; Removed Koch.
Puneeth Chaganti <punchagan@fossee.in>
parents:
6
diff
changeset
|
295 |
\item Introduce some random noise? |
6
1f9492506ba2
Added a problem after initial numpy section in session1.
Puneeth Chaganti <punchagan@fossee.in>
parents:
4
diff
changeset
|
296 |
\end{enumerate} |
4
e5047bcbb608
Moved Array Math, Creation slides around; Added time counters.
Puneeth Chaganti <punchagan@fossee.in>
parents:
3
diff
changeset
|
297 |
\inctime{15} |
3 | 298 |
\end{frame} |
4
e5047bcbb608
Moved Array Math, Creation slides around; Added time counters.
Puneeth Chaganti <punchagan@fossee.in>
parents:
3
diff
changeset
|
299 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
3 | 300 |
|
301 |
\section{2D Plotting} |
|
302 |
\subsection{Getting Started} |
|
303 |
||
304 |
\begin{frame} |
|
305 |
{IPython's \typ{pylab} mode} |
|
306 |
\begin{itemize} |
|
307 |
\item \typ{pylab}: convenient 2D plotting interface to MPL |
|
308 |
\item Immediate use: \typ{ipython -pylab} |
|
309 |
\item Imports all of pylab for you! |
|
310 |
\item Allows for interactive plotting |
|
311 |
\end{itemize} |
|
312 |
\end{frame} |
|
313 |
||
314 |
\begin{frame}[fragile] |
|
315 |
\frametitle{Basic 2D plotting} |
|
316 |
||
317 |
\begin{lstlisting} |
|
318 |
>>> x = linspace(0, 2*pi, 1000) |
|
319 |
>>> plot(x, sin(x)) |
|
320 |
>>> plot(x, sin(x), 'ro') |
|
321 |
>>> xlabel(r'$\chi$', color='g') |
|
322 |
# LaTeX markup! |
|
323 |
>>> ylabel(r'sin($\chi$)', color='r') |
|
324 |
>>> title('Simple figure', fontsize=20) |
|
325 |
>>> savefig('/tmp/test.eps') |
|
326 |
\end{lstlisting} |
|
327 |
\begin{itemize} |
|
328 |
\item Also: PNG, PDF, PS, EPS, SVG, PDF |
|
329 |
\end{itemize} |
|
330 |
\end{frame} |
|
331 |
||
4
e5047bcbb608
Moved Array Math, Creation slides around; Added time counters.
Puneeth Chaganti <punchagan@fossee.in>
parents:
3
diff
changeset
|
332 |
\subsection{Plots - Lines, Labels and Legends} |
3 | 333 |
\begin{frame}[fragile] |
7
adcc40e2bf70
Made changes in plotting section.
Shantanu <shantanu@fossee.in>
parents:
6
diff
changeset
|
334 |
\frametitle{Basic plotting} |
3 | 335 |
\begin{lstlisting} |
336 |
# Set properties of objects: |
|
337 |
>>> l, = plot(x, sin(x)) |
|
338 |
# Why "l,"? |
|
339 |
>>> setp(l, linewidth=2.0, color='r') |
|
340 |
>>> l.set_linewidth(2.0) |
|
341 |
>>> draw() # Redraw. |
|
342 |
>>> setp(l) # Print properties |
|
343 |
>>> clf() # Clear figure. |
|
344 |
>>> close() # Close figure. |
|
345 |
\end{lstlisting} |
|
346 |
\end{frame} |
|
347 |
||
348 |
\begin{frame}[fragile] |
|
10 | 349 |
\frametitle{Working with text \ldots} |
7
adcc40e2bf70
Made changes in plotting section.
Shantanu <shantanu@fossee.in>
parents:
6
diff
changeset
|
350 |
%\begin{itemize} |
adcc40e2bf70
Made changes in plotting section.
Shantanu <shantanu@fossee.in>
parents:
6
diff
changeset
|
351 |
% \item We already saw LaTeX markup support! |
adcc40e2bf70
Made changes in plotting section.
Shantanu <shantanu@fossee.in>
parents:
6
diff
changeset
|
352 |
%\end{itemize} |
adcc40e2bf70
Made changes in plotting section.
Shantanu <shantanu@fossee.in>
parents:
6
diff
changeset
|
353 |
\begin{lstlisting} |
adcc40e2bf70
Made changes in plotting section.
Shantanu <shantanu@fossee.in>
parents:
6
diff
changeset
|
354 |
>>> w = arange(-2,2,.1) |
adcc40e2bf70
Made changes in plotting section.
Shantanu <shantanu@fossee.in>
parents:
6
diff
changeset
|
355 |
>>> plot(w,exp(-(w*w))*cos) |
adcc40e2bf70
Made changes in plotting section.
Shantanu <shantanu@fossee.in>
parents:
6
diff
changeset
|
356 |
>>> ylabel('$f(\omega)$') |
adcc40e2bf70
Made changes in plotting section.
Shantanu <shantanu@fossee.in>
parents:
6
diff
changeset
|
357 |
>>> xlabel('$\omega$') |
adcc40e2bf70
Made changes in plotting section.
Shantanu <shantanu@fossee.in>
parents:
6
diff
changeset
|
358 |
>>> title(r"$f(\omega)=e^{-\omega^2} |
adcc40e2bf70
Made changes in plotting section.
Shantanu <shantanu@fossee.in>
parents:
6
diff
changeset
|
359 |
cos({\omega^2})$") |
adcc40e2bf70
Made changes in plotting section.
Shantanu <shantanu@fossee.in>
parents:
6
diff
changeset
|
360 |
>>> annotate('maxima',xy=(0, 1), |
adcc40e2bf70
Made changes in plotting section.
Shantanu <shantanu@fossee.in>
parents:
6
diff
changeset
|
361 |
xytext=(1, 0.8), |
adcc40e2bf70
Made changes in plotting section.
Shantanu <shantanu@fossee.in>
parents:
6
diff
changeset
|
362 |
arrowprops=dict( |
adcc40e2bf70
Made changes in plotting section.
Shantanu <shantanu@fossee.in>
parents:
6
diff
changeset
|
363 |
facecolor='black', |
adcc40e2bf70
Made changes in plotting section.
Shantanu <shantanu@fossee.in>
parents:
6
diff
changeset
|
364 |
shrink=0.05)) |
adcc40e2bf70
Made changes in plotting section.
Shantanu <shantanu@fossee.in>
parents:
6
diff
changeset
|
365 |
\end{lstlisting} |
10 | 366 |
|
7
adcc40e2bf70
Made changes in plotting section.
Shantanu <shantanu@fossee.in>
parents:
6
diff
changeset
|
367 |
\end{frame} |
adcc40e2bf70
Made changes in plotting section.
Shantanu <shantanu@fossee.in>
parents:
6
diff
changeset
|
368 |
|
adcc40e2bf70
Made changes in plotting section.
Shantanu <shantanu@fossee.in>
parents:
6
diff
changeset
|
369 |
\begin{frame}[fragile] |
8 | 370 |
\frametitle{Legends} |
371 |
\begin{lstlisting} |
|
372 |
>>> plot(x, cos(5*x), 'r--', |
|
373 |
label='cosine') |
|
374 |
>>> plot(x, sin(5*x), 'g--', |
|
375 |
label='sine') |
|
376 |
>>> legend() |
|
377 |
# Or use: |
|
378 |
>>> legend(['cosine', 'sine']) |
|
10 | 379 |
# Annotation: |
380 |
>>> text(1,0, '(1,0)') |
|
8 | 381 |
\end{lstlisting} |
382 |
\end{frame} |
|
383 |
||
384 |
\begin{frame}[fragile] |
|
3 | 385 |
\frametitle{Multiple figures} |
386 |
||
387 |
\begin{lstlisting} |
|
388 |
>>> figure(1) |
|
389 |
>>> plot(x, sin(x)) |
|
390 |
>>> figure(2) |
|
391 |
>>> plot(x, tanh(x)) |
|
392 |
>>> figure(1) |
|
393 |
>>> title('Easy as 1,2,3') |
|
394 |
\end{lstlisting} |
|
395 |
||
396 |
||
397 |
\end{frame} |
|
398 |
||
399 |
\begin{frame}[fragile] |
|
400 |
\frametitle{Note: \typ{pylab} in Python scripts} |
|
401 |
\begin{lstlisting} |
|
402 |
import pylab |
|
403 |
x = pylab.linspace(0, 20, 1000) |
|
404 |
pylab.plot(x, pylab.sin(x)) |
|
405 |
||
406 |
# Can also use: |
|
407 |
from pylab import linspace, sin, plot |
|
408 |
\end{lstlisting} |
|
409 |
\end{frame} |
|
410 |
||
411 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
412 |
\subsection{Types of Plots} |
|
413 |
\begin{frame}[fragile] |
|
414 |
\frametitle{X-Y plot} |
|
415 |
\begin{columns} |
|
416 |
\column{0.5\textwidth} |
|
417 |
\hspace*{-0.5in} |
|
418 |
\includegraphics[height=2in, interpolate=true]{data/xyplot} |
|
419 |
\column{0.45\textwidth} |
|
420 |
\begin{block}{Example code} |
|
421 |
\tiny |
|
422 |
\begin{lstlisting} |
|
423 |
t1 = arange(0.0, 5.0, 0.1) |
|
424 |
t2 = arange(0.0, 5.0, 0.02) |
|
425 |
t3 = arange(0.0, 2.0, 0.01) |
|
426 |
subplot(211) |
|
427 |
plot(t1, cos(2*pi*t1)*exp(-t1), 'bo', |
|
428 |
t2, cos(2*pi*t2)*exp(-t2), 'k') |
|
429 |
grid(True) |
|
430 |
title('A tale of 2 subplots') |
|
431 |
ylabel('Damped') |
|
432 |
subplot(212) |
|
433 |
plot(t3, cos(2*pi*t3), 'r--') |
|
434 |
grid(True) |
|
435 |
xlabel('time (s)') |
|
436 |
ylabel('Undamped') |
|
437 |
\end{lstlisting} |
|
438 |
\end{block} |
|
439 |
\end{columns} |
|
440 |
\end{frame} |
|
441 |
||
442 |
\begin{frame}[fragile] \frametitle{Semi-log and log-log plots} |
|
443 |
\begin{columns} |
|
444 |
\column{0.5\textwidth} |
|
445 |
\hspace*{-0.5in} |
|
446 |
\includegraphics[height=2in, interpolate=true]{data/log} |
|
447 |
\column{0.45\textwidth} |
|
448 |
\begin{block}{Example code} |
|
449 |
\tiny |
|
450 |
\begin{lstlisting} |
|
451 |
dt = 0.01 |
|
452 |
t = arange(dt, 20.0, dt) |
|
453 |
subplot(311) |
|
454 |
semilogy(t, exp(-t/5.0)) |
|
455 |
ylabel('semilogy') |
|
456 |
grid(True) |
|
457 |
subplot(312) |
|
458 |
semilogx(t, sin(2*pi*t)) |
|
459 |
ylabel('semilogx') |
|
460 |
grid(True) |
|
461 |
# minor grid on too |
|
462 |
gca().xaxis.grid(True, which='minor') |
|
463 |
subplot(313) |
|
464 |
loglog(t, 20*exp(-t/10.0), basex=4) |
|
465 |
grid(True) |
|
466 |
ylabel('loglog base 4 on x') |
|
467 |
\end{lstlisting} |
|
468 |
\end{block} |
|
469 |
\end{columns} |
|
470 |
\end{frame} |
|
471 |
||
472 |
\begin{frame}[fragile] \frametitle{Errorbar} |
|
473 |
\begin{columns} |
|
474 |
\column{0.5\textwidth} |
|
475 |
\hspace*{-0.5in} |
|
476 |
\includegraphics[height=2in, interpolate=true]{data/errorbar} |
|
477 |
\column{0.45\textwidth} |
|
478 |
\begin{block}{Example code} |
|
479 |
\tiny |
|
480 |
\begin{lstlisting} |
|
481 |
t = arange(0.1, 4, 0.1) |
|
482 |
s = exp(-t) |
|
483 |
e = 0.1*abs(randn(len(s))) |
|
484 |
f = 0.1*abs(randn(len(s))) |
|
485 |
g = 2*e |
|
486 |
h = 2*f |
|
487 |
errorbar(t, s, [e,g], f, fmt='o') |
|
488 |
xlabel('Distance (m)') |
|
489 |
ylabel('Height (m)') |
|
490 |
title('Mean and standard error '\ |
|
491 |
'as a function of distance') |
|
492 |
\end{lstlisting} |
|
493 |
\end{block} |
|
494 |
\end{columns} |
|
495 |
\end{frame} |
|
496 |
||
497 |
\begin{frame}[fragile] \frametitle{Histogram} |
|
498 |
\begin{columns} |
|
499 |
\column{0.5\textwidth} |
|
500 |
\hspace*{-0.5in} |
|
501 |
\includegraphics[height=2in, interpolate=true]{data/histogram} |
|
502 |
\column{0.45\textwidth} |
|
503 |
\begin{block}{Example code} |
|
504 |
\tiny |
|
505 |
\begin{lstlisting} |
|
506 |
mu, sigma = 100, 15 |
|
507 |
x = mu + sigma*randn(10000) |
|
508 |
# the histogram of the data |
|
509 |
n, bins, patches = hist(x, 100, normed=1) |
|
510 |
# add a 'best fit' line |
|
511 |
y = normpdf( bins, mu, sigma) |
|
512 |
l = plot(bins, y, 'r--', linewidth=2) |
|
513 |
xlim(40, 160) |
|
514 |
xlabel('Smarts') |
|
515 |
ylabel('P') |
|
516 |
title(r'$\rm{IQ:}\/ \mu=100,\/ \sigma=15$') |
|
517 |
\end{lstlisting} |
|
518 |
\end{block} |
|
519 |
\end{columns} |
|
520 |
\end{frame} |
|
521 |
||
522 |
\begin{frame}[fragile] \frametitle{Bar charts} |
|
523 |
\begin{columns} |
|
524 |
\column{0.5\textwidth} |
|
525 |
\hspace*{-0.5in} |
|
526 |
\includegraphics[height=2in, interpolate=true]{data/barchart} |
|
527 |
\column{0.45\textwidth} |
|
528 |
\begin{block}{Example code} |
|
529 |
\tiny |
|
530 |
\begin{lstlisting} |
|
531 |
N = 5 |
|
532 |
menMeans = (20, 35, 30, 35, 27) |
|
533 |
menStd = ( 2, 3, 4, 1, 2) |
|
534 |
# the x locations for the groups |
|
535 |
ind = arange(N) |
|
536 |
# the width of the bars |
|
537 |
width = 0.35 |
|
538 |
p1 = bar(ind, menMeans, width, |
|
539 |
color='r', yerr=menStd) |
|
540 |
womenMeans = (25, 32, 34, 20, 25) |
|
541 |
womenStd = ( 3, 5, 2, 3, 3) |
|
542 |
p2 = bar(ind+width, womenMeans, width, |
|
543 |
color='y', yerr=womenStd) |
|
544 |
ylabel('Scores') |
|
545 |
title('Scores by group and gender') |
|
546 |
xticks(ind+width, |
|
547 |
('G1', 'G2', 'G3', 'G4', 'G5')) |
|
548 |
xlim(-width,len(ind)) |
|
549 |
yticks(arange(0,41,10)) |
|
550 |
legend((p1[0], p2[0]), |
|
551 |
('Men', 'Women'), shadow=True) |
|
552 |
\end{lstlisting} |
|
553 |
\end{block} |
|
554 |
\end{columns} |
|
555 |
\end{frame} |
|
556 |
||
557 |
\begin{frame}[fragile] \frametitle{Pie charts} |
|
558 |
\begin{columns} |
|
559 |
\column{0.5\textwidth} |
|
560 |
\hspace*{-0.4in} |
|
561 |
\includegraphics[height=2.0in, interpolate=true]{data/piechart} |
|
562 |
\column{0.45\textwidth} |
|
563 |
\begin{block}{Example code} |
|
564 |
\tiny |
|
565 |
\begin{lstlisting} |
|
566 |
# make a square figure and axes |
|
567 |
figure(1, figsize=(8,8)) |
|
568 |
ax = axes([0.1, 0.1, 0.8, 0.8]) |
|
569 |
labels = 'Frogs', 'Hogs', 'Dogs', 'Logs' |
|
570 |
fracs = [15,30,45, 10] |
|
571 |
explode=(0, 0.05, 0, 0) |
|
572 |
pie(fracs, explode=explode, labels=labels, |
|
573 |
autopct='%1.1f%%', shadow=True) |
|
574 |
title('Raining Hogs and Dogs', |
|
575 |
bbox={'facecolor':'0.8', 'pad':5}) |
|
576 |
\end{lstlisting} |
|
577 |
\end{block} |
|
578 |
\end{columns} |
|
579 |
\end{frame} |
|
580 |
||
581 |
\begin{frame}[fragile] \frametitle{Scatter plots} |
|
582 |
\begin{columns} |
|
583 |
\column{0.5\textwidth} |
|
584 |
\hspace*{-0.4in} |
|
585 |
\includegraphics[height=2in, interpolate=true]{data/scatter} |
|
586 |
\column{0.45\textwidth} |
|
587 |
\begin{block}{Example code} |
|
588 |
\tiny |
|
589 |
\begin{lstlisting} |
|
590 |
N = 30 |
|
591 |
x = 0.9*rand(N) |
|
592 |
y = 0.9*rand(N) |
|
593 |
# 0 to 10 point radiuses |
|
594 |
area = pi*(10 * rand(N))**2 |
|
595 |
volume = 400 + rand(N)*450 |
|
596 |
scatter(x,y,s=area, marker='o', c=volume, |
|
597 |
alpha=0.75) |
|
598 |
xlabel(r'$\Delta_i$', size='x-large') |
|
599 |
ylabel(r'$\Delta_{i+1}$', size='x-large') |
|
600 |
title(r'Volume and percent change') |
|
601 |
grid(True) |
|
602 |
colorbar() |
|
603 |
savefig('scatter') |
|
604 |
\end{lstlisting} |
|
605 |
\end{block} |
|
606 |
\end{columns} |
|
607 |
\end{frame} |
|
608 |
||
609 |
\begin{frame}[fragile] \frametitle{Polar} |
|
610 |
\begin{columns} |
|
611 |
\column{0.5\textwidth} |
|
612 |
\hspace*{-0.5in} |
|
613 |
\includegraphics[height=2in, interpolate=true]{data/polar} |
|
614 |
\column{0.45\textwidth} |
|
615 |
\begin{block}{Example code} |
|
616 |
\tiny |
|
617 |
\begin{lstlisting} |
|
618 |
figure(figsize=(8,8)) |
|
619 |
ax = axes([0.1, 0.1, 0.8, 0.8], |
|
620 |
polar=True, |
|
621 |
axisbg='#d5de9c') |
|
622 |
r = arange(0,1,0.001) |
|
623 |
theta = 2*2*pi*r |
|
624 |
polar(theta, r, color='#ee8d18', lw=3) |
|
625 |
# the radius of the grid labels |
|
626 |
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
|
627 |
title(r'$\theta=4\pi r$', fontsize=20) |
3 | 628 |
\end{lstlisting} |
4
e5047bcbb608
Moved Array Math, Creation slides around; Added time counters.
Puneeth Chaganti <punchagan@fossee.in>
parents:
3
diff
changeset
|
629 |
|
3 | 630 |
\end{block} |
631 |
\end{columns} |
|
632 |
\end{frame} |
|
633 |
||
634 |
\begin{frame}[fragile] \frametitle{Contours} |
|
635 |
\begin{columns} |
|
636 |
\column{0.45\textwidth} |
|
637 |
\hspace*{-0.5in} |
|
638 |
\includegraphics[height=2in, interpolate=true]{data/contour} |
|
639 |
\column{0.525\textwidth} |
|
640 |
\begin{block}{Example code} |
|
641 |
\tiny |
|
642 |
\begin{lstlisting} |
|
643 |
x = arange(-3.0, 3.0, 0.025) |
|
644 |
y = arange(-2.0, 2.0, 0.025) |
|
645 |
X, Y = meshgrid(x, y) |
|
646 |
Z1 = bivariate_normal(X, Y, 1.0, 1.0, 0.0, 0.0) |
|
647 |
Z2 = bivariate_normal(X, Y, 1.5, 0.5, 1, 1) |
|
648 |
# difference of Gaussians |
|
649 |
Z = 10.0 * (Z2 - Z1) |
|
650 |
im = imshow(Z, interpolation='bilinear', |
|
651 |
origin='lower', |
|
652 |
cmap=cm.gray, extent=(-3,3,-2,2)) |
|
653 |
levels = arange(-1.2, 1.6, 0.2) |
|
654 |
# label every second level |
|
655 |
clabel(CS, levels[1::2], inline=1, |
|
656 |
fmt='%1.1f', fontsize=14) |
|
657 |
CS = contour(Z, levels, |
|
658 |
origin='lower', |
|
659 |
linewidths=2, |
|
660 |
extent=(-3,3,-2,2)) |
|
661 |
# make a colorbar for the contour lines |
|
662 |
CB = colorbar(CS, shrink=0.8, extend='both') |
|
663 |
title('Lines with colorbar') |
|
664 |
hot(); flag() |
|
665 |
\end{lstlisting} |
|
666 |
\end{block} |
|
667 |
\end{columns} |
|
668 |
\end{frame} |
|
669 |
||
670 |
\begin{frame}[fragile] \frametitle{Velocity vectors} |
|
671 |
\begin{columns} |
|
672 |
\column{0.5\textwidth} |
|
673 |
\hspace*{-0.5in} |
|
674 |
\includegraphics[height=2in, interpolate=true]{data/quiver} |
|
675 |
\column{0.45\textwidth} |
|
676 |
\begin{block}{Example code} |
|
677 |
\tiny |
|
678 |
\begin{lstlisting} |
|
679 |
X,Y = meshgrid(arange(0,2*pi,.2), |
|
680 |
arange(0,2*pi,.2) ) |
|
681 |
U = cos(X) |
|
682 |
V = sin(Y) |
|
683 |
Q = quiver(X[::3, ::3], Y[::3, ::3], |
|
684 |
U[::3, ::3], V[::3, ::3], |
|
685 |
color='r', units='x', |
|
686 |
linewidths=(2,), |
|
687 |
edgecolors=('k'), |
|
688 |
headaxislength=5 ) |
|
689 |
qk = quiverkey(Q, 0.5, 0.03, 1, '1 m/s', |
|
690 |
fontproperties= |
|
691 |
{'weight': 'bold'}) |
|
692 |
axis([-1, 7, -1, 7]) |
|
693 |
title('triangular head; scale '\ |
|
694 |
'with x view; black edges') |
|
695 |
\end{lstlisting} |
|
696 |
\end{block} |
|
697 |
\end{columns} |
|
698 |
\end{frame} |
|
699 |
||
700 |
\begin{frame}[fragile] \frametitle{Maps} |
|
8 | 701 |
\includegraphics[height=2.3in, interpolate=true]{data/plotmap} |
3 | 702 |
\begin{center} |
703 |
\tiny |
|
704 |
For details see \url{http://matplotlib.sourceforge.net/screenshots/plotmap.py} |
|
705 |
\end{center} |
|
706 |
\end{frame} |
|
707 |
||
708 |
||
709 |
\begin{frame} |
|
710 |
\frametitle{More information} |
|
711 |
\begin{itemize} |
|
712 |
\item More information here: \url{http://matplotlib.sf.net} |
|
713 |
\item \url{http://matplotlib.sf.net/tutorial.html} |
|
714 |
\item \url{http://matplotlib.sf.net/screenshots.html} |
|
715 |
\end{itemize} |
|
716 |
||
717 |
\inctime{25} |
|
718 |
\end{frame} |
|
719 |
||
720 |
\begin{frame} |
|
9
2281002b579b
Edited Problem Sets - Added cobweb plot; Removed Koch.
Puneeth Chaganti <punchagan@fossee.in>
parents:
6
diff
changeset
|
721 |
\frametitle{Problem Set} |
3 | 722 |
\begin{enumerate} |
723 |
\item Write a function that plots any n-gon given \typ{n}. |
|
724 |
\item Consider the logistic map, $f(x) = kx(1-x)$, plot it for |
|
725 |
$k=2.5, 3.5$ and $4$ |
|
726 |
\end{enumerate} |
|
727 |
\end{frame} |
|
728 |
||
9
2281002b579b
Edited Problem Sets - Added cobweb plot; Removed Koch.
Puneeth Chaganti <punchagan@fossee.in>
parents:
6
diff
changeset
|
729 |
\begin{frame}[fragile] |
2281002b579b
Edited Problem Sets - Added cobweb plot; Removed Koch.
Puneeth Chaganti <punchagan@fossee.in>
parents:
6
diff
changeset
|
730 |
\frametitle{Problem Set} |
2281002b579b
Edited Problem Sets - Added cobweb plot; Removed Koch.
Puneeth Chaganti <punchagan@fossee.in>
parents:
6
diff
changeset
|
731 |
\begin{columns} |
2281002b579b
Edited Problem Sets - Added cobweb plot; Removed Koch.
Puneeth Chaganti <punchagan@fossee.in>
parents:
6
diff
changeset
|
732 |
\column{0.6\textwidth} |
2281002b579b
Edited Problem Sets - Added cobweb plot; Removed Koch.
Puneeth Chaganti <punchagan@fossee.in>
parents:
6
diff
changeset
|
733 |
\small{ |
2281002b579b
Edited Problem Sets - Added cobweb plot; Removed Koch.
Puneeth Chaganti <punchagan@fossee.in>
parents:
6
diff
changeset
|
734 |
\begin{enumerate} |
3 | 735 |
\item Consider the iteration $x_{n+1} = f(x_n)$ where $f(x) = |
736 |
kx(1-x)$. Plot the successive iterates of this process. |
|
737 |
\item Plot this using a cobweb plot as follows: |
|
738 |
\begin{enumerate} |
|
739 |
\item Start at $(x_0, 0)$ |
|
740 |
\item Draw line to $(x_i, f(x_i))$; |
|
741 |
\item Set $x_{i+1} = f(x_i)$ |
|
742 |
\item Draw line to $(x_i, x_i)$ |
|
743 |
\item Repeat from 2 for as long as you want |
|
744 |
\end{enumerate} |
|
9
2281002b579b
Edited Problem Sets - Added cobweb plot; Removed Koch.
Puneeth Chaganti <punchagan@fossee.in>
parents:
6
diff
changeset
|
745 |
\end{enumerate}} |
2281002b579b
Edited Problem Sets - Added cobweb plot; Removed Koch.
Puneeth Chaganti <punchagan@fossee.in>
parents:
6
diff
changeset
|
746 |
\column{0.35\textwidth} |
2281002b579b
Edited Problem Sets - Added cobweb plot; Removed Koch.
Puneeth Chaganti <punchagan@fossee.in>
parents:
6
diff
changeset
|
747 |
\hspace*{-0.5in} |
2281002b579b
Edited Problem Sets - Added cobweb plot; Removed Koch.
Puneeth Chaganti <punchagan@fossee.in>
parents:
6
diff
changeset
|
748 |
\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
|
749 |
\end{columns} |
2281002b579b
Edited Problem Sets - Added cobweb plot; Removed Koch.
Puneeth Chaganti <punchagan@fossee.in>
parents:
6
diff
changeset
|
750 |
\inctime{20} |
3 | 751 |
\end{frame} |
752 |
||
753 |
\end{document} |