day1/cheatsheet5.tex
changeset 348 bf9a90676978
parent 347 22e3480e4794
child 349 58366fe3839b
equal deleted inserted replaced
347:22e3480e4794 348:bf9a90676978
     1 \documentclass[12pt]{article}
       
     2 \title{Matrices and Solution of Equations}
       
     3 \author{FOSSEE}
       
     4 \begin{document}
       
     5 \date{}
       
     6 \vspace{-1in}
       
     7 \begin{center}
       
     8 \LARGE{Interpolation, Differentiation and Integration}\\
       
     9 \large{FOSSEE}
       
    10 \end{center}
       
    11 \section{}
       
    12 Loading a data file
       
    13 \begin{verbatim}
       
    14 In [2]: x, y = loadtxt('points.txt', unpack = True)
       
    15 #load data file directly into Arrays.
       
    16 \end{verbatim}
       
    17 \section{}
       
    18 Interpolate
       
    19 \begin{verbatim}
       
    20 In []: from scipy.interpolate import splrep
       
    21 In []: tck = splrep(x,y) #get spline curve representation for x,y.
       
    22 In []: from scipy.interpolate import splev
       
    23 #To evaluate spline and it's derivatives.
       
    24 In []: Xnew = arange(0.01,3,0.02)
       
    25 #missing set of points
       
    26 In []: Ynew = splev(Xnew, tck)
       
    27 #Value of function at Xnew
       
    28 In []: plot(Xnew, Ynew)
       
    29 \end{verbatim}
       
    30 
       
    31 \section{Differentiation}
       
    32 Taylor series - finite difference approximations
       
    33 $f(x+h)=f(x)+hf^{'}(x)$ Forward
       
    34 \begin{verbatim}
       
    35 In []: x = linspace(0, 2*pi, 100)
       
    36 In []: y = sin(x)
       
    37 In []: deltax = x[1] - x[0]
       
    38 In []: fD = (y[1:] - y[:-1]) / deltax 
       
    39 #fD is the required forward difference
       
    40 \end{verbatim}
       
    41 
       
    42 \section{Quadrature}
       
    43 $\int_0^1(sin(x) + x^2)$ 
       
    44 In []: def f(x):
       
    45            return sin(x)+x**2
       
    46 In []: from scipy.integrate import quad
       
    47 In []: quad(f, 0, 1)
       
    48 \end{document}
       
    49