day2/exercises.tex
changeset 297 a835affb1447
child 330 46533051b9d3
equal deleted inserted replaced
296:2d08c45681a1 297:a835affb1447
       
     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[] {8 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:\\
       
   115 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 2}
       
   134   Given a string of numbers like, ``1, 3-7, 12, 15, 18-21'', produce the following 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 3}
       
   143   Count frequencies of words in a file.
       
   144 \inctime{25}
       
   145 \end{frame}
       
   146 
       
   147 \begin{frame}[fragile]
       
   148   \frametitle{Problem set 4}
       
   149   Central difference
       
   150   \begin{equation*}
       
   151   \frac{sin(x+h)-sin(x-h)}{2h}
       
   152   \end{equation*}
       
   153   \begin{lstlisting}
       
   154   In []: x = linspace(0, 2*pi, 100)
       
   155   In []: y = sin(x)
       
   156   In []: deltax = x[1] - x[0]
       
   157   \end{lstlisting}
       
   158   \pause
       
   159     \begin{enumerate}
       
   160       \item Given this, get the finite difference of sin in the range 0 to 2*pi
       
   161     \end{enumerate}
       
   162 \end{frame}
       
   163 
       
   164 \begin{frame}
       
   165   \frametitle{Problem Set 5}
       
   166   \begin{itemize}
       
   167       \item[5.1] Write a function that plots any regular n-gon given \typ{n}.
       
   168       \item[5.2] Consider the logistic map, $f(x) = kx(1-x)$, plot it for
       
   169           $k=2.5, 3.5$ and $4$ in the same plot.
       
   170 \end{itemize}
       
   171 \end{frame}
       
   172 
       
   173 \begin{frame}[fragile] 
       
   174 \frametitle{Problem Set 5}
       
   175   \begin{columns}
       
   176     \column{0.6\textwidth}
       
   177     \small{
       
   178     \begin{itemize}
       
   179       \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. 
       
   180     \end{itemize}}
       
   181     \column{0.35\textwidth}
       
   182     \hspace*{-0.5in}
       
   183   \includegraphics[height=1.6in, interpolate=true]{data/cobweb}  
       
   184 \end{columns}
       
   185 \end{frame}
       
   186 
       
   187 \begin{frame}
       
   188   \frametitle{Problem Set 5.3}
       
   189   Plot the cobweb plot as follows:
       
   190   \begin{enumerate}
       
   191     \item Start at $(x_0, 0)$ ($\implies$ i=0)
       
   192     \item Draw a line to $(x_i, f(x_i))$
       
   193     \item Set $x_{i+1} = f(x_i)$
       
   194     \item Draw a line to $(x_{i+1}, x_{i+1})$
       
   195     \item $(i\implies i+1)$ 
       
   196     \item Repeat from 2 for as long as you want 
       
   197   \end{enumerate}
       
   198 \inctime{20}
       
   199 \end{frame}
       
   200 
       
   201 \end{document}