day1/session5.tex
author Shantanu <shantanu@fossee.in>
Sat, 31 Oct 2009 01:33:41 +0530
changeset 262 9664eddee075
parent 261 9cce24d00957
parent 260 1f5fea506927
child 263 8a4a1e5aec85
permissions -rw-r--r--
Merged all branches.
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}
239
8953675dc056 Added slide numbers.
Puneeth Chaganti <punchagan@fossee.in>
parents: 226
diff changeset
    18
  \useoutertheme{infolines}
202
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
240
5a96cf81bdc5 Changed titles of Day1 slides.
Puneeth Chaganti <punchagan@fossee.in>
parents: 239
diff changeset
    77
\title[Calculus]{Python for Science and Engg: Interpolation, Differentiation and Integration}
202
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}
222
ffa8f417d761 Corrected session number in session5.
Puneeth Chaganti <punchagan@fossee.in>
parents: 221
diff changeset
    82
\date[] {31, October 2009\\Day 1, Session 5}
202
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
224
668f88f20218 Added differentiation example.
Puneeth Chaganti <punchagan@fossee.in>
parents: 223
diff changeset
    99
\AtBeginSection[]
668f88f20218 Added differentiation example.
Puneeth Chaganti <punchagan@fossee.in>
parents: 223
diff changeset
   100
{
668f88f20218 Added differentiation example.
Puneeth Chaganti <punchagan@fossee.in>
parents: 223
diff changeset
   101
  \begin{frame}<beamer>
668f88f20218 Added differentiation example.
Puneeth Chaganti <punchagan@fossee.in>
parents: 223
diff changeset
   102
   \frametitle{Outline}
668f88f20218 Added differentiation example.
Puneeth Chaganti <punchagan@fossee.in>
parents: 223
diff changeset
   103
   \tableofcontents[currentsection,currentsubsection]
668f88f20218 Added differentiation example.
Puneeth Chaganti <punchagan@fossee.in>
parents: 223
diff changeset
   104
  \end{frame}
668f88f20218 Added differentiation example.
Puneeth Chaganti <punchagan@fossee.in>
parents: 223
diff changeset
   105
}
202
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
259
bb77a470e00a Added loadtxt section to Day1 Session5.
Puneeth Chaganti <punchagan@fossee.in>
parents: 256
diff changeset
   121
%% \begin{frame}
bb77a470e00a Added loadtxt section to Day1 Session5.
Puneeth Chaganti <punchagan@fossee.in>
parents: 256
diff changeset
   122
%%   \frametitle{Outline}
bb77a470e00a Added loadtxt section to Day1 Session5.
Puneeth Chaganti <punchagan@fossee.in>
parents: 256
diff changeset
   123
%%   \tableofcontents
bb77a470e00a Added loadtxt section to Day1 Session5.
Puneeth Chaganti <punchagan@fossee.in>
parents: 256
diff changeset
   124
%% %  \pausesections
bb77a470e00a Added loadtxt section to Day1 Session5.
Puneeth Chaganti <punchagan@fossee.in>
parents: 256
diff changeset
   125
%% \end{frame}
bb77a470e00a Added loadtxt section to Day1 Session5.
Puneeth Chaganti <punchagan@fossee.in>
parents: 256
diff changeset
   126
bb77a470e00a Added loadtxt section to Day1 Session5.
Puneeth Chaganti <punchagan@fossee.in>
parents: 256
diff changeset
   127
bb77a470e00a Added loadtxt section to Day1 Session5.
Puneeth Chaganti <punchagan@fossee.in>
parents: 256
diff changeset
   128
\section{\typ{loadtxt}}
bb77a470e00a Added loadtxt section to Day1 Session5.
Puneeth Chaganti <punchagan@fossee.in>
parents: 256
diff changeset
   129
bb77a470e00a Added loadtxt section to Day1 Session5.
Puneeth Chaganti <punchagan@fossee.in>
parents: 256
diff changeset
   130
\begin{frame}[fragile]
bb77a470e00a Added loadtxt section to Day1 Session5.
Puneeth Chaganti <punchagan@fossee.in>
parents: 256
diff changeset
   131
  \frametitle{\typ{loadtxt}}
bb77a470e00a Added loadtxt section to Day1 Session5.
Puneeth Chaganti <punchagan@fossee.in>
parents: 256
diff changeset
   132
  \begin{itemize}
bb77a470e00a Added loadtxt section to Day1 Session5.
Puneeth Chaganti <punchagan@fossee.in>
parents: 256
diff changeset
   133
  \item Load data from a text file.
bb77a470e00a Added loadtxt section to Day1 Session5.
Puneeth Chaganti <punchagan@fossee.in>
parents: 256
diff changeset
   134
  \item Each row must have same number of values.
bb77a470e00a Added loadtxt section to Day1 Session5.
Puneeth Chaganti <punchagan@fossee.in>
parents: 256
diff changeset
   135
  \end{itemize}
bb77a470e00a Added loadtxt section to Day1 Session5.
Puneeth Chaganti <punchagan@fossee.in>
parents: 256
diff changeset
   136
\begin{lstlisting}
260
1f5fea506927 Changed loadtxt to use unpack argument.
Puneeth Chaganti <punchagan@fossee.in>
parents: 259
diff changeset
   137
In []: L, T = loadtxt('pendulum.txt', 
1f5fea506927 Changed loadtxt to use unpack argument.
Puneeth Chaganti <punchagan@fossee.in>
parents: 259
diff changeset
   138
                       unpack = True)
259
bb77a470e00a Added loadtxt section to Day1 Session5.
Puneeth Chaganti <punchagan@fossee.in>
parents: 256
diff changeset
   139
\end{lstlisting}
202
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   140
\end{frame}
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   141
259
bb77a470e00a Added loadtxt section to Day1 Session5.
Puneeth Chaganti <punchagan@fossee.in>
parents: 256
diff changeset
   142
