day1/session4.tex
changeset 179 eea01ca072ff
parent 178 8a3a9d98fa84
child 185 e59ab9ab1a89
equal deleted inserted replaced
178:8a3a9d98fa84 179:eea01ca072ff
   122   \frametitle{Outline}
   122   \frametitle{Outline}
   123   \tableofcontents
   123   \tableofcontents
   124 %  \pausesections
   124 %  \pausesections
   125 \end{frame}
   125 \end{frame}
   126 
   126 
       
   127 \section{Solving linear equations}
       
   128 \begin{frame}[fragile]
       
   129 \frametitle{Solution of equations}
       
   130 Consider,
       
   131   \begin{align*}
       
   132     3x + 2y - z  & = 1 \\
       
   133     2x - 2y + 4z  & = -2 \\
       
   134     -x + \frac{1}{2}y -z & = 0
       
   135   \end{align*}
       
   136 Solution:
       
   137   \begin{align*}
       
   138     x & = 1 \\
       
   139     y & = -2 \\
       
   140     z & = -2
       
   141   \end{align*}
       
   142 \end{frame}
       
   143 
       
   144 \begin{frame}[fragile]
       
   145 \frametitle{Solving using Matrices}
       
   146 Let us now look at how to solve this using \kwrd{matrices}
       
   147   \begin{lstlisting}
       
   148     In []: A = matrix([[3,2,-1],[2,-2,4],[-1, 0.5, -1]])
       
   149     In []: b = matrix([[1], [-2], [0]])
       
   150     In []: x = linalg.solve(A, b)
       
   151     In []: Ax = dot(A, x)
       
   152     In []: allclose(Ax, b)
       
   153     Out[]: True
       
   154   \end{lstlisting}
       
   155 \end{frame}
       
   156 
       
   157 \begin{frame}[fragile]
       
   158 \frametitle{Solution:}
       
   159 \begin{lstlisting}
       
   160 In []: x
       
   161 Out[]: 
       
   162 array([[ 1.],
       
   163        [-2.],
       
   164        [-2.]])
       
   165 
       
   166 In []: Ax
       
   167 Out[]: 
       
   168 matrix([[  1.00000000e+00],
       
   169         [ -2.00000000e+00],
       
   170         [  2.22044605e-16]])
       
   171 \end{lstlisting}
       
   172 \end{frame}
       
   173 
   127 \section{Matrices}
   174 \section{Matrices}
   128 \subsection{Initializing}
   175 \subsection{Initializing}
   129 \begin{frame}[fragile]
   176 \begin{frame}[fragile]
   130 \frametitle{Matrices: Initializing}
   177 \frametitle{Matrices: Initializing}
   131 \begin{lstlisting}
   178 \begin{lstlisting}
   142 \end{frame}
   189 \end{frame}
   143 
   190 
   144 \subsection{Basic Operations}
   191 \subsection{Basic Operations}
   145 \begin{frame}[fragile]
   192 \begin{frame}[fragile]
   146 \frametitle{Inverse of a Matrix}
   193 \frametitle{Inverse of a Matrix}
       
   194 
   147 \begin{small}
   195 \begin{small}
   148 \begin{lstlisting}
   196 \begin{lstlisting}
   149   In []: linalg.inv(a)
   197 In []: linalg.inv(A)
   150   Out[]: 
   198 Out[]: 
   151   matrix([[  3.15221191e+15,  -6.30442381e+15,   3.15221191e+15],
   199 matrix([[ 0.07734807,  0.01657459,  0.32044199],
   152           [ -6.30442381e+15,   1.26088476e+16,  -6.30442381e+15],
   200         [ 0.09944751, -0.12154696, -0.01657459],
   153           [  3.15221191e+15,  -6.30442381e+15,   3.15221191e+15]])
   201         [-0.02762431, -0.07734807,  0.17127072]])
       
   202 
   154 \end{lstlisting}
   203 \end{lstlisting}
   155 \end{small}
   204 \end{small}
   156 \end{frame}
   205 \end{frame}
   157 
   206 
   158 \begin{frame}[fragile]
   207 \begin{frame}[fragile]
   174 \begin{frame}[fragile]
   223 \begin{frame}[fragile]
   175 \frametitle{Eigen Values and Eigen Matrix}
   224 \frametitle{Eigen Values and Eigen Matrix}
   176 \begin{small}
   225 \begin{small}
   177 \begin{lstlisting}
   226 \begin{lstlisting}
   178   In []: linalg.eigvals(a)
   227   In []: linalg.eigvals(a)
   179   Out[]: array([  1.61168440e+01,  -1.11684397e+00,  -1.22196337e-15])
   228   Out[]: array([1.61168440e+01, -1.11684397e+00, -1.22196337e-15])
   180 
   229 
   181   In []: linalg.eig(a)
   230   In []: linalg.eig(a)
   182   Out[]: 
   231   Out[]: 
   183   (array([  1.61168440e+01,  -1.11684397e+00,  -1.22196337e-15]),
   232   (array([ 1.61168440e+01, -1.11684397e+00, -1.22196337e-15]),
   184    matrix([[-0.23197069, -0.78583024,  0.40824829],
   233    matrix([[-0.23197069, -0.78583024,  0.40824829],
   185           [-0.52532209, -0.08675134, -0.81649658],
   234           [-0.52532209, -0.08675134, -0.81649658],
   186           [-0.8186735 ,  0.61232756,  0.40824829]]))
   235           [-0.8186735 ,  0.61232756,  0.40824829]]))
   187 \end{lstlisting}
   236 \end{lstlisting}
   188 \end{small}
   237 \end{small}
   189 \end{frame}
       
   190 
       
   191 \section{Solving linear equations}
       
   192 \begin{frame}[fragile]
       
   193 \frametitle{Solution of equations}
       
   194 Example problem: Consider the set of equations
       
   195 \vspace{-0.1in}
       
   196   \begin{align*}
       
   197     3x + 2y - z  & = 1 \\
       
   198     2x - 2y + 4z  & = -2 \\
       
   199     -x + \frac{1}{2}y -z & = 0
       
   200   \end{align*}
       
   201 \vspace{-0.08in}
       
   202   To Solve this, 
       
   203   \begin{lstlisting}
       
   204     In []: A = array([[3,2,-1],[2,-2,4],[-1, 0.5, -1]])
       
   205     In []: b = array([1, -2, 0])
       
   206     In []: x = linalg.solve(A, b)
       
   207     In []: Ax = dot(A, x)
       
   208     In []: allclose(Ax, b)
       
   209     Out[]: True
       
   210   \end{lstlisting}
       
   211 \end{frame}
   238 \end{frame}
   212 
   239 
   213 
   240 
   214 \section{Integration}
   241 \section{Integration}
   215 
   242