|
1 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
2 %Tutorial slides on Python. |
|
3 % |
|
4 % Author: Prabhu Ramachandran <prabhu at aero.iitb.ac.in> |
|
5 % Copyright (c) 2005-2009, 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 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
75 % Title page |
|
76 \title[Exercises]{Exercises} |
|
77 |
|
78 \author[FOSSEE] {FOSSEE} |
|
79 |
|
80 \institute[IIT Bombay] {Department of Aerospace Engineering\\IIT Bombay} |
|
81 \date[] {1, November 2009\\Day 2} |
|
82 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
83 |
|
84 %\pgfdeclareimage[height=0.75cm]{iitmlogo}{iitmlogo} |
|
85 %\logo{\pgfuseimage{iitmlogo}} |
|
86 |
|
87 |
|
88 %% Delete this, if you do not want the table of contents to pop up at |
|
89 %% the beginning of each subsection: |
|
90 \AtBeginSubsection[] |
|
91 { |
|
92 \begin{frame}<beamer> |
|
93 \frametitle{Outline} |
|
94 \tableofcontents[currentsection,currentsubsection] |
|
95 \end{frame} |
|
96 } |
|
97 |
|
98 |
|
99 % If you wish to uncover everything in a step-wise fashion, uncomment |
|
100 % the following command: |
|
101 %\beamerdefaultoverlayspecification{<+->} |
|
102 |
|
103 %\includeonlyframes{current,current1,current2,current3,current4,current5,current6} |
|
104 |
|
105 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
106 % DOCUMENT STARTS |
|
107 \begin{document} |
|
108 |
|
109 \begin{frame} |
|
110 \titlepage |
|
111 \end{frame} |
|
112 |
|
113 \begin{frame}{Problem 1.1} |
|
114 The aliquot of a number is defined as: the sum of the \emph{proper} divisors of the number. For example, aliquot(12) = 1 + 2 + 3 + 4 + 6 = 16.\\ |
|
115 Write a function that returns the aliquot number of a given number. |
|
116 \end{frame} |
|
117 |
|
118 \begin{frame}{Problem 1.2} |
|
119 A pair of numbers (a, b) is said to be \alert{amicable} if the aliquot number of a is b and the aliquot number of b is a.\\ |
|
120 Example: \texttt{220, 284}\\ |
|
121 Write a program that prints all four digit amicable pairs. |
|
122 |
|
123 \inctime{20} |
|
124 \end{frame} |
|
125 |
|
126 %% \begin{frame}{Problem 2} |
|
127 %% Given an empty chessboard and one Bishop placed in any s%quare, say (r, c), generate the list of all squares the Bi%shop could move to. |
|
128 |
|
129 %% \end{frame} |
|
130 |
|
131 \begin{frame}[fragile] |
|
132 \frametitle{Problem Set 2} |
|
133 Given a string like, ``1, 3-7, 12, 15, 18-21'', produce the list \\ |
|
134 \begin{lstlisting} |
|
135 [1,3,4,5,6,7,12,15,18,19,20,21] |
|
136 \end{lstlisting} |
|
137 \inctime{10} |
|
138 \end{frame} |
|
139 |
|
140 \begin{frame} |
|
141 \frametitle{Problem Set 3} |
|
142 \begin{description} |
|
143 \item[3.1] Count word frequencies in a file. |
|
144 \end{description} |
|
145 \inctime{5} |
|
146 \end{frame} |
|
147 |
|
148 \begin{frame}[fragile] |
|
149 \frametitle{Problem set 4} |
|
150 Finite difference |
|
151 \begin{equation*} |
|
152 \frac{sin(x+h)-sin(x)}{h} |
|
153 \end{equation*} |
|
154 \begin{lstlisting} |
|
155 >>> x = linspace(0,2*pi,100) |
|
156 >>> y = sin(x) |
|
157 >>> deltax = x[1] - x[0] |
|
158 \end{lstlisting} |
|
159 \pause |
|
160 \begin{enumerate} |
|
161 \item Given this, get the finite difference of sin in the range 0 to 2*pi |
|
162 \end{enumerate} |
|
163 \end{frame} |
|
164 |
|
165 \begin{frame} |
|
166 \frametitle{Problem Set 5} |
|
167 \begin{itemize} |
|
168 \item[5.1] Write a function that plots any regular n-gon given \typ{n}. |
|
169 \item[5.2] Consider the logistic map, $f(x) = kx(1-x)$, plot it for |
|
170 $k=2.5, 3.5$ and $4$ in the same plot. |
|
171 \end{itemize} |
|
172 \end{frame} |
|
173 |
|
174 \begin{frame}[fragile] |
|
175 \frametitle{Problem Set 5} |
|
176 \begin{columns} |
|
177 \column{0.6\textwidth} |
|
178 \small{ |
|
179 \begin{itemize} |
|
180 \item[3] Consider the iteration $x_{n+1} = f(x_n)$ where $f(x) = kx(1-x)$. Plot the successive iterates of this process as explained below. |
|
181 \end{itemize}} |
|
182 \column{0.35\textwidth} |
|
183 \hspace*{-0.5in} |
|
184 \includegraphics[height=1.6in, interpolate=true]{data/cobweb} |
|
185 \end{columns} |
|
186 \end{frame} |
|
187 |
|
188 \begin{frame} |
|
189 \frametitle{Problem Set 5.3} |
|
190 Plot the cobweb plot as follows: |
|
191 \begin{enumerate} |
|
192 \item Start at $(x_0, 0)$ ($\implies$ i=0) |
|
193 \item Draw a line to $(x_i, f(x_i))$ |
|
194 \item Set $x_{i+1} = f(x_i)$ |
|
195 \item Draw a line to $(x_{i+1}, x_{i+1})$ |
|
196 \item $(i\implies i+1)$ |
|
197 \item Repeat from 2 for as long as you want |
|
198 \end{enumerate} |
|
199 \inctime{20} |
|
200 \end{frame} |
|
201 |
|
202 \end{document} |