%% \begin{frame}[fragile]
bb77a470e00a Added loadtxt section to Day1 Session5.
Puneeth Chaganti <punchagan@fossee.in>
parents: 256
diff changeset
   143
%%   \frametitle{\typ{loadtxt}}
bb77a470e00a Added loadtxt section to Day1 Session5.
Puneeth Chaganti <punchagan@fossee.in>
parents: 256
diff changeset
   144
%% \end{frame}
bb77a470e00a Added loadtxt section to Day1 Session5.
Puneeth Chaganti <punchagan@fossee.in>
parents: 256
diff changeset
   145
221
9ed9539446bc Updated day1 session5 and session6.
Puneeth Chaganti <punchagan@fossee.in>
parents: 202
diff changeset
   146
\section{Interpolation}
9ed9539446bc Updated day1 session5 and session6.
Puneeth Chaganti <punchagan@fossee.in>
parents: 202
diff changeset
   147
\begin{frame}[fragile]
261
9cce24d00957 1 quiz, seesion5 plots, added links to reference.
Shantanu <shantanu@fossee.in>
parents: 259
diff changeset
   148
\frametitle{Loading data (revisited)}
221
9ed9539446bc Updated day1 session5 and session6.
Puneeth Chaganti <punchagan@fossee.in>
parents: 202
diff changeset
   149
\begin{itemize}
256
a06196a05043 Added interpolate and loadtxt section to session 5 day 1.
Shantanu <shantanu@fossee.in>
parents: 244
diff changeset
   150
  \item Given data file \typ{points.txt}.
a06196a05043 Added interpolate and loadtxt section to session 5 day 1.
Shantanu <shantanu@fossee.in>
parents: 244
diff changeset
   151
  \item It contains x,y position of particle.
a06196a05043 Added interpolate and loadtxt section to session 5 day 1.
Shantanu <shantanu@fossee.in>
parents: 244
diff changeset
   152
  \item Plot the given points.
a06196a05043 Added interpolate and loadtxt section to session 5 day 1.
Shantanu <shantanu@fossee.in>
parents: 244
diff changeset
   153
%%  \item Interpolate the missing region.
221
9ed9539446bc Updated day1 session5 and session6.
Puneeth Chaganti <punchagan@fossee.in>
parents: 202
diff changeset
   154
\end{itemize}
9ed9539446bc Updated day1 session5 and session6.
Puneeth Chaganti <punchagan@fossee.in>
parents: 202
diff changeset
   155
\begin{lstlisting}
260
1f5fea506927 Changed loadtxt to use unpack argument.
Puneeth Chaganti <punchagan@fossee.in>
parents: 259
diff changeset
   156
In []: x, y = loadtxt('points.txt',
1f5fea506927 Changed loadtxt to use unpack argument.
Puneeth Chaganti <punchagan@fossee.in>
parents: 259
diff changeset
   157
                       unpack = True)
256
a06196a05043 Added interpolate and loadtxt section to session 5 day 1.
Shantanu <shantanu@fossee.in>
parents: 244
diff changeset
   158
In []: plot(x, y, '.')
221
9ed9539446bc Updated day1 session5 and session6.
Puneeth Chaganti <punchagan@fossee.in>
parents: 202
diff changeset
   159
\end{lstlisting}
9ed9539446bc Updated day1 session5 and session6.
Puneeth Chaganti <punchagan@fossee.in>
parents: 202
diff changeset
   160
\end{frame}
9ed9539446bc Updated day1 session5 and session6.
Puneeth Chaganti <punchagan@fossee.in>
parents: 202
diff changeset
   161
261
9cce24d00957 1 quiz, seesion5 plots, added links to reference.
Shantanu <shantanu@fossee.in>
parents: 259
diff changeset
   162
\begin{frame}
9cce24d00957 1 quiz, seesion5 plots, added links to reference.
Shantanu <shantanu@fossee.in>
parents: 259
diff changeset
   163
  \frametitle{Plot}
9cce24d00957 1 quiz, seesion5 plots, added links to reference.
Shantanu <shantanu@fossee.in>
parents: 259
diff changeset
   164
  \begin{center}
9cce24d00957 1 quiz, seesion5 plots, added links to reference.
Shantanu <shantanu@fossee.in>
parents: 259
diff changeset
   165
    \includegraphics[height=2in, interpolate=true]{data/missing_points}
9cce24d00957 1 quiz, seesion5 plots, added links to reference.
Shantanu <shantanu@fossee.in>
parents: 259
diff changeset
   166
  \end{center}
9cce24d00957 1 quiz, seesion5 plots, added links to reference.
Shantanu <shantanu@fossee.in>
parents: 259
diff changeset
   167
\end{frame}
221
9ed9539446bc Updated day1 session5 and session6.
Puneeth Chaganti <punchagan@fossee.in>
parents: 202
diff changeset
   168
%% \begin{frame}[fragile]
9ed9539446bc Updated day1 session5 and session6.
Puneeth Chaganti <punchagan@fossee.in>
parents: 202
diff changeset
   169
%% \frametitle{Interpolation \ldots}
9ed9539446bc Updated day1 session5 and session6.
Puneeth Chaganti <punchagan@fossee.in>
parents: 202
diff changeset
   170
%% \begin{small}
9ed9539446bc Updated day1 session5 and session6.
Puneeth Chaganti <punchagan@fossee.in>
parents: 202
diff changeset
   171
%%   \typ{In []: from scipy.interpolate import interp1d}
9ed9539446bc Updated day1 session5 and session6.
Puneeth Chaganti <punchagan@fossee.in>
parents: 202
diff changeset
   172
%% \end{small}
9ed9539446bc Updated day1 session5 and session6.
Puneeth Chaganti <punchagan@fossee.in>
parents: 202
diff changeset
   173
