288
|
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{infolines}
|
|
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, Session 4}
|
|
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:
|
|
115 |
\center{aliquot(12) = 1 + 2 + 3 + 4 + 6 = 16.}\\
|
|
116 |
Write a function that returns the aliquot number of a given number.
|
|
117 |
\end{frame}
|
|
118 |
|
|
119 |
\begin{frame}{Problem 1.2}
|
|
120 |
Pair of numbers (a, b) is said to be \alert{amicable} if aliquot number of a is b and aliquot number of b is a.\\
|
|
121 |
Example: \texttt{220, 284}\\
|
|
122 |
Write a program that prints all four digit amicable pairs.
|
|
123 |
|
|
124 |
\inctime{20}
|
|
125 |
\end{frame}
|
|
126 |
|
|
127 |
%% \begin{frame}{Problem 2}
|
|
128 |
%% 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.
|
|
129 |
|
|
130 |
%% \end{frame}
|
|
131 |
|
|
132 |
\begin{frame}[fragile]
|
|
133 |
\frametitle{Problem Set 2}
|
|
134 |
Given a string like, ``1, 3-7, 12, 15, 18-21'', produce the list \\
|
|
135 |
\begin{lstlisting}
|
|
136 |
[1,3,4,5,6,7,12,15,18,19,20,21]
|
|
137 |
\end{lstlisting}
|
|
138 |
\inctime{10}
|
|
139 |
\end{frame}
|
|
140 |
|
|
141 |
\begin{frame}
|
|
142 |
\frametitle{Problem Set 3}
|
|
143 |
\begin{description}
|
|
144 |
\item[3.1] Count word frequencies in a file.
|
|
145 |
\end{description}
|
|
146 |
\inctime{5}
|
|
147 |
\end{frame}
|
|
148 |
|
|
149 |
\begin{frame}[fragile]
|
|
150 |
\frametitle{Problem set 4}
|
|
151 |
Central difference
|
|
152 |
\begin{equation*}
|
|
153 |
\frac{sin(x+h)-sin(x-h)}{2h}
|
|
154 |
\end{equation*}
|
|
155 |
\begin{lstlisting}
|
|
156 |
In []: x = linspace(0, 2*pi, 100)
|
|
157 |
In []: y = sin(x)
|
|
158 |
In []: deltax = x[1] - x[0]
|
|
159 |
\end{lstlisting}
|
|
160 |
\pause
|
|
161 |
\begin{enumerate}
|
|
162 |
\item Given this, get the finite difference of sin in the range 0 to 2*pi
|
|
163 |
\end{enumerate}
|
|
164 |
\end{frame}
|
|
165 |
|
|
166 |
\begin{frame}
|
|
167 |
\frametitle{Problem Set 5}
|
|
168 |
\begin{itemize}
|
|
169 |
\item[5.1] Write a function that plots any regular n-gon given \typ{n}.
|
|
170 |
\item[5.2] Consider the logistic map, $f(x) = kx(1-x)$, plot it for
|
|
171 |
$k=2.5, 3.5$ and $4$ in the same plot.
|
|
172 |
\end{itemize}
|
|
173 |
\end{frame}
|
|
174 |
|
|
175 |
\begin{frame}[fragile]
|
|
176 |
\frametitle{Problem Set 5}
|
|
177 |
\begin{columns}
|
|
178 |
\column{0.6\textwidth}
|
|
179 |
\small{
|
|
180 |
\begin{itemize}
|
|
181 |
\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.
|
|
182 |
\end{itemize}}
|
|
183 |
\column{0.35\textwidth}
|
|
184 |
\hspace*{-0.5in}
|
|
185 |
\includegraphics[height=1.6in, interpolate=true]{data/cobweb}
|
|
186 |
\end{columns}
|
|
187 |
\end{frame}
|
|
188 |
|
|
189 |
\begin{frame}
|
|
190 |
\frametitle{Problem Set 5.3}
|
|
191 |
Plot the cobweb plot as follows:
|
|
192 |
\begin{enumerate}
|
|
193 |
\item Start at $(x_0, 0)$ ($\implies$ i=0)
|
|
194 |
\item Draw a line to $(x_i, f(x_i))$
|
|
195 |
\item Set $x_{i+1} = f(x_i)$
|
|
196 |
\item Draw a line to $(x_{i+1}, x_{i+1})$
|
|
197 |
\item $(i\implies i+1)$
|
|
198 |
\item Repeat from 2 for as long as you want
|
|
199 |
\end{enumerate}
|
|
200 |
\inctime{20}
|
|
201 |
\end{frame}
|
|
202 |
|
|
203 |
\end{document}
|