author | Santosh G. Vattam <vattam.santosh@gmail.com> |
Wed, 11 Nov 2009 12:52:50 +0530 | |
changeset 303 | 26f5e864a135 |
parent 284 | 3c191accbb32 |
child 340 | 347ff2714deb |
permissions | -rw-r--r-- |
284
3c191accbb32
Added Cheatsheets for day1.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
1 |
\documentclass[12pt]{article} |
3c191accbb32
Added Cheatsheets for day1.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
2 |
\title{Matrices and Solution of Equations} |
3c191accbb32
Added Cheatsheets for day1.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
3 |
\author{FOSSEE} |
3c191accbb32
Added Cheatsheets for day1.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
4 |
\begin{document} |
3c191accbb32
Added Cheatsheets for day1.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
5 |
\date{} |
3c191accbb32
Added Cheatsheets for day1.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
6 |
\vspace{-1in} |
3c191accbb32
Added Cheatsheets for day1.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
7 |
\begin{center} |
3c191accbb32
Added Cheatsheets for day1.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
8 |
\LARGE{Interpolation, Differentiation and Integration}\\ |
3c191accbb32
Added Cheatsheets for day1.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
9 |
\large{FOSSEE} |
3c191accbb32
Added Cheatsheets for day1.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
10 |
\end{center} |
3c191accbb32
Added Cheatsheets for day1.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
11 |
\section{} |
3c191accbb32
Added Cheatsheets for day1.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
12 |
Loading a data file |
3c191accbb32
Added Cheatsheets for day1.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
13 |
\begin{verbatim} |
3c191accbb32
Added Cheatsheets for day1.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
14 |
In [2]: x, y = loadtxt('points.txt', unpack = True) |
3c191accbb32
Added Cheatsheets for day1.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
15 |
#load data file directly into Arrays. |
3c191accbb32
Added Cheatsheets for day1.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
16 |
\end{verbatim} |
3c191accbb32
Added Cheatsheets for day1.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
17 |
\section{} |
3c191accbb32
Added Cheatsheets for day1.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
18 |
Interploate |
3c191accbb32
Added Cheatsheets for day1.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
19 |
\begin{verbatim} |
3c191accbb32
Added Cheatsheets for day1.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
20 |
In []: from scipy.interpolate import splrep |
3c191accbb32
Added Cheatsheets for day1.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
21 |
In []: tck = splrep(x,y) #get spline curve representation for x,y. |
3c191accbb32
Added Cheatsheets for day1.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
22 |
In []: from scipy.interpolate import splev |
3c191accbb32
Added Cheatsheets for day1.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
23 |
#To evaluate spline and it's derivatives. |
3c191accbb32
Added Cheatsheets for day1.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
24 |
In []: Xnew = arange(0.01,3,0.02) |
3c191accbb32
Added Cheatsheets for day1.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
25 |
#missing set of points |
3c191accbb32
Added Cheatsheets for day1.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
26 |
In []: Ynew = splev(Xnew, tck) |
3c191accbb32
Added Cheatsheets for day1.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
27 |
#Value of function at Xnew |
3c191accbb32
Added Cheatsheets for day1.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
28 |
In []: plot(Xnew, Ynew) |
3c191accbb32
Added Cheatsheets for day1.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
29 |
\end{verbatim} |
3c191accbb32
Added Cheatsheets for day1.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
30 |
|
3c191accbb32
Added Cheatsheets for day1.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
31 |
\section{Differentiation} |
3c191accbb32
Added Cheatsheets for day1.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
32 |
Taylor series - finite difference approximations |
3c191accbb32
Added Cheatsheets for day1.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
33 |
$f(x+h)=f(x)+hf^{'}(x)$ Forward |
3c191accbb32
Added Cheatsheets for day1.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
34 |
\begin{verbatim} |
3c191accbb32
Added Cheatsheets for day1.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
35 |
In []: x = linspace(0, 2*pi, 100) |
3c191accbb32
Added Cheatsheets for day1.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
36 |
In []: y = sin(x) |
3c191accbb32
Added Cheatsheets for day1.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
37 |
In []: deltax = x[1] - x[0] |
3c191accbb32
Added Cheatsheets for day1.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
38 |
In []: fD = (y[1:] - y[:-1]) / deltax |
3c191accbb32
Added Cheatsheets for day1.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
39 |
#fD is the required forward difference |
3c191accbb32
Added Cheatsheets for day1.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
40 |
\end{verbatim} |
3c191accbb32
Added Cheatsheets for day1.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
41 |
|
3c191accbb32
Added Cheatsheets for day1.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
42 |
\section{Quadrature} |
3c191accbb32
Added Cheatsheets for day1.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
43 |
$\int_0^1(sin(x) + x^2)$ |
3c191accbb32
Added Cheatsheets for day1.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
44 |
In []: def f(x): |
3c191accbb32
Added Cheatsheets for day1.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
45 |
return sin(x)+x**2 |
3c191accbb32
Added Cheatsheets for day1.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
46 |
In []: from scipy.integrate import quad |
3c191accbb32
Added Cheatsheets for day1.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
47 |
In []: quad(f, 0, 1) |
3c191accbb32
Added Cheatsheets for day1.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
48 |
\end{document} |
3c191accbb32
Added Cheatsheets for day1.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
49 |