%% \begin{itemize}
9ed9539446bc Updated day1 session5 and session6.
Puneeth Chaganti <punchagan@fossee.in>
parents: 202
diff changeset
   174
%% \item The \typ{interp1d} function returns a function
9ed9539446bc Updated day1 session5 and session6.
Puneeth Chaganti <punchagan@fossee.in>
parents: 202
diff changeset
   175
%% \begin{lstlisting}
9ed9539446bc Updated day1 session5 and session6.
Puneeth Chaganti <punchagan@fossee.in>
parents: 202
diff changeset
   176
%%   In []: f = interp1d(L, T)
9ed9539446bc Updated day1 session5 and session6.
Puneeth Chaganti <punchagan@fossee.in>
parents: 202
diff changeset
   177
%% \end{lstlisting}
9ed9539446bc Updated day1 session5 and session6.
Puneeth Chaganti <punchagan@fossee.in>
parents: 202
diff changeset
   178
%% \item Functions can be assigned to variables 
9ed9539446bc Updated day1 session5 and session6.
Puneeth Chaganti <punchagan@fossee.in>
parents: 202
diff changeset
   179
%% \item This function interpolates between known data values to obtain unknown
9ed9539446bc Updated day1 session5 and session6.
Puneeth Chaganti <punchagan@fossee.in>
parents: 202
diff changeset
   180
%% \end{itemize}
9ed9539446bc Updated day1 session5 and session6.
Puneeth Chaganti <punchagan@fossee.in>
parents: 202
diff changeset
   181
%% \end{frame}
9ed9539446bc Updated day1 session5 and session6.
Puneeth Chaganti <punchagan@fossee.in>
parents: 202
diff changeset
   182
9ed9539446bc Updated day1 session5 and session6.
Puneeth Chaganti <punchagan@fossee.in>
parents: 202
diff changeset
   183
%% \begin{frame}[fragile]
9ed9539446bc Updated day1 session5 and session6.
Puneeth Chaganti <punchagan@fossee.in>
parents: 202
diff changeset
   184
%% \frametitle{Interpolation \ldots}
9ed9539446bc Updated day1 session5 and session6.
Puneeth Chaganti <punchagan@fossee.in>
parents: 202
diff changeset
   185
%% \begin{lstlisting}
9ed9539446bc Updated day1 session5 and session6.
Puneeth Chaganti <punchagan@fossee.in>
parents: 202
diff changeset
   186
%% In []: Ln = arange(0.1,0.99,0.005)
9ed9539446bc Updated day1 session5 and session6.
Puneeth Chaganti <punchagan@fossee.in>
parents: 202
diff changeset
   187
%% # Interpolating! 
9ed9539446bc Updated day1 session5 and session6.
Puneeth Chaganti <punchagan@fossee.in>
parents: 202
diff changeset
   188
%% # The new values in range of old data
9ed9539446bc Updated day1 session5 and session6.
Puneeth Chaganti <punchagan@fossee.in>
parents: 202
diff changeset
   189
%% In []: plot(L, T, 'o', Ln, f(Ln), '-')
9ed9539446bc Updated day1 session5 and session6.
Puneeth Chaganti <punchagan@fossee.in>
parents: 202
diff changeset
   190
%% In []: f = interp1d(L, T, kind='cubic')
9ed9539446bc Updated day1 session5 and session6.
Puneeth Chaganti <punchagan@fossee.in>
parents: 202
diff changeset
   191
%% # When kind not specified, it's linear
9ed9539446bc Updated day1 session5 and session6.
Puneeth Chaganti <punchagan@fossee.in>
parents: 202
diff changeset
   192
%% # Others are ...
9ed9539446bc Updated day1 session5 and session6.
Puneeth Chaganti <punchagan@fossee.in>
parents: 202
diff changeset
   193
%% # 'nearest', 'zero', 
9ed9539446bc Updated day1 session5 and session6.
Puneeth Chaganti <punchagan@fossee.in>
parents: 202
diff changeset
   194
%% # 'slinear', 'quadratic'
9ed9539446bc Updated day1 session5 and session6.
Puneeth Chaganti <punchagan@fossee.in>
parents: 202
diff changeset
   195
%% \end{lstlisting}
9ed9539446bc Updated day1 session5 and session6.
Puneeth Chaganti <punchagan@fossee.in>
parents: 202
diff changeset
   196
%% \end{frame}
9ed9539446bc Updated day1 session5 and session6.
Puneeth Chaganti <punchagan@fossee.in>
parents: 202
diff changeset
   197
9ed9539446bc Updated day1 session5 and session6.
Puneeth Chaganti <punchagan@fossee.in>
parents: 202
diff changeset
   198
\begin{frame}[fragile]
9ed9539446bc Updated day1 session5 and session6.
Puneeth Chaganti <punchagan@fossee.in>
parents: 202
diff changeset
   199
\frametitle{Spline Interpolation}
9ed9539446bc Updated day1 session5 and session6.
Puneeth Chaganti <punchagan@fossee.in>
parents: 202
diff changeset
   200
\begin{small}
9ed9539446bc Updated day1 session5 and session6.
Puneeth Chaganti <punchagan@fossee.in>
parents: 202
diff changeset
   201
\begin{lstlisting}
9ed9539446bc Updated day1 session5 and session6.
Puneeth Chaganti <punchagan@fossee.in>
parents: 202
diff changeset
   202
In []: from scipy.interpolate import splrep
9ed9539446bc Updated day1 session5 and session6.
Puneeth Chaganti <punchagan@fossee.in>
parents: 202
diff changeset
   203
In []: from scipy.interpolate import splev
9ed9539446bc Updated day1 session5 and session6.
Puneeth Chaganti <punchagan@fossee.in>
parents: 202
diff changeset
   204
