day1/session5.tex
author Puneeth Chaganti <punchagan@fossee.in>
Tue, 27 Oct 2009 18:34:16 +0530
changeset 202 2b902f2d25e5
child 221 9ed9539446bc
permissions -rw-r--r--
Started session5.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
202
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
     1
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
     2
%Tutorial slides on Python.
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
     3
%
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
     4
% Author: FOSSEE 
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
     5
% Copyright (c) 2009, FOSSEE, IIT Bombay
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
     6
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
     7
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
     8
\documentclass[14pt,compress]{beamer}
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
     9
%\documentclass[draft]{beamer}
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    10
%\documentclass[compress,handout]{beamer}
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    11
%\usepackage{pgfpages} 
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    12
%\pgfpagesuselayout{2 on 1}[a4paper,border shrink=5mm]
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    13
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    14
% Modified from: generic-ornate-15min-45min.de.tex
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    15
\mode<presentation>
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    16
{
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    17
  \usetheme{Warsaw}
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    18
  \useoutertheme{split}
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    19
  \setbeamercovered{transparent}
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    20
}
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    21
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    22
\usepackage[english]{babel}
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    23
\usepackage[latin1]{inputenc}
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    24
%\usepackage{times}
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    25
\usepackage[T1]{fontenc}
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    26
\usepackage{amsmath}
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    27
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    28
% Taken from Fernando's slides.
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    29
\usepackage{ae,aecompl}
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    30
\usepackage{mathpazo,courier,euler}
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    31
\usepackage[scaled=.95]{helvet}
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    32
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    33
\definecolor{darkgreen}{rgb}{0,0.5,0}
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    34
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    35
\usepackage{listings}
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    36
\lstset{language=Python,
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    37
    basicstyle=\ttfamily\bfseries,
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    38
    commentstyle=\color{red}\itshape,
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    39
  stringstyle=\color{darkgreen},
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    40
  showstringspaces=false,
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    41
  keywordstyle=\color{blue}\bfseries}
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    42
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    43
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    44
% Macros
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    45
\setbeamercolor{emphbar}{bg=blue!20, fg=black}
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    46
\newcommand{\emphbar}[1]
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    47
{\begin{beamercolorbox}[rounded=true]{emphbar} 
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    48
      {#1}
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    49
 \end{beamercolorbox}
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    50
}
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    51
\newcounter{time}
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    52
\setcounter{time}{0}
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    53
\newcommand{\inctime}[1]{\addtocounter{time}{#1}{\tiny \thetime\ m}}
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    54
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    55
\newcommand{\typ}[1]{\lstinline{#1}}
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    56
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    57
\newcommand{\kwrd}[1]{ \texttt{\textbf{\color{blue}{#1}}}  }
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    58
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    59
%%% This is from Fernando's setup.
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    60
% \usepackage{color}
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    61
% \definecolor{orange}{cmyk}{0,0.4,0.8,0.2}
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    62
% % Use and configure listings package for nicely formatted code
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    63
% \usepackage{listings}
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    64
% \lstset{
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    65
%    language=Python,
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    66
%    basicstyle=\small\ttfamily,
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    67
%    commentstyle=\ttfamily\color{blue},
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    68
%    stringstyle=\ttfamily\color{orange},
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    69
%    showstringspaces=false,
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    70
%    breaklines=true,
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    71
%    postbreak = \space\dots
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    72
% }
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    73
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    74
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    75
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    76
% Title page
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    77
\title[Basic Python]{Interpolation, Differentiation and Integration}
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    78
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    79
\author[FOSSEE] {FOSSEE}
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    80
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    81
\institute[IIT Bombay] {Department of Aerospace Engineering\\IIT Bombay}
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    82
\date[] {31, October 2009\\Day 1, Session 4}
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    83
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    84
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    85
%\pgfdeclareimage[height=0.75cm]{iitmlogo}{iitmlogo}
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    86
%\logo{\pgfuseimage{iitmlogo}}
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    87
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    88
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    89
%% Delete this, if you do not want the table of contents to pop up at
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    90
%% the beginning of each subsection:
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    91
\AtBeginSubsection[]
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    92
{
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    93
  \begin{frame}<beamer>
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    94
    \frametitle{Outline}
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    95
    \tableofcontents[currentsection,currentsubsection]
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    96
  \end{frame}
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    97
}
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    98
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    99
%%\AtBeginSection[]
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   100
%%{
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   101
  %%\begin{frame}<beamer>
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   102
%%    \frametitle{Outline}
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   103
  %%  \tableofcontents[currentsection,currentsubsection]
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   104
  %%\end{frame}
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   105
%%}
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   106
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   107
% If you wish to uncover everything in a step-wise fashion, uncomment
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   108
% the following command: 
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   109
%\beamerdefaultoverlayspecification{<+->}
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   110
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   111
%\includeonlyframes{current,current1,current2,current3,current4,current5,current6}
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   112
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   113
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   114
% DOCUMENT STARTS
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   115
\begin{document}
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   116
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   117
\begin{frame}
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   118
  \titlepage
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   119
\end{frame}
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   120
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   121
\begin{frame}
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   122
  \frametitle{Outline}
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   123
  \tableofcontents
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   124
%  \pausesections
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   125
\end{frame}
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   126
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   127
\section{Integration}
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   128
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   129
\subsection{Quadrature}
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   130
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   131
\begin{frame}[fragile]
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   132
\frametitle{Quadrature}
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   133
\begin{itemize}
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   134
\item We wish to find area under a curve
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   135
\item Area under $(sin(x) + x^2)$ in $(0,1)$
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   136
\item scipy has functions to do that
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   137
\end{itemize}
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   138
\small{\typ{In []: from scipy.integrate import quad}}
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   139
\begin{itemize}
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   140
\item Inputs - function to integrate, limits
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   141
\end{itemize}
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   142
\begin{lstlisting}
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   143
In []: x = 0
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   144
In []: quad(sin(x)+x**2, 0, 1)
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   145
\end{lstlisting}
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   146
\alert{\typ{error:}}
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   147
\typ{First argument must be a callable function.}
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   148
\end{frame}
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   149
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   150
\begin{frame}[fragile]
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   151
\frametitle{Functions - Definition}
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   152
\begin{lstlisting}
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   153
In []: def f(x):
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   154
           return sin(x)+x**2
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   155
In []: quad(f, 0, 1)
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   156
\end{lstlisting}
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   157
\begin{itemize}
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   158
\item \typ{def}
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   159
\item arguments
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   160
\item \typ{return}
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   161
\end{itemize}
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   162
\end{frame}
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   163
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   164
\begin{frame}[fragile]
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   165
\frametitle{Functions - Calling them}
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   166
\begin{lstlisting}
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   167
In [15]: f()
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   168
---------------------------------------
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   169
\end{lstlisting}
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   170
\alert{\typ{TypeError:}}\typ{f() takes exactly 1 argument}
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   171
\typ{(0 given)}
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   172
\begin{lstlisting}
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   173
In []: f(0)
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   174
Out[]: 0.0
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   175
In []: f(1)
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   176
Out[]: 1.8414709848078965
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   177
\end{lstlisting}
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   178
\end{frame}
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   179
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   180
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   181
\begin{frame}[fragile]
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   182
\frametitle{Functions - Default Arguments}
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   183
\begin{lstlisting}
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   184
In []: def f(x=1):
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   185
           return sin(x)+x**2
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   186
In []: f(10)
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   187
Out[]: 99.455978889110625
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   188
In []: f(1)
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   189
Out[]: 1.8414709848078965
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   190
In []: f()
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   191
Out[]: 1.8414709848078965
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   192
\end{lstlisting}
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   193
\end{frame}
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   194
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   195
\begin{frame}[fragile]
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   196
\frametitle{Functions - Keyword Arguments}
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   197
\begin{lstlisting}
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   198
In []: def f(x=1, y=pi):
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   199
           return sin(y)+x**2
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   200
In []: f()
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   201
Out[]: 1.0000000000000002
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   202
In []: f(2)
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   203
Out[]: 4.0
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   204
In []: f(y=2)
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   205
Out[]: 1.9092974268256817
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   206
In []: f(y=pi/2,x=0)
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   207
Out[]: 1.0
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   208
\end{lstlisting}
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   209
\end{frame}
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   210
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   211
\begin{frame}[fragile]
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   212
  \frametitle{More on functions}
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   213
  \begin{itemize}
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   214
  \item Scope of variables in the function is local
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   215
  \item Mutable items are \alert{passed by reference}
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   216
  \item First line after definition may be a documentation string
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   217
    (\alert{recommended!})
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   218
  \item Function definition and execution defines a name bound to the
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   219
    function
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   220
  \item You \emph{can} assign a variable to a function!
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   221
  \end{itemize}
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   222
\end{frame}
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   223
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   224
\begin{frame}[fragile]
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   225
\frametitle{Quadrature \ldots}
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   226
\begin{lstlisting}
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   227
In []: quad(f, 0, 1)
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   228
\end{lstlisting}
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   229
Returns the integral and an estimate of the absolute error in the result.
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   230
\begin{itemize}
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   231
\item Use \typ{dblquad} for Double integrals
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   232
\item Use \typ{tplquad} for Triple integrals
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   233
\end{itemize}
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   234
\end{frame}
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   235
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   236
\subsection{ODEs}
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   237
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   238
\begin{frame}[fragile]
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   239
\frametitle{ODE Integration}
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   240
We shall use the simple ODE of a simple pendulum. 
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   241
\begin{equation*}
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   242
\ddot{\theta} = -\frac{g}{L}sin(\theta)
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   243
\end{equation*}
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   244
\begin{itemize}
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   245
\item This equation can be written as a system of two first order ODEs
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   246
\end{itemize}
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   247
\begin{align}
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   248
\dot{\theta} &= \omega \\
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   249
\dot{\omega} &= -\frac{g}{L}sin(\theta) \\
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   250
 \text{At}\ t &= 0 : \nonumber \\
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   251
 \theta = \theta_0\quad & \&\quad  \omega = 0 \nonumber
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   252
\end{align}
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   253
\end{frame}
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   254
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   255
\begin{frame}[fragile]
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   256
\frametitle{Solving ODEs using SciPy}
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   257
\begin{itemize}
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   258
\item We use the \typ{odeint} function from scipy to do the integration
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   259
\item Define a function as below
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   260
\end{itemize}
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   261
\begin{lstlisting}
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   262
In []: def pend_int(unknown, t, p):
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   263
  ....     theta, omega = unknown
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   264
  ....     g, L = p
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   265
  ....     f=[omega, -(g/L)*sin(theta)]
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   266
  ....     return f
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   267
  ....
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   268
\end{lstlisting}
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   269
\end{frame}
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   270
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   271
\begin{frame}[fragile]
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   272
\frametitle{Solving ODEs using SciPy \ldots}
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   273
\begin{itemize}
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   274
\item \typ{t} is the time variable \\ 
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   275
\item \typ{p} has the constants \\
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   276
\item \typ{initial} has the initial values
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   277
\end{itemize}
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   278
\begin{lstlisting}
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   279
In []: t = linspace(0, 10, 101)
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   280
In []: p=(-9.81, 0.2)
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   281
In []: initial = [10*2*pi/360, 0]
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   282
\end{lstlisting}
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   283
\end{frame}
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   284
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   285
\begin{frame}[fragile]
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   286
\frametitle{Solving ODEs using SciPy \ldots}
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   287
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   288
\small{\typ{In []: from scipy.integrate import odeint}}
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   289
\begin{lstlisting}
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   290
In []: pend_sol = odeint(pend_int, 
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   291
                         initial,t, 
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   292
                         args=(p,))
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   293
\end{lstlisting}
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   294
\end{frame}
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   295
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   296
\begin{frame}
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   297
  \frametitle{Things we have learned}
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   298
  \begin{itemize}
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   299
  \item Functions
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   300
    \begin{itemize}
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   301
    \item Definition
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   302
    \item Calling
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   303
    \item Default Arguments
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   304
    \item Keyword Arguments
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   305
    \end{itemize}
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   306
  \item Quadrature
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   307
  \end{itemize}
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   308
\end{frame}
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   309
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   310
\end{document}
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   311