author | Puneeth Chaganti <punchagan@fossee.in> |
Wed, 04 Nov 2009 10:35:53 +0530 | |
changeset 267 | 978d06520462 |
parent 266 | 28d4714a9702 |
child 269 | 9c9be698d7ad |
permissions | -rw-r--r-- |
202 | 1 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
2 |
%Tutorial slides on Python. |
|
3 |
% |
|
4 |
% Author: FOSSEE |
|
5 |
% Copyright (c) 2009, FOSSEE, IIT Bombay |
|
6 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
7 |
||
8 |
\documentclass[14pt,compress]{beamer} |
|
9 |
%\documentclass[draft]{beamer} |
|
10 |
%\documentclass[compress,handout]{beamer} |
|
11 |
%\usepackage{pgfpages} |
|
12 |
%\pgfpagesuselayout{2 on 1}[a4paper,border shrink=5mm] |
|
13 |
||
14 |
% Modified from: generic-ornate-15min-45min.de.tex |
|
15 |
\mode<presentation> |
|
16 |
{ |
|
17 |
\usetheme{Warsaw} |
|
239
8953675dc056
Added slide numbers.
Puneeth Chaganti <punchagan@fossee.in>
parents:
226
diff
changeset
|
18 |
\useoutertheme{infolines} |
202 | 19 |
\setbeamercovered{transparent} |
20 |
} |
|
21 |
||
22 |
\usepackage[english]{babel} |
|
23 |
\usepackage[latin1]{inputenc} |
|
24 |
%\usepackage{times} |
|
25 |
\usepackage[T1]{fontenc} |
|
26 |
\usepackage{amsmath} |
|
27 |
||
28 |
% Taken from Fernando's slides. |
|
29 |
\usepackage{ae,aecompl} |
|
30 |
\usepackage{mathpazo,courier,euler} |
|
31 |
\usepackage[scaled=.95]{helvet} |
|
32 |
||
33 |
\definecolor{darkgreen}{rgb}{0,0.5,0} |
|
34 |
||
35 |
\usepackage{listings} |
|
36 |
\lstset{language=Python, |
|
37 |
basicstyle=\ttfamily\bfseries, |
|
38 |
commentstyle=\color{red}\itshape, |
|
39 |
stringstyle=\color{darkgreen}, |
|
40 |
showstringspaces=false, |
|
41 |
keywordstyle=\color{blue}\bfseries} |
|
42 |
||
43 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
44 |
% Macros |
|
45 |
\setbeamercolor{emphbar}{bg=blue!20, fg=black} |
|
46 |
\newcommand{\emphbar}[1] |
|
47 |
{\begin{beamercolorbox}[rounded=true]{emphbar} |
|
48 |
{#1} |
|
49 |
\end{beamercolorbox} |
|
50 |
} |
|
51 |
\newcounter{time} |
|
52 |
\setcounter{time}{0} |
|
53 |
\newcommand{\inctime}[1]{\addtocounter{time}{#1}{\tiny \thetime\ m}} |
|
54 |
||
55 |
\newcommand{\typ}[1]{\lstinline{#1}} |
|
56 |
||
57 |
\newcommand{\kwrd}[1]{ \texttt{\textbf{\color{blue}{#1}}} } |
|
58 |
||
59 |
%%% This is from Fernando's setup. |
|
60 |
% \usepackage{color} |
|
61 |
% \definecolor{orange}{cmyk}{0,0.4,0.8,0.2} |
|
62 |
% % Use and configure listings package for nicely formatted code |
|
63 |
% \usepackage{listings} |
|
64 |
% \lstset{ |
|
65 |
% language=Python, |
|
66 |
% basicstyle=\small\ttfamily, |
|
67 |
% commentstyle=\ttfamily\color{blue}, |
|
68 |
% stringstyle=\ttfamily\color{orange}, |
|
69 |
% showstringspaces=false, |
|
70 |
% breaklines=true, |
|
71 |
% postbreak = \space\dots |
|
72 |
% } |
|
73 |
||
74 |
||
75 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
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 | 78 |
|
79 |
\author[FOSSEE] {FOSSEE} |
|
80 |
||
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 | 83 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
84 |
||
85 |
%\pgfdeclareimage[height=0.75cm]{iitmlogo}{iitmlogo} |
|
86 |
%\logo{\pgfuseimage{iitmlogo}} |
|
87 |
||
88 |
||
89 |
%% Delete this, if you do not want the table of contents to pop up at |
|
90 |
%% the beginning of each subsection: |
|
91 |
\AtBeginSubsection[] |
|
92 |
{ |
|
93 |
\begin{frame}<beamer> |
|
94 |
\frametitle{Outline} |
|
95 |
\tableofcontents[currentsection,currentsubsection] |
|
96 |
\end{frame} |
|
97 |
} |
|
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 | 106 |
|
107 |
% If you wish to uncover everything in a step-wise fashion, uncomment |
|
108 |
% the following command: |
|
109 |
%\beamerdefaultoverlayspecification{<+->} |
|
110 |
||
111 |
%\includeonlyframes{current,current1,current2,current3,current4,current5,current6} |
|
112 |
||
113 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
114 |
% DOCUMENT STARTS |
|
115 |
\begin{document} |
|
116 |
||
117 |
\begin{frame} |
|
118 |
\titlepage |
|
119 |
\end{frame} |
|
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 |
|
263
8a4a1e5aec85
Changes made for Goa workshop .
Shantanu <shantanu@fossee.in>
parents:
262
diff
changeset
|
127 |
\section{\typ{loadtxt}} |
259
bb77a470e00a
Added loadtxt section to Day1 Session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
256
diff
changeset
|
128 |
|
263
8a4a1e5aec85
Changes made for Goa workshop .
Shantanu <shantanu@fossee.in>
parents:
262
diff
changeset
|
129 |
\begin{frame}[fragile] |
8a4a1e5aec85
Changes made for Goa workshop .
Shantanu <shantanu@fossee.in>
parents:
262
diff
changeset
|
130 |
\frametitle{Array slicing} |
8a4a1e5aec85
Changes made for Goa workshop .
Shantanu <shantanu@fossee.in>
parents:
262
diff
changeset
|
131 |
\begin{lstlisting} |
8a4a1e5aec85
Changes made for Goa workshop .
Shantanu <shantanu@fossee.in>
parents:
262
diff
changeset
|
132 |
In []: A = array([[ 1, 1, 2, -1], |
8a4a1e5aec85
Changes made for Goa workshop .
Shantanu <shantanu@fossee.in>
parents:
262
diff
changeset
|
133 |
[ 2, 5, -1, -9], |
8a4a1e5aec85
Changes made for Goa workshop .
Shantanu <shantanu@fossee.in>
parents:
262
diff
changeset
|
134 |
[ 2, 1, -1, 3], |
8a4a1e5aec85
Changes made for Goa workshop .
Shantanu <shantanu@fossee.in>
parents:
262
diff
changeset
|
135 |
[ 1, -3, 2, 7]]) |
8a4a1e5aec85
Changes made for Goa workshop .
Shantanu <shantanu@fossee.in>
parents:
262
diff
changeset
|
136 |
|
8a4a1e5aec85
Changes made for Goa workshop .
Shantanu <shantanu@fossee.in>
parents:
262
diff
changeset
|
137 |
In []: A[:,0] |
8a4a1e5aec85
Changes made for Goa workshop .
Shantanu <shantanu@fossee.in>
parents:
262
diff
changeset
|
138 |
Out[]: array([ 1, 2, 2, 1]) |
8a4a1e5aec85
Changes made for Goa workshop .
Shantanu <shantanu@fossee.in>
parents:
262
diff
changeset
|
139 |
|
8a4a1e5aec85
Changes made for Goa workshop .
Shantanu <shantanu@fossee.in>
parents:
262
diff
changeset
|
140 |
In []: A[1:3,1:3] |
8a4a1e5aec85
Changes made for Goa workshop .
Shantanu <shantanu@fossee.in>
parents:
262
diff
changeset
|
141 |
Out[]: |
8a4a1e5aec85
Changes made for Goa workshop .
Shantanu <shantanu@fossee.in>
parents:
262
diff
changeset
|
142 |
array([[ 5, -1], |
8a4a1e5aec85
Changes made for Goa workshop .
Shantanu <shantanu@fossee.in>
parents:
262
diff
changeset
|
143 |
[ 1, -1]]) |
8a4a1e5aec85
Changes made for Goa workshop .
Shantanu <shantanu@fossee.in>
parents:
262
diff
changeset
|
144 |
\end{lstlisting} |
8a4a1e5aec85
Changes made for Goa workshop .
Shantanu <shantanu@fossee.in>
parents:
262
diff
changeset
|
145 |
\end{frame} |
259
bb77a470e00a
Added loadtxt section to Day1 Session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
256
diff
changeset
|
146 |
|
bb77a470e00a
Added loadtxt section to Day1 Session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
256
diff
changeset
|
147 |
\begin{frame}[fragile] |
bb77a470e00a
Added loadtxt section to Day1 Session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
256
diff
changeset
|
148 |
\frametitle{\typ{loadtxt}} |
bb77a470e00a
Added loadtxt section to Day1 Session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
256
diff
changeset
|
149 |
\begin{itemize} |
bb77a470e00a
Added loadtxt section to Day1 Session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
256
diff
changeset
|
150 |
\item Load data from a text file. |
bb77a470e00a
Added loadtxt section to Day1 Session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
256
diff
changeset
|
151 |
\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
|
152 |
\end{itemize} |
bb77a470e00a
Added loadtxt section to Day1 Session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
256
diff
changeset
|
153 |
\begin{lstlisting} |
263
8a4a1e5aec85
Changes made for Goa workshop .
Shantanu <shantanu@fossee.in>
parents:
262
diff
changeset
|
154 |
In []: data = loadtxt('pendulum.txt') |
8a4a1e5aec85
Changes made for Goa workshop .
Shantanu <shantanu@fossee.in>
parents:
262
diff
changeset
|
155 |
In []: x = data[:, 0] |
8a4a1e5aec85
Changes made for Goa workshop .
Shantanu <shantanu@fossee.in>
parents:
262
diff
changeset
|
156 |
In []: y = data[:, 1] |
259
bb77a470e00a
Added loadtxt section to Day1 Session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
256
diff
changeset
|
157 |
\end{lstlisting} |
202 | 158 |
\end{frame} |
159 |
||
259
bb77a470e00a
Added loadtxt section to Day1 Session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
256
diff
changeset
|
160 |
%% \begin{frame}[fragile] |
bb77a470e00a
Added loadtxt section to Day1 Session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
256
diff
changeset
|
161 |
%% \frametitle{\typ{loadtxt}} |
bb77a470e00a
Added loadtxt section to Day1 Session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
256
diff
changeset
|
162 |
%% \end{frame} |
bb77a470e00a
Added loadtxt section to Day1 Session5.
Puneeth Chaganti <punchagan@fossee.in>
parents:
256
diff
changeset
|
163 |
|
221
9ed9539446bc
Updated day1 session5 and session6.
Puneeth Chaganti <punchagan@fossee.in>
parents:
202
diff
changeset
|
164 |
\section{Interpolation} |
9ed9539446bc
Updated day1 session5 and session6.
Puneeth Chaganti <punchagan@fossee.in>
parents:
202
diff
changeset
|
165 |
\begin{frame}[fragile] |
261
9cce24d00957
1 quiz, seesion5 plots, added links to reference.
Shantanu <shantanu@fossee.in>
parents:
259
diff
changeset
|
166 |
\frametitle{Loading data (revisited)} |
221
9ed9539446bc
Updated day1 session5 and session6.
Puneeth Chaganti <punchagan@fossee.in>
parents:
202
diff
changeset
|
167 |
\begin{itemize} |
256
a06196a05043
Added interpolate and loadtxt section to session 5 day 1.
Shantanu <shantanu@fossee.in>
parents:
244
diff
changeset
|
168 |
\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
|
169 |
\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
|
170 |
\item Plot the given points. |
a06196a05043
Added interpolate and loadtxt section to session 5 day 1.
Shantanu <shantanu@fossee.in>
parents:
244
diff
changeset
|
171 |
%% \item Interpolate the missing region. |
221
9ed9539446bc
Updated day1 session5 and session6.
Puneeth Chaganti <punchagan@fossee.in>
parents:
202
diff
changeset
|
172 |
\end{itemize} |
9ed9539446bc
Updated day1 session5 and session6.
Puneeth Chaganti <punchagan@fossee.in>
parents:
202
diff
changeset
|
173 |
\begin{lstlisting} |
260
1f5fea506927
Changed loadtxt to use unpack argument.
Puneeth Chaganti <punchagan@fossee.in>
parents:
259
diff
changeset
|
174 |
In []: x, y = loadtxt('points.txt', |
1f5fea506927
Changed loadtxt to use unpack argument.
Puneeth Chaganti <punchagan@fossee.in>
parents:
259
diff
changeset
|
175 |
unpack = True) |
256
a06196a05043
Added interpolate and loadtxt section to session 5 day 1.
Shantanu <shantanu@fossee.in>
parents:
244
diff
changeset
|
176 |
In []: plot(x, y, '.') |
221
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 |
\end{frame} |
9ed9539446bc
Updated day1 session5 and session6.
Puneeth Chaganti <punchagan@fossee.in>
parents:
202
diff
changeset
|
179 |
|
261
9cce24d00957
1 quiz, seesion5 plots, added links to reference.
Shantanu <shantanu@fossee.in>
parents:
259
diff
changeset
|
180 |
\begin{frame} |
9cce24d00957
1 quiz, seesion5 plots, added links to reference.
Shantanu <shantanu@fossee.in>
parents:
259
diff
changeset
|
181 |
\frametitle{Plot} |
9cce24d00957
1 quiz, seesion5 plots, added links to reference.
Shantanu <shantanu@fossee.in>
parents:
259
diff
changeset
|
182 |
\begin{center} |
9cce24d00957
1 quiz, seesion5 plots, added links to reference.
Shantanu <shantanu@fossee.in>
parents:
259
diff
changeset
|
183 |
\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
|
184 |
\end{center} |
9cce24d00957
1 quiz, seesion5 plots, added links to reference.
Shantanu <shantanu@fossee.in>
parents:
259
diff
changeset
|
185 |
\end{frame} |
221
9ed9539446bc
Updated day1 session5 and session6.
Puneeth Chaganti <punchagan@fossee.in>
parents:
202
diff
changeset
|
186 |
%% \begin{frame}[fragile] |
9ed9539446bc
Updated day1 session5 and session6.
Puneeth Chaganti <punchagan@fossee.in>
parents:
202
diff
changeset
|
187 |
%% \frametitle{Interpolation \ldots} |
9ed9539446bc
Updated day1 session5 and session6.
Puneeth Chaganti <punchagan@fossee.in>
parents:
202
diff
changeset
|
188 |
%% \begin{small} |
9ed9539446bc
Updated day1 session5 and session6.
Puneeth Chaganti <punchagan@fossee.in>
parents:
202
diff
changeset
|
189 |
%% \typ{In []: from scipy.interpolate import interp1d} |
9ed9539446bc
Updated day1 session5 and session6.
Puneeth Chaganti <punchagan@fossee.in>
parents:
202
diff
changeset
|
190 |
%% \end{small} |
9ed9539446bc
Updated day1 session5 and session6.
Puneeth Chaganti <punchagan@fossee.in>
parents:
202
diff
changeset
|
191 |
%% \begin{itemize} |
9ed9539446bc
Updated day1 session5 and session6.
Puneeth Chaganti <punchagan@fossee.in>
parents:
202
diff
changeset
|
192 |
%% \item The \typ{interp1d} function returns a function |
9ed9539446bc
Updated day1 session5 and session6.
Puneeth Chaganti <punchagan@fossee.in>
parents:
202
diff
changeset
|
193 |
%% \begin{lstlisting} |
9ed9539446bc
Updated day1 session5 and session6.
Puneeth Chaganti <punchagan@fossee.in>
parents:
202
diff
changeset
|
194 |
%% In []: f = interp1d(L, T) |
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 |
%% \item Functions can be assigned to variables |
9ed9539446bc
Updated day1 session5 and session6.
Puneeth Chaganti <punchagan@fossee.in>
parents:
202
diff
changeset
|
197 |
%% \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
|
198 |
%% \end{itemize} |
9ed9539446bc
Updated day1 session5 and session6.
Puneeth Chaganti <punchagan@fossee.in>
parents:
202
diff
changeset
|
199 |
%% \end{frame} |
9ed9539446bc
Updated day1 session5 and session6.
Puneeth Chaganti <punchagan@fossee.in>
parents:
202
diff
changeset
|
200 |
|
9ed9539446bc
Updated day1 session5 and session6.
Puneeth Chaganti <punchagan@fossee.in>
parents:
202
diff
changeset
|
201 |
%% \begin{frame}[fragile] |
9ed9539446bc
Updated day1 session5 and session6.
Puneeth Chaganti <punchagan@fossee.in>
parents:
202
diff
changeset
|
202 |
%% \frametitle{Interpolation \ldots} |
9ed9539446bc
Updated day1 session5 and session6.
Puneeth Chaganti <punchagan@fossee.in>
parents:
202
diff
changeset
|
203 |
%% \begin{lstlisting} |
9ed9539446bc
Updated day1 session5 and session6.
Puneeth Chaganti <punchagan@fossee.in>
parents:
202
diff
changeset
|
204 |
%% In []: Ln = arange(0.1,0.99,0.005) |
9ed9539446bc
Updated day1 session5 and session6.
Puneeth Chaganti <punchagan@fossee.in>
parents:
202
diff
changeset
|
205 |
%% # Interpolating! |
9ed9539446bc
Updated day1 session5 and session6.
Puneeth Chaganti <punchagan@fossee.in>
parents:
202
diff
changeset
|
206 |
%% # The new values in range of old data |
9ed9539446bc
Updated day1 session5 and session6.
Puneeth Chaganti <punchagan@fossee.in>
parents:
202
diff
changeset
|
207 |
%% In []: plot(L, T, 'o', Ln, f(Ln), '-') |
9ed9539446bc
Updated day1 session5 and session6.
Puneeth Chaganti <punchagan@fossee.in>
parents:
202
diff
changeset
|
208 |
%% In []: f = interp1d(L, T, kind='cubic') |
9ed9539446bc
Updated day1 session5 and session6.
Puneeth Chaganti <punchagan@fossee.in>
parents:
202
diff
changeset
|
209 |
%% # When kind not specified, it's linear |
9ed9539446bc
Updated day1 session5 and session6.
Puneeth Chaganti <punchagan@fossee.in>
parents:
202
diff
changeset
|
210 |
%% # Others are ... |
9ed9539446bc
Updated day1 session5 and session6.
Puneeth Chaganti <punchagan@fossee.in>
parents:
202
diff
changeset
|
211 |
%% # 'nearest', 'zero', |
9ed9539446bc
Updated day1 session5 and session6.
Puneeth Chaganti <punchagan@fossee.in>
parents:
202
diff
changeset
|
212 |
%% # 'slinear', 'quadratic' |
9ed9539446bc
Updated day1 session5 and session6.
Puneeth Chaganti <punchagan@fossee.in>
parents:
202
diff
changeset
|
213 |
%% \end{lstlisting} |
9ed9539446bc
Updated day1 session5 and session6.
Puneeth Chaganti <punchagan@fossee.in>
parents:
202
diff
changeset
|
214 |
%% \end{frame} |
9ed9539446bc
Updated day1 session5 and session6.
Puneeth Chaganti <punchagan@fossee.in>
parents:
202
diff
changeset
|
215 |
|
9ed9539446bc
Updated day1 session5 and session6.
Puneeth Chaganti <punchagan@fossee.in>
parents:
202
diff
changeset
|
216 |
\begin{frame}[fragile] |
9ed9539446bc
Updated day1 session5 and session6.
Puneeth Chaganti <punchagan@fossee.in>
parents:
202
diff
changeset
|
217 |
\frametitle{Spline Interpolation} |
9ed9539446bc
Updated day1 session5 and session6.
Puneeth Chaganti <punchagan@fossee.in>
parents:
202
diff
changeset
|
218 |
\begin{small} |
9ed9539446bc
Updated day1 session5 and session6.
Puneeth Chaganti <punchagan@fossee.in>
parents:
202
diff
changeset
|
219 |
\begin{lstlisting} |
9ed9539446bc
Updated day1 session5 and session6.
Puneeth Chaganti <punchagan@fossee.in>
parents:
202
diff
changeset
|
220 |
In []: from scipy.interpolate import splrep |
9ed9539446bc
Updated day1 session5 and session6.
Puneeth Chaganti <punchagan@fossee.in>
parents:
202
diff
changeset
|
221 |
In []: from scipy.interpolate import splev |
9ed9539446bc
Updated day1 session5 and session6.
Puneeth Chaganti <punchagan@fossee.in>
parents:
202
diff
changeset
|
222 |
\end{lstlisting} |
9ed9539446bc
Updated day1 session5 and session6.
Puneeth Chaganti <punchagan@fossee.in>
parents:
202
diff
changeset
|
223 |
\end{small} |
9ed9539446bc
Updated day1 session5 and session6.
Puneeth Chaganti <punchagan@fossee.in>
parents:
202
diff
changeset
|
224 |
\begin{itemize} |
9ed9539446bc
Updated day1 session5 and session6.
Puneeth Chaganti <punchagan@fossee.in>
parents:
202
diff
changeset
|
225 |
\item Involves two steps |
9ed9539446bc
Updated day1 session5 and session6.
Puneeth Chaganti <punchagan@fossee.in>
parents:
202
diff
changeset
|
226 |
\begin{enumerate} |
9ed9539446bc
Updated day1 session5 and session6.
Puneeth Chaganti <punchagan@fossee.in>
parents:
202
diff
changeset
|
227 |
\item Find out the spline curve, coefficients |
9ed9539446bc
Updated day1 session5 and session6.
Puneeth Chaganti <punchagan@fossee.in>
parents:
202
diff
changeset
|
228 |
\item Evaluate the spline at new points |
9ed9539446bc
Updated day1 session5 and session6.
Puneeth Chaganti <punchagan@fossee.in>
parents:
202
diff
changeset
|
229 |
\end{enumerate} |
9ed9539446bc
Updated day1 session5 and session6.
Puneeth Chaganti <punchagan@fossee.in>
parents:
202
diff
changeset
|
230 |
\end{itemize} |
9ed9539446bc
Updated day1 session5 and session6.
Puneeth Chaganti <punchagan@fossee.in>
parents:
202
diff
changeset
|
231 |
\end{frame} |
202 | 232 |
|
221
9ed9539446bc
Updated day1 session5 and session6.
Puneeth Chaganti <punchagan@fossee.in>
parents:
202
diff
changeset
|
233 |
\begin{frame}[fragile] |
9ed9539446bc
Updated day1 session5 and session6.
Puneeth Chaganti <punchagan@fossee.in>
parents:
202
diff
changeset
|
234 |
\frametitle{\typ{splrep}} |
256
a06196a05043
Added interpolate and loadtxt section to session 5 day 1.
Shantanu <shantanu@fossee.in>
parents:
244
diff
changeset
|
235 |
To find the spline curve |
221
9ed9539446bc
Updated day1 session5 and session6.
Puneeth Chaganti <punchagan@fossee.in>
parents:
202
diff
changeset
|
236 |
\begin{lstlisting} |
256
a06196a05043
Added interpolate and loadtxt section to session 5 day 1.
Shantanu <shantanu@fossee.in>
parents:
244
diff
changeset
|
237 |
In []: tck = splrep(x, y) |
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 |
\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
|
240 |
\end{frame} |
9ed9539446bc
Updated day1 session5 and session6.
Puneeth Chaganti <punchagan@fossee.in>
parents:
202
diff
changeset
|
241 |
|
9ed9539446bc
Updated day1 session5 and session6.
Puneeth Chaganti <punchagan@fossee.in>
parents:
202
diff
changeset
|
242 |
\begin{frame}[fragile] |
9ed9539446bc
Updated day1 session5 and session6.
Puneeth Chaganti <punchagan@fossee.in>
parents:
202
diff
changeset
|
243 |
\frametitle{\typ{splev}} |
263
8a4a1e5aec85
Changes made for Goa workshop .
Shantanu <shantanu@fossee.in>
parents:
262
diff
changeset
|
244 |
To Evaluate a spline and it's derivatives |
221
9ed9539446bc
Updated day1 session5 and session6.
Puneeth Chaganti <punchagan@fossee.in>
parents:
202
diff
changeset
|
245 |
\begin{lstlisting} |
256
a06196a05043
Added interpolate and loadtxt section to session 5 day 1.
Shantanu <shantanu@fossee.in>
parents:
244
diff
changeset
|
246 |
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
|
247 |
In []: Ynew = splev(Xnew, tck) |
a06196a05043
Added interpolate and loadtxt section to session 5 day 1.
Shantanu <shantanu@fossee.in>
parents:
244
diff
changeset
|
248 |
|
a06196a05043
Added interpolate and loadtxt section to session 5 day 1.
Shantanu <shantanu@fossee.in>
parents:
244
diff
changeset
|
249 |
In []: y.shape |
a06196a05043
Added interpolate and loadtxt section to session 5 day 1.
Shantanu <shantanu@fossee.in>
parents:
244
diff
changeset
|
250 |
Out[]: (40,) |
221
9ed9539446bc
Updated day1 session5 and session6.
Puneeth Chaganti <punchagan@fossee.in>
parents:
202
diff
changeset
|
251 |
|
256
a06196a05043
Added interpolate and loadtxt section to session 5 day 1.
Shantanu <shantanu@fossee.in>
parents:
244
diff
changeset
|
252 |
In []: Ynew.shape |
a06196a05043
Added interpolate and loadtxt section to session 5 day 1.
Shantanu <shantanu@fossee.in>
parents:
244
diff
changeset
|
253 |
Out[]: (150,) |
a06196a05043
Added interpolate and loadtxt section to session 5 day 1.
Shantanu <shantanu@fossee.in>
parents:
244
diff
changeset
|
254 |
|
a06196a05043
Added interpolate and loadtxt section to session 5 day 1.
Shantanu <shantanu@fossee.in>
parents:
244
diff
changeset
|
255 |
In []: plot(Xnew, Ynew) |
221
9ed9539446bc
Updated day1 session5 and session6.
Puneeth Chaganti <punchagan@fossee.in>
parents:
202
diff
changeset
|
256 |
\end{lstlisting} |
256
a06196a05043
Added interpolate and loadtxt section to session 5 day 1.
Shantanu <shantanu@fossee.in>
parents:
244
diff
changeset
|
257 |
|
221
9ed9539446bc
Updated day1 session5 and session6.
Puneeth Chaganti <punchagan@fossee.in>
parents:
202
diff
changeset
|
258 |
\end{frame} |
9ed9539446bc
Updated day1 session5 and session6.
Puneeth Chaganti <punchagan@fossee.in>
parents:
202
diff
changeset
|
259 |
|
224
668f88f20218
Added differentiation example.
Puneeth Chaganti <punchagan@fossee.in>
parents:
223
diff
changeset
|
260 |
%% \begin{frame}[fragile] |
668f88f20218
Added differentiation example.
Puneeth Chaganti <punchagan@fossee.in>
parents:
223
diff
changeset
|
261 |
%% \frametitle{Interpolation \ldots} |
668f88f20218
Added differentiation example.
Puneeth Chaganti <punchagan@fossee.in>
parents:
223
diff
changeset
|
262 |
%% \begin{itemize} |
668f88f20218
Added differentiation example.
Puneeth Chaganti <punchagan@fossee.in>
parents:
223
diff
changeset
|
263 |
%% \item |
668f88f20218
Added differentiation example.
Puneeth Chaganti <punchagan@fossee.in>
parents:
223
diff
changeset
|
264 |
%% \end{itemize} |
668f88f20218
Added differentiation example.
Puneeth Chaganti <punchagan@fossee.in>
parents:
223
diff
changeset
|
265 |
%% \end{frame} |
221
9ed9539446bc
Updated day1 session5 and session6.
Puneeth Chaganti <punchagan@fossee.in>
parents:
202
diff
changeset
|
266 |
|
265
ac31e2f3754e
Changes to session1, 5 and 6 at Goa.
Puneeth Chaganti <punchagan@fossee.in>
parents:
260
diff
changeset
|
267 |
\begin{frame} |
ac31e2f3754e
Changes to session1, 5 and 6 at Goa.
Puneeth Chaganti <punchagan@fossee.in>
parents:
260
diff
changeset
|
268 |
\frametitle{Plot} |
ac31e2f3754e
Changes to session1, 5 and 6 at Goa.
Puneeth Chaganti <punchagan@fossee.in>
parents:
260
diff
changeset
|
269 |
\begin{center} |
ac31e2f3754e
Changes to session1, 5 and 6 at Goa.
Puneeth Chaganti <punchagan@fossee.in>
parents:
260
diff
changeset
|
270 |
\includegraphics[height=2in, interpolate=true]{data/interpolate} |
ac31e2f3754e
Changes to session1, 5 and 6 at Goa.
Puneeth Chaganti <punchagan@fossee.in>
parents:
260
diff
changeset
|
271 |
\end{center} |
ac31e2f3754e
Changes to session1, 5 and 6 at Goa.
Puneeth Chaganti <punchagan@fossee.in>
parents:
260
diff
changeset
|
272 |
\end{frame} |
ac31e2f3754e
Changes to session1, 5 and 6 at Goa.
Puneeth Chaganti <punchagan@fossee.in>
parents:
260
diff
changeset
|
273 |
|
221
9ed9539446bc
Updated day1 session5 and session6.
Puneeth Chaganti <punchagan@fossee.in>
parents:
202
diff
changeset
|
274 |
\section{Differentiation} |
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{Numerical Differentiation} |
9ed9539446bc
Updated day1 session5 and session6.
Puneeth Chaganti <punchagan@fossee.in>
parents:
202
diff
changeset
|
278 |
\begin{itemize} |
9ed9539446bc
Updated day1 session5 and session6.
Puneeth Chaganti <punchagan@fossee.in>
parents:
202
diff
changeset
|
279 |
\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
|
280 |
\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
|
281 |
\item Taylor series - finite difference approximations |
9ed9539446bc
Updated day1 session5 and session6.
Puneeth Chaganti <punchagan@fossee.in>
parents:
202
diff
changeset
|
282 |
\end{itemize} |
9ed9539446bc
Updated day1 session5 and session6.
Puneeth Chaganti <punchagan@fossee.in>
parents:
202
diff
changeset
|
283 |
\begin{center} |
9ed9539446bc
Updated day1 session5 and session6.
Puneeth Chaganti <punchagan@fossee.in>
parents:
202
diff
changeset
|
284 |
\begin{tabular}{l l} |
263
8a4a1e5aec85
Changes made for Goa workshop .
Shantanu <shantanu@fossee.in>
parents:
262
diff
changeset
|
285 |
$f(x+h)=f(x)+hf^{'}(x)$ &Forward \\ |
8a4a1e5aec85
Changes made for Goa workshop .
Shantanu <shantanu@fossee.in>
parents:
262
diff
changeset
|
286 |
$f(x-h)=f(x)-hf^{'}(x)$ &Backward |
221
9ed9539446bc
Updated day1 session5 and session6.
Puneeth Chaganti <punchagan@fossee.in>
parents:
202
diff
changeset
|
287 |
\end{tabular} |
9ed9539446bc
Updated day1 session5 and session6.
Puneeth Chaganti <punchagan@fossee.in>
parents:
202
diff
changeset
|
288 |
\end{center} |
9ed9539446bc
Updated day1 session5 and session6.
Puneeth Chaganti <punchagan@fossee.in>
parents:
202
diff
changeset
|
289 |
\end{frame} |
9ed9539446bc
Updated day1 session5 and session6.
Puneeth Chaganti <punchagan@fossee.in>
parents:
202
diff
changeset
|
290 |
|
9ed9539446bc
Updated day1 session5 and session6.
Puneeth Chaganti <punchagan@fossee.in>
parents:
202
diff
changeset
|
291 |
\begin{frame}[fragile] |
9ed9539446bc
Updated day1 session5 and session6.
Puneeth Chaganti <punchagan@fossee.in>
parents:
202
diff
changeset
|
292 |
\frametitle{Forward Difference} |
9ed9539446bc
Updated day1 session5 and session6.
Puneeth Chaganti <punchagan@fossee.in>
parents:
202
diff
changeset
|
293 |
\begin{lstlisting} |
9ed9539446bc
Updated day1 session5 and session6.
Puneeth Chaganti <punchagan@fossee.in>
parents:
202
diff
changeset
|
294 |
In []: x = linspace(0, 2*pi, 100) |
9ed9539446bc
Updated day1 session5 and session6.
Puneeth Chaganti <punchagan@fossee.in>
parents:
202
diff
changeset
|
295 |
In []: y = sin(x) |
9ed9539446bc
Updated day1 session5 and session6.
Puneeth Chaganti <punchagan@fossee.in>
parents:
202
diff
changeset
|
296 |
In []: deltax = x[1] - x[0] |
9ed9539446bc
Updated day1 session5 and session6.
Puneeth Chaganti <punchagan@fossee.in>
parents:
202
diff
changeset
|
297 |
\end{lstlisting} |
9ed9539446bc
Updated day1 session5 and session6.
Puneeth Chaganti <punchagan@fossee.in>
parents:
202
diff
changeset
|
298 |
Obtain the finite forward difference of y |
9ed9539446bc
Updated day1 session5 and session6.
Puneeth Chaganti <punchagan@fossee.in>
parents:
202
diff
changeset
|
299 |
\end{frame} |
9ed9539446bc
Updated day1 session5 and session6.
Puneeth Chaganti <punchagan@fossee.in>
parents:
202
diff
changeset
|
300 |
|
9ed9539446bc
Updated day1 session5 and session6.
Puneeth Chaganti <punchagan@fossee.in>
parents:
202
diff
changeset
|
301 |
\begin{frame}[fragile] |
9ed9539446bc
Updated day1 session5 and session6.
Puneeth Chaganti <punchagan@fossee.in>
parents:
202
diff
changeset
|
302 |
\frametitle{Forward Difference \ldots} |
9ed9539446bc
Updated day1 session5 and session6.
Puneeth Chaganti <punchagan@fossee.in>
parents:
202
diff
changeset
|
303 |
\begin{lstlisting} |
9ed9539446bc
Updated day1 session5 and session6.
Puneeth Chaganti <punchagan@fossee.in>
parents:
202
diff
changeset
|
304 |
In []: fD = (y[1:] - y[:-1]) / deltax |
263
8a4a1e5aec85
Changes made for Goa workshop .
Shantanu <shantanu@fossee.in>
parents:
262
diff
changeset
|
305 |
In []: print len(fD) |
8a4a1e5aec85
Changes made for Goa workshop .
Shantanu <shantanu@fossee.in>
parents:
262
diff
changeset
|
306 |
Out[]: 99 |
8a4a1e5aec85
Changes made for Goa workshop .
Shantanu <shantanu@fossee.in>
parents:
262
diff
changeset
|
307 |
In []: plot(x, y) |
8a4a1e5aec85
Changes made for Goa workshop .
Shantanu <shantanu@fossee.in>
parents:
262
diff
changeset
|
308 |
In []: plot(x[:-1], fD) |
221
9ed9539446bc
Updated day1 session5 and session6.
Puneeth Chaganti <punchagan@fossee.in>
parents:
202
diff
changeset
|
309 |
\end{lstlisting} |
265
ac31e2f3754e
Changes to session1, 5 and 6 at Goa.
Puneeth Chaganti <punchagan@fossee.in>
parents:
260
diff
changeset
|
310 |
\vspace{-.2in} |
221
9ed9539446bc
Updated day1 session5 and session6.
Puneeth Chaganti <punchagan@fossee.in>
parents:
202
diff
changeset
|
311 |
\begin{center} |
265
ac31e2f3754e
Changes to session1, 5 and 6 at Goa.
Puneeth Chaganti <punchagan@fossee.in>
parents:
260
diff
changeset
|
312 |
\includegraphics[height=1.8in, interpolate=true]{data/fwdDiff} |
221
9ed9539446bc
Updated day1 session5 and session6.
Puneeth Chaganti <punchagan@fossee.in>
parents:
202
diff
changeset
|
313 |
\end{center} |
9ed9539446bc
Updated day1 session5 and session6.
Puneeth Chaganti <punchagan@fossee.in>
parents:
202
diff
changeset
|
314 |
\end{frame} |
9ed9539446bc
Updated day1 session5 and session6.
Puneeth Chaganti <punchagan@fossee.in>
parents:
202
diff
changeset
|
315 |
|
9ed9539446bc
Updated day1 session5 and session6.
Puneeth Chaganti <punchagan@fossee.in>
parents:
202
diff
changeset
|
316 |
\begin{frame}[fragile] |
224
668f88f20218
Added differentiation example.
Puneeth Chaganti <punchagan@fossee.in>
parents:
223
diff
changeset
|
317 |
\frametitle{Example} |
668f88f20218
Added differentiation example.
Puneeth Chaganti <punchagan@fossee.in>
parents:
223
diff
changeset
|
318 |
\begin{itemize} |
668f88f20218
Added differentiation example.
Puneeth Chaganti <punchagan@fossee.in>
parents:
223
diff
changeset
|
319 |
\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
|
320 |
\item Find velocity \& acceleration in x, y directions |
668f88f20218
Added differentiation example.
Puneeth Chaganti <punchagan@fossee.in>
parents:
223
diff
changeset
|
321 |
\end{itemize} |
668f88f20218
Added differentiation example.
Puneeth Chaganti <punchagan@fossee.in>
parents:
223
diff
changeset
|
322 |
\small{ |
668f88f20218
Added differentiation example.
Puneeth Chaganti <punchagan@fossee.in>
parents:
223
diff
changeset
|
323 |
\begin{center} |
668f88f20218
Added differentiation example.
Puneeth Chaganti <punchagan@fossee.in>
parents:
223
diff
changeset
|
324 |
\begin{tabular}{| c | c | c |} |
668f88f20218
Added differentiation example.
Puneeth Chaganti <punchagan@fossee.in>
parents:
223
diff
changeset
|
325 |
\hline |
668f88f20218
Added differentiation example.
Puneeth Chaganti <punchagan@fossee.in>
parents:
223
diff
changeset
|
326 |
$X$ & $Y$ \\ \hline |
668f88f20218
Added differentiation example.
Puneeth Chaganti <punchagan@fossee.in>
parents:
223
diff
changeset
|
327 |
0. & 0.\\ \hline |
668f88f20218
Added differentiation example.
Puneeth Chaganti <punchagan@fossee.in>
parents:
223
diff
changeset
|
328 |
0.25 & 0.47775\\ \hline |
668f88f20218
Added differentiation example.
Puneeth Chaganti <punchagan@fossee.in>
parents:
223
diff
changeset
|
329 |
0.5 & 0.931\\ \hline |
668f88f20218
Added differentiation example.
Puneeth Chaganti <punchagan@fossee.in>
parents:
223
diff
changeset
|
330 |
0.75 & 1.35975\\ \hline |
668f88f20218
Added differentiation example.
Puneeth Chaganti <punchagan@fossee.in>
parents:
223
diff
changeset
|
331 |
1. & 1.764\\ \hline |
668f88f20218
Added differentiation example.
Puneeth Chaganti <punchagan@fossee.in>
parents:
223
diff
changeset
|
332 |
1.25 & 2.14375\\ \hline |
668f88f20218
Added differentiation example.
Puneeth Chaganti <punchagan@fossee.in>
parents:
223
diff
changeset
|
333 |
\vdots & \vdots\\ \hline |
668f88f20218
Added differentiation example.
Puneeth Chaganti <punchagan@fossee.in>
parents:
223
diff
changeset
|
334 |
\end{tabular} |
668f88f20218
Added differentiation example.
Puneeth Chaganti <punchagan@fossee.in>
parents:
223
diff
changeset
|
335 |
\end{center}} |
668f88f20218
Added differentiation example.
Puneeth Chaganti <punchagan@fossee.in>
parents:
223
diff
changeset
|
336 |
\end{frame} |
668f88f20218
Added differentiation example.
Puneeth Chaganti <punchagan@fossee.in>
parents:
223
diff
changeset
|
337 |
|
668f88f20218
Added differentiation example.
Puneeth Chaganti <punchagan@fossee.in>
parents:
223
diff
changeset
|
338 |
\begin{frame}[fragile] |
668f88f20218
Added differentiation example.
Puneeth Chaganti <punchagan@fossee.in>
parents:
223
diff
changeset
|
339 |
\frametitle{Example \ldots} |
668f88f20218
Added differentiation example.
Puneeth Chaganti <punchagan@fossee.in>
parents:
223
diff
changeset
|
340 |
\begin{itemize} |
668f88f20218
Added differentiation example.
Puneeth Chaganti <punchagan@fossee.in>
parents:
223
diff
changeset
|
341 |
\item Read the file |
265
ac31e2f3754e
Changes to session1, 5 and 6 at Goa.
Puneeth Chaganti <punchagan@fossee.in>
parents:
260
diff
changeset
|
342 |
\item Obtain an array of X, Y |
224
668f88f20218
Added differentiation example.
Puneeth Chaganti <punchagan@fossee.in>
parents:
223
diff
changeset
|
343 |
\item Obtain velocity and acceleration |
668f88f20218
Added differentiation example.
Puneeth Chaganti <punchagan@fossee.in>
parents:
223
diff
changeset
|
344 |
\item use \typ{deltaT = 0.05} |
668f88f20218
Added differentiation example.
Puneeth Chaganti <punchagan@fossee.in>
parents:
223
diff
changeset
|
345 |
\end{itemize} |
668f88f20218
Added differentiation example.
Puneeth Chaganti <punchagan@fossee.in>
parents:
223
diff
changeset
|
346 |
\begin{lstlisting} |
265
ac31e2f3754e
Changes to session1, 5 and 6 at Goa.
Puneeth Chaganti <punchagan@fossee.in>
parents:
260
diff
changeset
|
347 |
In []: data = loadtxt('pos.txt') |
ac31e2f3754e
Changes to session1, 5 and 6 at Goa.
Puneeth Chaganti <punchagan@fossee.in>
parents:
260
diff
changeset
|
348 |
In []: X,Y = data[:,0], data[:,1] |
224
668f88f20218
Added differentiation example.
Puneeth Chaganti <punchagan@fossee.in>
parents:
223
diff
changeset
|
349 |
In []: S = array([X, Y]) |
668f88f20218
Added differentiation example.
Puneeth Chaganti <punchagan@fossee.in>
parents:
223
diff
changeset
|
350 |
\end{lstlisting} |
668f88f20218
Added differentiation example.
Puneeth Chaganti <punchagan@fossee.in>
parents:
223
diff
changeset
|
351 |
\end{frame} |
668f88f20218
Added differentiation example.
Puneeth Chaganti <punchagan@fossee.in>
parents:
223
diff
changeset
|
352 |
|
668f88f20218
Added differentiation example.
Puneeth Chaganti <punchagan@fossee.in>
parents:
223
diff
changeset
|
353 |
|
668f88f20218
Added differentiation example.
Puneeth Chaganti <punchagan@fossee.in>
parents:
223
diff
changeset
|
354 |
\begin{frame}[fragile] |
668f88f20218
Added differentiation example.
Puneeth Chaganti <punchagan@fossee.in>
parents:
223
diff
changeset
|
355 |
\frametitle{Example \ldots} |
668f88f20218
Added differentiation example.
Puneeth Chaganti <punchagan@fossee.in>
parents:
223
diff
changeset
|
356 |
\begin{lstlisting} |
668f88f20218
Added differentiation example.
Puneeth Chaganti <punchagan@fossee.in>
parents:
223
diff
changeset
|
357 |
In []: deltaT = 0.05 |
668f88f20218
Added differentiation example.
Puneeth Chaganti <punchagan@fossee.in>
parents:
223
diff
changeset
|
358 |
|
668f88f20218
Added differentiation example.
Puneeth Chaganti <punchagan@fossee.in>
parents:
223
diff
changeset
|
359 |
In []: v = (S[:,1:]-S[:,:-1])/deltaT |
668f88f20218
Added differentiation example.
Puneeth Chaganti <punchagan@fossee.in>
parents:
223
diff
changeset
|
360 |
|
668f88f20218
Added differentiation example.
Puneeth Chaganti <punchagan@fossee.in>
parents:
223
diff
changeset
|
361 |
In []: a = (v[:,1:]-v[:,:-1])/deltaT |
668f88f20218
Added differentiation example.
Puneeth Chaganti <punchagan@fossee.in>
parents:
223
diff
changeset
|
362 |
\end{lstlisting} |
265
ac31e2f3754e
Changes to session1, 5 and 6 at Goa.
Puneeth Chaganti <punchagan@fossee.in>
parents:
260
diff
changeset
|
363 |
\end{frame} |
ac31e2f3754e
Changes to session1, 5 and 6 at Goa.
Puneeth Chaganti <punchagan@fossee.in>
parents:
260
diff
changeset
|
364 |
|
ac31e2f3754e
Changes to session1, 5 and 6 at Goa.
Puneeth Chaganti <punchagan@fossee.in>
parents:
260
diff
changeset
|
365 |
\begin{frame}[fragile] |
ac31e2f3754e
Changes to session1, 5 and 6 at Goa.
Puneeth Chaganti <punchagan@fossee.in>
parents:
260
diff
changeset
|
366 |
\frametitle{Example \ldots} |
ac31e2f3754e
Changes to session1, 5 and 6 at Goa.
Puneeth Chaganti <punchagan@fossee.in>
parents:
260
diff
changeset
|
367 |
Plotting Y, $v_y$, $a_y$ |
ac31e2f3754e
Changes to session1, 5 and 6 at Goa.
Puneeth Chaganti <punchagan@fossee.in>
parents:
260
diff
changeset
|
368 |
\begin{lstlisting} |
ac31e2f3754e
Changes to session1, 5 and 6 at Goa.
Puneeth Chaganti <punchagan@fossee.in>
parents:
260
diff
changeset
|
369 |
In []: plot(Y) |
ac31e2f3754e
Changes to session1, 5 and 6 at Goa.
Puneeth Chaganti <punchagan@fossee.in>
parents:
260
diff
changeset
|
370 |
In []: plot(v[1,:]) |
ac31e2f3754e
Changes to session1, 5 and 6 at Goa.
Puneeth Chaganti <punchagan@fossee.in>
parents:
260
diff
changeset
|
371 |
In []: plot(a[1,:]) |
ac31e2f3754e
Changes to session1, 5 and 6 at Goa.
Puneeth Chaganti <punchagan@fossee.in>
parents:
260
diff
changeset
|
372 |
\end{lstlisting} |
ac31e2f3754e
Changes to session1, 5 and 6 at Goa.
Puneeth Chaganti <punchagan@fossee.in>
parents:
260
diff
changeset
|
373 |
\begin{center} |
ac31e2f3754e
Changes to session1, 5 and 6 at Goa.
Puneeth Chaganti <punchagan@fossee.in>
parents:
260
diff
changeset
|
374 |
\includegraphics[height=1.8in, interpolate=true]{data/pos_vel_accel} |
ac31e2f3754e
Changes to session1, 5 and 6 at Goa.
Puneeth Chaganti <punchagan@fossee.in>
parents:
260
diff
changeset
|
375 |
\end{center} |
221
9ed9539446bc
Updated day1 session5 and session6.
Puneeth Chaganti <punchagan@fossee.in>
parents:
202
diff
changeset
|
376 |
\end{frame} |
9ed9539446bc
Updated day1 session5 and session6.
Puneeth Chaganti <punchagan@fossee.in>
parents:
202
diff
changeset
|
377 |
|
9ed9539446bc
Updated day1 session5 and session6.
Puneeth Chaganti <punchagan@fossee.in>
parents:
202
diff
changeset
|
378 |
\section{Quadrature} |
202 | 379 |
|
380 |
\begin{frame}[fragile] |
|
381 |
\frametitle{Quadrature} |
|
263
8a4a1e5aec85
Changes made for Goa workshop .
Shantanu <shantanu@fossee.in>
parents:
262
diff
changeset
|
382 |
|
8a4a1e5aec85
Changes made for Goa workshop .
Shantanu <shantanu@fossee.in>
parents:
262
diff
changeset
|
383 |
\emphbar{$\int_0^1(sin(x) + x^2)$} |
8a4a1e5aec85
Changes made for Goa workshop .
Shantanu <shantanu@fossee.in>
parents:
262
diff
changeset
|
384 |
|
8a4a1e5aec85
Changes made for Goa workshop .
Shantanu <shantanu@fossee.in>
parents:
262
diff
changeset
|
385 |
\typ{In []: from scipy.integrate import quad} |
8a4a1e5aec85
Changes made for Goa workshop .
Shantanu <shantanu@fossee.in>
parents:
262
diff
changeset
|
386 |
|
202 | 387 |
\begin{itemize} |
388 |
\item Inputs - function to integrate, limits |
|
389 |
\end{itemize} |
|
390 |
\begin{lstlisting} |
|
265
ac31e2f3754e
Changes to session1, 5 and 6 at Goa.
Puneeth Chaganti <punchagan@fossee.in>
parents:
260
diff
changeset
|
391 |
In []: quad(sin(x)+x**2, 0, 1) |
ac31e2f3754e
Changes to session1, 5 and 6 at Goa.
Puneeth Chaganti <punchagan@fossee.in>
parents:
260
diff
changeset
|
392 |
NameError: name 'x' is not defined |
202 | 393 |
In []: x = 0 |
394 |
In []: quad(sin(x)+x**2, 0, 1) |
|
395 |
\end{lstlisting} |
|
221
9ed9539446bc
Updated day1 session5 and session6.
Puneeth Chaganti <punchagan@fossee.in>
parents:
202
diff
changeset
|
396 |
\begin{small} |
202 | 397 |
\alert{\typ{error:}} |
398 |
\typ{First argument must be a callable function.} |
|
221
9ed9539446bc
Updated day1 session5 and session6.
Puneeth Chaganti <punchagan@fossee.in>
parents:
202
diff
changeset
|
399 |
\end{small} |
202 | 400 |
\end{frame} |
401 |
||
402 |
\begin{frame}[fragile] |
|
403 |
\frametitle{Functions - Definition} |
|
221
9ed9539446bc
Updated day1 session5 and session6.
Puneeth Chaganti <punchagan@fossee.in>
parents:
202
diff
changeset
|
404 |
We have been using them all along. Now let's see how to define them. |
202 | 405 |
\begin{lstlisting} |
406 |
In []: def f(x): |
|
407 |
return sin(x)+x**2 |
|
408 |
In []: quad(f, 0, 1) |
|
409 |
\end{lstlisting} |
|
410 |
\begin{itemize} |
|
411 |
\item \typ{def} |
|
223
081600805dde
Minor edits to sessions 5 and 6.
Puneeth Chaganti <punchagan@fossee.in>
parents:
222
diff
changeset
|
412 |
\item name |
202 | 413 |
\item arguments |
414 |
\item \typ{return} |
|
415 |
\end{itemize} |
|
416 |
\end{frame} |
|
417 |
||
418 |
\begin{frame}[fragile] |
|
419 |
\frametitle{Functions - Calling them} |
|
420 |
\begin{lstlisting} |
|
421 |
In [15]: f() |
|
422 |
--------------------------------------- |
|
423 |
\end{lstlisting} |
|
424 |
\alert{\typ{TypeError:}}\typ{f() takes exactly 1 argument} |
|
425 |
\typ{(0 given)} |
|
426 |
\begin{lstlisting} |
|
427 |
In []: f(0) |
|
428 |
Out[]: 0.0 |
|
429 |
In []: f(1) |
|
430 |
Out[]: 1.8414709848078965 |
|
431 |
\end{lstlisting} |
|
223
081600805dde
Minor edits to sessions 5 and 6.
Puneeth Chaganti <punchagan@fossee.in>
parents:
222
diff
changeset
|
432 |
More on Functions later \ldots |
202 | 433 |
\end{frame} |
434 |
||
435 |
\begin{frame}[fragile] |
|
436 |
\frametitle{Quadrature \ldots} |
|
437 |
\begin{lstlisting} |
|
438 |
In []: quad(f, 0, 1) |
|
439 |
\end{lstlisting} |
|
440 |
Returns the integral and an estimate of the absolute error in the result. |
|
441 |
\begin{itemize} |
|
263
8a4a1e5aec85
Changes made for Goa workshop .
Shantanu <shantanu@fossee.in>
parents:
262
diff
changeset
|
442 |
\item \typ{dblquad}, \typ{tplquad} are available |
202 | 443 |
\end{itemize} |
444 |
\end{frame} |
|
445 |
||
446 |
\begin{frame} |
|
447 |
\frametitle{Things we have learned} |
|
448 |
\begin{itemize} |
|
221
9ed9539446bc
Updated day1 session5 and session6.
Puneeth Chaganti <punchagan@fossee.in>
parents:
202
diff
changeset
|
449 |
\item Interpolation |
9ed9539446bc
Updated day1 session5 and session6.
Puneeth Chaganti <punchagan@fossee.in>
parents:
202
diff
changeset
|
450 |
\item Differentiation |
202 | 451 |
\item Functions |
452 |
\begin{itemize} |
|
453 |
\item Definition |
|
454 |
\item Calling |
|
455 |
\item Default Arguments |
|
456 |
\item Keyword Arguments |
|
457 |
\end{itemize} |
|
458 |
\item Quadrature |
|
459 |
\end{itemize} |
|
460 |
\end{frame} |
|
223
081600805dde
Minor edits to sessions 5 and 6.
Puneeth Chaganti <punchagan@fossee.in>
parents:
222
diff
changeset
|
461 |
|
202 | 462 |
\end{document} |
463 |