\end{lstlisting}
9ed9539446bc Updated day1 session5 and session6.
Puneeth Chaganti <punchagan@fossee.in>
parents: 202
diff changeset
   205
\end{small}
9ed9539446bc Updated day1 session5 and session6.
Puneeth Chaganti <punchagan@fossee.in>
parents: 202
diff changeset
   206
\begin{itemize}
9ed9539446bc Updated day1 session5 and session6.
Puneeth Chaganti <punchagan@fossee.in>
parents: 202
diff changeset
   207
\item Involves two steps
9ed9539446bc Updated day1 session5 and session6.
Puneeth Chaganti <punchagan@fossee.in>
parents: 202
diff changeset
   208
  \begin{enumerate}
9ed9539446bc Updated day1 session5 and session6.
Puneeth Chaganti <punchagan@fossee.in>
parents: 202
diff changeset
   209
  \item Find out the spline curve, coefficients
9ed9539446bc Updated day1 session5 and session6.
Puneeth Chaganti <punchagan@fossee.in>
parents: 202
diff changeset
   210
  \item Evaluate the spline at new points
9ed9539446bc Updated day1 session5 and session6.
Puneeth Chaganti <punchagan@fossee.in>
parents: 202
diff changeset
   211
  \end{enumerate}
9ed9539446bc Updated day1 session5 and session6.
Puneeth Chaganti <punchagan@fossee.in>
parents: 202
diff changeset
   212
\end{itemize}
9ed9539446bc Updated day1 session5 and session6.
Puneeth Chaganti <punchagan@fossee.in>
parents: 202
diff changeset
   213
\end{frame}
202
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   214
221
9ed9539446bc Updated day1 session5 and session6.
Puneeth Chaganti <punchagan@fossee.in>
parents: 202
diff changeset
   215
\begin{frame}[fragile]
9ed9539446bc Updated day1 session5 and session6.
Puneeth Chaganti <punchagan@fossee.in>
parents: 202
diff changeset
   216
\frametitle{\typ{splrep}}
256
a06196a05043 Added interpolate and loadtxt section to session 5 day 1.
Shantanu <shantanu@fossee.in>
parents: 244
diff changeset
   217
To find the spline curve
221
9ed9539446bc Updated day1 session5 and session6.
Puneeth Chaganti <punchagan@fossee.in>
parents: 202
diff changeset
   218
\begin{lstlisting}
256
a06196a05043 Added interpolate and loadtxt section to session 5 day 1.
Shantanu <shantanu@fossee.in>
parents: 244
diff changeset
   219
In []: tck = splrep(x, y)
221
9ed9539446bc Updated day1 session5 and session6.
Puneeth Chaganti <punchagan@fossee.in>
parents: 202
diff changeset
   220
\end{lstlisting}
256
a06196a05043 Added interpolate and loadtxt section to session 5 day 1.
Shantanu <shantanu@fossee.in>
parents: 244
diff changeset
   221
\typ{tck} contains parameters required for representing the spline curve!
221
9ed9539446bc Updated day1 session5 and session6.
Puneeth Chaganti <punchagan@fossee.in>
parents: 202
diff changeset
   222
\end{frame}
9ed9539446bc Updated day1 session5 and session6.
Puneeth Chaganti <punchagan@fossee.in>
parents: 202
diff changeset
   223
9ed9539446bc Updated day1 session5 and session6.
Puneeth Chaganti <punchagan@fossee.in>
parents: 202
diff changeset
   224
\begin{frame}[fragile]
9ed9539446bc Updated day1 session5 and session6.
Puneeth Chaganti <punchagan@fossee.in>
parents: 202
diff changeset
   225
\frametitle{\typ{splev}}
9ed9539446bc Updated day1 session5 and session6.
Puneeth Chaganti <punchagan@fossee.in>
parents: 202
diff changeset
   226
To Evaluate a B-spline and it's derivatives
9ed9539446bc Updated day1 session5 and session6.
Puneeth Chaganti <punchagan@fossee.in>
parents: 202
diff changeset
   227
\begin{lstlisting}
256
a06196a05043 Added interpolate and loadtxt section to session 5 day 1.
Shantanu <shantanu@fossee.in>
parents: 244
diff changeset
   228
In []: Xnew = arange(0.01,3,0.02)
a06196a05043 Added interpolate and loadtxt section to session 5 day 1.
Shantanu <shantanu@fossee.in>
parents: 244
diff changeset
   229
In []: Ynew = splev(Xnew, tck)
a06196a05043 Added interpolate and loadtxt section to session 5 day 1.
Shantanu <shantanu@fossee.in>
parents: 244
diff changeset
   230
a06196a05043 Added interpolate and loadtxt section to session 5 day 1.
Shantanu <shantanu@fossee.in>
parents: 244
diff changeset
   231
In []: y.shape
a06196a05043 Added interpolate and loadtxt section to session 5 day 1.
Shantanu <shantanu@fossee.in>
parents: 244
diff changeset
   232
Out[]: (40,)
221
9ed9539446bc Updated day1 session5 and session6.
Puneeth Chaganti <punchagan@fossee.in>
parents: 202
diff changeset
   233
256
a06196a05043 Added interpolate and loadtxt section to session 5 day 1.
Shantanu <shantanu@fossee.in>
parents: 244
diff changeset
   234
In []: Ynew.shape
a06196a05043 Added interpolate and loadtxt section to session 5 day 1.
Shantanu <shantanu@fossee.in>
parents: 244
diff changeset
   235
Out[]: (150,)
a06196a05043 Added interpolate and loadtxt section to session 5 day 1.
Shantanu <shantanu@fossee.in>
parents: 244
diff changeset
   236
 
a06196a05043 Added interpolate and loadtxt section to session 5 day 1.
Shantanu <shantanu@fossee.in>
parents: 244
diff changeset
   237
In []: plot(Xnew, Ynew)
221
9ed9539446bc Updated day1 session5 and session6.
Puneeth Chaganti <punchagan@fossee.in>
parents: 202
diff changeset
   238
\end{lstlisting}
256
a06196a05043 Added interpolate and loadtxt section to session 5 day 1.
Shantanu <shantanu@fossee.in>
parents: 244
diff changeset
   239
221
9ed9539446bc Updated day1 session5 and session6.
Puneeth Chaganti <punchagan@fossee.in>
parents: 202
diff changeset
   240
\end{frame}
9ed9539446bc Updated day1 session5 and session6.
Puneeth Chaganti <punchagan@fossee.in>
parents: 202
diff changeset
   241
224
668f88f20218 Added differentiation example.
Puneeth Chaganti <punchagan@fossee.in>
parents: 223
diff changeset
   242
%% \begin{frame}[fragile]
668f88f20218 Added differentiation example.
Puneeth Chaganti <punchagan@fossee.in>
parents: 223
diff changeset
   243
%% \frametitle{Interpolation \ldots}
668f88f20218 Added differentiation example.
Puneeth Chaganti <punchagan@fossee.in>
parents: 223
diff changeset
   244
%% \begin{itemize}
668f88f20218 Added differentiation example.
Puneeth Chaganti <punchagan@fossee.in>
parents: 223
diff changeset
   245
%% \item 
668f88f20218 Added differentiation example.
Puneeth Chaganti <punchagan@fossee.in>
parents: 223
diff changeset
   246
%% \end{itemize}
668f88f20218 Added differentiation example.
Puneeth Chaganti <punchagan@fossee.in>
parents: 223
diff changeset
   247
%% \end{frame}
221
9ed9539446bc Updated day1 session5 and session6.
Puneeth Chaganti <punchagan@fossee.in>
parents: 202
diff changeset
   248
9ed9539446bc Updated day1 session5 and session6.
Puneeth Chaganti <punchagan@fossee.in>
parents: 202
diff changeset
   249
\section{Differentiation}
9ed9539446bc Updated day1 session5 and session6.
Puneeth Chaganti <punchagan@fossee.in>
parents: 202
diff changeset
   250
9ed9539446bc Updated day1 session5 and session6.
Puneeth Chaganti <punchagan@fossee.in>
parents: 202
diff changeset
   251
\begin{frame}[fragile]
9ed9539446bc Updated day1 session5 and session6.
Puneeth Chaganti <punchagan@fossee.in>
parents: 202
diff changeset
   252
\frametitle{Numerical Differentiation}
9ed9539446bc Updated day1 session5 and session6.
Puneeth Chaganti <punchagan@fossee.in>
parents: 202
diff changeset
   253
\begin{itemize}
9ed9539446bc Updated day1 session5 and session6.
Puneeth Chaganti <punchagan@fossee.in>
parents: 202
diff changeset
   254
\item Given function $f(x)$ or data points $y=f(x)$
9ed9539446bc Updated day1 session5 and session6.
Puneeth Chaganti <punchagan@fossee.in>
parents: 202
diff changeset
   255
\item We wish to calculate $f^{'}(x)$ at points $x$
9ed9539446bc Updated day1 session5 and session6.
Puneeth Chaganti <punchagan@fossee.in>
parents: 202
diff changeset
   256
\item Taylor series - finite difference approximations
9ed9539446bc Updated day1 session5 and session6.
Puneeth Chaganti <punchagan@fossee.in>
parents: 202
diff changeset
   257
\end{itemize}
9ed9539446bc Updated day1 session5 and session6.
Puneeth Chaganti <punchagan@fossee.in>
parents: 202
diff changeset
   258
\begin{center}
9ed9539446bc Updated day1 session5 and session6.
Puneeth Chaganti <punchagan@fossee.in>
parents: 202
diff changeset
   259
\begin{tabular}{l l}
9ed9539446bc Updated day1 session5 and session6.
Puneeth Chaganti <punchagan@fossee.in>
parents: 202
diff changeset
   260
$f(x+h)=f(x)+h.f^{'}(x)$ &Forward \\
9ed9539446bc Updated day1 session5 and session6.
Puneeth Chaganti <punchagan@fossee.in>
parents: 202
diff changeset
   261
$f(x-h)=f(x)-h.f^{'}(x)$ &Backward
9ed9539446bc Updated day1 session5 and session6.
Puneeth Chaganti <punchagan@fossee.in>
parents: 202
diff changeset
   262
\end{tabular}
9ed9539446bc Updated day1 session5 and session6.
Puneeth Chaganti <punchagan@fossee.in>
parents: 202
diff changeset
   263
\end{center}
9ed9539446bc Updated day1 session5 and session6.
Puneeth Chaganti <punchagan@fossee.in>
parents: 202
diff changeset
   264
\end{frame}
9ed9539446bc Updated day1 session5 and session6.
Puneeth Chaganti <punchagan@fossee.in>
parents: 202
diff changeset
   265
9ed9539446bc Updated day1 session5 and session6.
Puneeth Chaganti <punchagan@fossee.in>
parents: 202
diff changeset
   266
\begin{frame}[fragile]
9ed9539446bc Updated day1 session5 and session6.
Puneeth Chaganti <punchagan@fossee.in>
parents: 202
diff changeset
   267
\frametitle{Forward Difference}
9ed9539446bc Updated day1 session5 and session6.
Puneeth Chaganti <punchagan@fossee.in>
parents: 202
diff changeset
   268
\begin{lstlisting}
9ed9539446bc Updated day1 session5 and session6.
Puneeth Chaganti <punchagan@fossee.in>
parents: 202
diff changeset
   269
In []: x = linspace(0, 2*pi, 100)
9ed9539446bc Updated day1 session5 and session6.
Puneeth Chaganti <punchagan@fossee.in>
parents: 202
diff changeset
   270
In []: y = sin(x)
9ed9539446bc Updated day1 session5 and session6.
Puneeth Chaganti <punchagan@fossee.in>
parents: 202
diff changeset
   271
In []: deltax = x[1] - x[0]
9ed9539446bc Updated day1 session5 and session6.
Puneeth Chaganti <punchagan@fossee.in>
parents: 202
diff changeset
   272
\end{lstlisting}
9ed9539446bc Updated day1 session5 and session6.
Puneeth Chaganti <punchagan@fossee.in>
parents: 202
diff changeset
   273
Obtain the finite forward difference of y
9ed9539446bc Updated day1 session5 and session6.
Puneeth Chaganti <punchagan@fossee.in>
parents: 202
diff changeset
   274
\end{frame}
9ed9539446bc Updated day1 session5 and session6.
Puneeth Chaganti <punchagan@fossee.in>
parents: 202
diff changeset
   275
9ed9539446bc Updated day1 session5 and session6.
Puneeth Chaganti <punchagan@fossee.in>
parents: 202
diff changeset
   276
\begin{frame}[fragile]
9ed9539446bc Updated day1 session5 and session6.
Puneeth Chaganti <punchagan@fossee.in>
parents: 202
diff changeset
   277
\frametitle{Forward Difference \ldots}
9ed9539446bc Updated day1 session5 and session6.
Puneeth Chaganti <punchagan@fossee.in>
parents: 202
diff changeset
   278
\begin{lstlisting}
9ed9539446bc Updated day1 session5 and session6.
Puneeth Chaganti <punchagan@fossee.in>
parents: 202
diff changeset
   279
In []: fD = (y[1:] - y[:-1]) / deltax
9ed9539446bc Updated day1 session5 and session6.
Puneeth Chaganti <punchagan@fossee.in>
parents: 202
diff changeset
   280
In []: plot(x, y, x[:-1], fD)
9ed9539446bc Updated day1 session5 and session6.
Puneeth Chaganti <punchagan@fossee.in>
parents: 202
diff changeset
   281
\end{lstlisting}
9ed9539446bc Updated day1 session5 and session6.
Puneeth Chaganti <punchagan@fossee.in>
parents: 202
diff changeset
   282
\begin{center}
9ed9539446bc Updated day1 session5 and session6.
Puneeth Chaganti <punchagan@fossee.in>
parents: 202
diff changeset
   283
  \includegraphics[height=2in, interpolate=true]{data/fwdDiff}
9ed9539446bc Updated day1 session5 and session6.
Puneeth Chaganti <punchagan@fossee.in>
parents: 202
diff changeset
   284
\end{center}
9ed9539446bc Updated day1 session5 and session6.
Puneeth Chaganti <punchagan@fossee.in>
parents: 202
diff changeset
   285
\end{frame}
9ed9539446bc Updated day1 session5 and session6.
Puneeth Chaganti <punchagan@fossee.in>
parents: 202
diff changeset
   286
9ed9539446bc Updated day1 session5 and session6.
Puneeth Chaganti <punchagan@fossee.in>
parents: 202
diff changeset
   287
\begin{frame}[fragile]
224
668f88f20218 Added differentiation example.
Puneeth Chaganti <punchagan@fossee.in>
parents: 223
diff changeset
   288
\frametitle{Example}
668f88f20218 Added differentiation example.
Puneeth Chaganti <punchagan@fossee.in>
parents: 223
diff changeset
   289
\begin{itemize}
668f88f20218 Added differentiation example.
Puneeth Chaganti <punchagan@fossee.in>
parents: 223
diff changeset
   290
\item Given x, y positions of a particle in \typ{pos.txt}
668f88f20218 Added differentiation example.
Puneeth Chaganti <punchagan@fossee.in>
parents: 223
diff changeset
   291
\item Find velocity \& acceleration in x, y directions
668f88f20218 Added differentiation example.
Puneeth Chaganti <punchagan@fossee.in>
parents: 223
diff changeset
   292
\end{itemize}
668f88f20218 Added differentiation example.
Puneeth Chaganti <punchagan@fossee.in>
parents: 223
diff changeset
   293
\small{
668f88f20218 Added differentiation example.
Puneeth Chaganti <punchagan@fossee.in>
parents: 223
diff changeset
   294
\begin{center}
668f88f20218 Added differentiation example.
Puneeth Chaganti <punchagan@fossee.in>
parents: 223
diff changeset
   295
\begin{tabular}{| c | c | c |}
668f88f20218 Added differentiation example.
Puneeth Chaganti <punchagan@fossee.in>
parents: 223
diff changeset
   296
\hline
668f88f20218 Added differentiation example.
Puneeth Chaganti <punchagan@fossee.in>
parents: 223
diff changeset
   297
$X$ & $Y$ \\ \hline
668f88f20218 Added differentiation example.
Puneeth Chaganti <punchagan@fossee.in>
parents: 223
diff changeset
   298
0.     &  0.\\ \hline
668f88f20218 Added differentiation example.
Puneeth Chaganti <punchagan@fossee.in>
parents: 223
diff changeset
   299
0.25   &  0.47775\\ \hline
668f88f20218 Added differentiation example.
Puneeth Chaganti <punchagan@fossee.in>
parents: 223
diff changeset
   300
0.5    &  0.931\\ \hline
668f88f20218 Added differentiation example.
Puneeth Chaganti <punchagan@fossee.in>
parents: 223
diff changeset
   301
0.75   &  1.35975\\ \hline
668f88f20218 Added differentiation example.
Puneeth Chaganti <punchagan@fossee.in>
parents: 223
diff changeset
   302
1.     &  1.764\\ \hline
668f88f20218 Added differentiation example.
Puneeth Chaganti <punchagan@fossee.in>
parents: 223
diff changeset
   303
1.25   &  2.14375\\ \hline
668f88f20218 Added differentiation example.
Puneeth Chaganti <punchagan@fossee.in>
parents: 223
diff changeset
   304
\vdots & \vdots\\ \hline
668f88f20218 Added differentiation example.
Puneeth Chaganti <punchagan@fossee.in>
parents: 223
diff changeset
   305
\end{tabular}
668f88f20218 Added differentiation example.
Puneeth Chaganti <punchagan@fossee.in>
parents: 223
diff changeset
   306
\end{center}}
668f88f20218 Added differentiation example.
Puneeth Chaganti <punchagan@fossee.in>
parents: 223
diff changeset
   307
\end{frame}
668f88f20218 Added differentiation example.
Puneeth Chaganti <punchagan@fossee.in>
parents: 223
diff changeset
   308
668f88f20218 Added differentiation example.
Puneeth Chaganti <punchagan@fossee.in>
parents: 223
diff changeset
   309
\begin{frame}[fragile]
668f88f20218 Added differentiation example.
Puneeth Chaganti <punchagan@fossee.in>
parents: 223
diff changeset
   310
\frametitle{Example \ldots}
668f88f20218 Added differentiation example.
Puneeth Chaganti <punchagan@fossee.in>
parents: 223
diff changeset
   311
\begin{itemize}
668f88f20218 Added differentiation example.
Puneeth Chaganti <punchagan@fossee.in>
parents: 223
diff changeset
   312
\item Read the file
668f88f20218 Added differentiation example.
Puneeth Chaganti <punchagan@fossee.in>
parents: 223
diff changeset
   313
\item Obtain an array of x, y
668f88f20218 Added differentiation example.
Puneeth Chaganti <punchagan@fossee.in>
parents: 223
diff changeset
   314
\item Obtain velocity and acceleration
668f88f20218 Added differentiation example.
Puneeth Chaganti <punchagan@fossee.in>
parents: 223
diff changeset
   315
\item use \typ{deltaT = 0.05}
668f88f20218 Added differentiation example.
Puneeth Chaganti <punchagan@fossee.in>
parents: 223
diff changeset
   316
\end{itemize}
668f88f20218 Added differentiation example.
Puneeth Chaganti <punchagan@fossee.in>
parents: 223
diff changeset
   317
\begin{lstlisting}
668f88f20218 Added differentiation example.
Puneeth Chaganti <punchagan@fossee.in>
parents: 223
diff changeset
   318
In []: X = []
668f88f20218 Added differentiation example.
Puneeth Chaganti <punchagan@fossee.in>
parents: 223
diff changeset
   319
In []: Y = []
668f88f20218 Added differentiation example.
Puneeth Chaganti <punchagan@fossee.in>
parents: 223
diff changeset
   320
In []: for line in open('location.txt'):
668f88f20218 Added differentiation example.
Puneeth Chaganti <punchagan@fossee.in>
parents: 223
diff changeset
   321
  ....     points = line.split()
668f88f20218 Added differentiation example.
Puneeth Chaganti <punchagan@fossee.in>
parents: 223
diff changeset
   322
  ....     X.append(float(points[0]))
668f88f20218 Added differentiation example.
Puneeth Chaganti <punchagan@fossee.in>
parents: 223
diff changeset
   323
  ....     Y.append(float(points[1]))
668f88f20218 Added differentiation example.
Puneeth Chaganti <punchagan@fossee.in>
parents: 223
diff changeset
   324
In []: S = array([X, Y])
668f88f20218 Added differentiation example.
Puneeth Chaganti <punchagan@fossee.in>
parents: 223
diff changeset
   325
\end{lstlisting}
668f88f20218 Added differentiation example.
Puneeth Chaganti <punchagan@fossee.in>
parents: 223
diff changeset
   326
\end{frame}
668f88f20218 Added differentiation example.
Puneeth Chaganti <punchagan@fossee.in>
parents: 223
diff changeset
   327
668f88f20218 Added differentiation example.
Puneeth Chaganti <punchagan@fossee.in>
parents: 223
diff changeset
   328
668f88f20218 Added differentiation example.
Puneeth Chaganti <punchagan@fossee.in>
parents: 223
diff changeset
   329
\begin{frame}[fragile]
668f88f20218 Added differentiation example.
Puneeth Chaganti <punchagan@fossee.in>
parents: 223
diff changeset
   330
\frametitle{Example \ldots}
668f88f20218 Added differentiation example.
Puneeth Chaganti <punchagan@fossee.in>
parents: 223
diff changeset
   331
\begin{itemize}
668f88f20218 Added differentiation example.
Puneeth Chaganti <punchagan@fossee.in>
parents: 223
diff changeset
   332
\item use \typ{deltaT = 0.05}
668f88f20218 Added differentiation example.
Puneeth Chaganti <punchagan@fossee.in>
parents: 223
diff changeset
   333
\end{itemize}
668f88f20218 Added differentiation example.
Puneeth Chaganti <punchagan@fossee.in>
parents: 223
diff changeset
   334
\begin{lstlisting}
668f88f20218 Added differentiation example.
Puneeth Chaganti <punchagan@fossee.in>
parents: 223
diff changeset
   335
In []: deltaT = 0.05
668f88f20218 Added differentiation example.
Puneeth Chaganti <punchagan@fossee.in>
parents: 223
diff changeset
   336
668f88f20218 Added differentiation example.
Puneeth Chaganti <punchagan@fossee.in>
parents: 223
diff changeset
   337
In []: v = (S[:,1:]-S[:,:-1])/deltaT
668f88f20218 Added differentiation example.
Puneeth Chaganti <punchagan@fossee.in>
parents: 223
diff changeset
   338
668f88f20218 Added differentiation example.
Puneeth Chaganti <punchagan@fossee.in>
parents: 223
diff changeset
   339
In []: a = (v[:,1:]-v[:,:-1])/deltaT
668f88f20218 Added differentiation example.
Puneeth Chaganti <punchagan@fossee.in>
parents: 223
diff changeset
   340
\end{lstlisting}
668f88f20218 Added differentiation example.
Puneeth Chaganti <punchagan@fossee.in>
parents: 223
diff changeset
   341
Try Plotting the position, velocity \& acceleration.
221
9ed9539446bc Updated day1 session5 and session6.
Puneeth Chaganti <punchagan@fossee.in>
parents: 202
diff changeset
   342
\end{frame}
9ed9539446bc Updated day1 session5 and session6.
Puneeth Chaganti <punchagan@fossee.in>
parents: 202
diff changeset
   343
9ed9539446bc Updated day1 session5 and session6.
Puneeth Chaganti <punchagan@fossee.in>
parents: 202
diff changeset
   344
\section{Quadrature}
202
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   345
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   346
\begin{frame}[fragile]
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   347
\frametitle{Quadrature}
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   348
\begin{itemize}
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   349
\item We wish to find area under a curve
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   350
\item Area under $(sin(x) + x^2)$ in $(0,1)$
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   351
\item scipy has functions to do that
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   352
\end{itemize}
221
9ed9539446bc Updated day1 session5 and session6.
Puneeth Chaganti <punchagan@fossee.in>
parents: 202
diff changeset
   353
\begin{small}
9ed9539446bc Updated day1 session5 and session6.
Puneeth Chaganti <punchagan@fossee.in>
parents: 202
diff changeset
   354
  \typ{In []: from scipy.integrate import quad}
9ed9539446bc Updated day1 session5 and session6.
Puneeth Chaganti <punchagan@fossee.in>
parents: 202
diff changeset
   355
\end{small}
202
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   356
\begin{itemize}
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   357
\item Inputs - function to integrate, limits
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   358
\end{itemize}
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   359
\begin{lstlisting}
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   360
In []: x = 0
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   361
In []: quad(sin(x)+x**2, 0, 1)
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   362
\end{lstlisting}
221
9ed9539446bc Updated day1 session5 and session6.
Puneeth Chaganti <punchagan@fossee.in>
parents: 202
diff changeset
   363
\begin{small}
202
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   364
\alert{\typ{error:}}
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   365
\typ{First argument must be a callable function.}
221
9ed9539446bc Updated day1 session5 and session6.
Puneeth Chaganti <punchagan@fossee.in>
parents: 202
diff changeset
   366
\end{small}
202
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   367
\end{frame}
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   368
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   369
\begin{frame}[fragile]
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   370
\frametitle{Functions - Definition}
221
9ed9539446bc Updated day1 session5 and session6.
Puneeth Chaganti <punchagan@fossee.in>
parents: 202
diff changeset
   371
We have been using them all along. Now let's see how to define them.
202
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   372
\begin{lstlisting}
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   373
In []: def f(x):
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   374
           return sin(x)+x**2
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   375
In []: quad(f, 0, 1)
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   376
\end{lstlisting}
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   377
\begin{itemize}
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   378
\item \typ{def}
223
081600805dde Minor edits to sessions 5 and 6.
Puneeth Chaganti <punchagan@fossee.in>
parents: 222
diff changeset
   379
\item name
202
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   380
\item arguments
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   381
\item \typ{return}
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   382
\end{itemize}
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   383
\end{frame}
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   384
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   385
\begin{frame}[fragile]
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   386
\frametitle{Functions - Calling them}
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   387
\begin{lstlisting}
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   388
In [15]: f()
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   389
---------------------------------------
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   390
\end{lstlisting}
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   391
\alert{\typ{TypeError:}}\typ{f() takes exactly 1 argument}
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   392
\typ{(0 given)}
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   393
\begin{lstlisting}
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   394
In []: f(0)
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   395
Out[]: 0.0
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   396
In []: f(1)
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   397
Out[]: 1.8414709848078965
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   398
\end{lstlisting}
223
081600805dde Minor edits to sessions 5 and 6.
Puneeth Chaganti <punchagan@fossee.in>
parents: 222
diff changeset
   399
More on Functions later \ldots
202
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   400
\end{frame}
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   401
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   402
\begin{frame}[fragile]
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   403
\frametitle{Quadrature \ldots}
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   404
\begin{lstlisting}
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   405
In []: quad(f, 0, 1)
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   406
\end{lstlisting}
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   407
Returns the integral and an estimate of the absolute error in the result.
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   408
\begin{itemize}
224
668f88f20218 Added differentiation example.
Puneeth Chaganti <punchagan@fossee.in>
parents: 223
diff changeset
   409
\item Look at \typ{dblquad} for Double integrals
202
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   410
\item Use \typ{tplquad} for Triple integrals
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   411
\end{itemize}
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   412
\end{frame}
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   413
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   414
\begin{frame}
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   415
  \frametitle{Things we have learned}
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   416
  \begin{itemize}
221
9ed9539446bc Updated day1 session5 and session6.
Puneeth Chaganti <punchagan@fossee.in>
parents: 202
diff changeset
   417
  \item Interpolation
9ed9539446bc Updated day1 session5 and session6.
Puneeth Chaganti <punchagan@fossee.in>
parents: 202
diff changeset
   418
  \item Differentiation
202
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   419
  \item Functions
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   420
    \begin{itemize}
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   421
    \item Definition
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   422
    \item Calling
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   423
    \item Default Arguments
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   424
    \item Keyword Arguments
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   425
    \end{itemize}
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   426
  \item Quadrature
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   427
  \end{itemize}
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   428
\end{frame}
223
081600805dde Minor edits to sessions 5 and 6.
Puneeth Chaganti <punchagan@fossee.in>
parents: 222
diff changeset
   429
202
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   430
\end{document}
2b902f2d25e5 Started session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   431