day1/session4.tex
changeset 273 c378d1ffb1d1
parent 272 e5fc37a9ca96
child 277 ef9337f7048c
equal deleted inserted replaced
272:e5fc37a9ca96 273:c378d1ffb1d1
   472 \item Now plot Tline vs. L, to get the Least squares fit line. 
   472 \item Now plot Tline vs. L, to get the Least squares fit line. 
   473 \end{itemize}
   473 \end{itemize}
   474 \begin{lstlisting}
   474 \begin{lstlisting}
   475 In []: plot(L, Tline)
   475 In []: plot(L, Tline)
   476 \end{lstlisting}
   476 \end{lstlisting}
   477 \end{frame}
       
   478 
       
   479 \section{Solving linear equations}
       
   480 
       
   481 \begin{frame}[fragile]
       
   482 \frametitle{Solution of equations}
       
   483 Consider,
       
   484   \begin{align*}
       
   485     3x + 2y - z  & = 1 \\
       
   486     2x - 2y + 4z  & = -2 \\
       
   487     -x + \frac{1}{2}y -z & = 0
       
   488   \end{align*}
       
   489 Solution:
       
   490   \begin{align*}
       
   491     x & = 1 \\
       
   492     y & = -2 \\
       
   493     z & = -2
       
   494   \end{align*}
       
   495 \end{frame}
       
   496 
       
   497 \begin{frame}[fragile]
       
   498 \frametitle{Solving using Matrices}
       
   499 Let us now look at how to solve this using \kwrd{matrices}
       
   500   \begin{lstlisting}
       
   501     In []: A = array([[3,2,-1],
       
   502                       [2,-2,4],                   
       
   503                       [-1, 0.5, -1]])
       
   504     In []: b = array([[1], [-2], [0]])
       
   505     In []: x = solve(A, b)
       
   506     In []: Ax = dot(A,x)
       
   507   \end{lstlisting}
       
   508 \end{frame}
       
   509 
       
   510 \begin{frame}[fragile]
       
   511 \frametitle{Solution:}
       
   512 \begin{lstlisting}
       
   513 In []: x
       
   514 Out[]: 
       
   515 array([[ 1.],
       
   516        [-2.],
       
   517        [-2.]])
       
   518 \end{lstlisting}
       
   519 \end{frame}
       
   520 
       
   521 \begin{frame}[fragile]
       
   522 \frametitle{Let's check!}
       
   523 \begin{lstlisting}
       
   524 In []: Ax
       
   525 Out[]: 
       
   526 array([[  1.00000000e+00],
       
   527        [ -2.00000000e+00],
       
   528        [  2.22044605e-16]])
       
   529 \end{lstlisting}
       
   530 \begin{block}{}
       
   531 The last term in the matrix is actually \alert{0}!\\
       
   532 We can use \kwrd{allclose()} to check.
       
   533 \end{block}
       
   534 \begin{lstlisting}
       
   535 In []: allclose(Ax, b)
       
   536 Out[]: True
       
   537 \end{lstlisting}
       
   538 \inctime{15}
       
   539 \end{frame}
       
   540 
       
   541 \subsection{Exercises}
       
   542 
       
   543 \begin{frame}[fragile]
       
   544 \frametitle{Problem 1}
       
   545 Given the matrix:\\
       
   546 \begin{center}
       
   547 $\begin{bmatrix}
       
   548 -2 & 2 & 3\\
       
   549  2 & 1 & 6\\
       
   550 -1 &-2 & 0\\
       
   551 \end{bmatrix}$
       
   552 \end{center}
       
   553 Find:
       
   554 \begin{itemize}
       
   555   \item[i] Transpose
       
   556   \item[ii]Inverse
       
   557   \item[iii]Determinant
       
   558   \item[iv] Eigenvalues and Eigen vectors
       
   559   \item[v] Singular Value decomposition
       
   560 \end{itemize}
       
   561 \end{frame}
       
   562 
       
   563 \begin{frame}[fragile]
       
   564 \frametitle{Problem 2}
       
   565 Given 
       
   566 \begin{center}
       
   567 A = 
       
   568 $\begin{bmatrix}
       
   569 -3 & 1 & 5 \\
       
   570 1 & 0 & -2 \\
       
   571 5 & -2 & 4 \\
       
   572 \end{bmatrix}$
       
   573 , B = 
       
   574 $\begin{bmatrix}
       
   575 0 & 9 & -12 \\
       
   576 -9 & 0 & 20 \\
       
   577 12 & -20 & 0 \\
       
   578 \end{bmatrix}$
       
   579 \end{center}
       
   580 Find:
       
   581 \begin{itemize}
       
   582   \item[i] Sum of A and B
       
   583   \item[ii]Elementwise Product of A and B
       
   584   \item[iii] Matrix product of A and B
       
   585 \end{itemize}
       
   586 \end{frame}
       
   587 
       
   588 \begin{frame}[fragile]
       
   589 \frametitle{Solution}
       
   590 Sum: 
       
   591 $\begin{bmatrix}
       
   592 -3 & 10 & 7 \\
       
   593 -8 & 0 & 18 \\
       
   594 17 & -22 & 4 \\
       
   595 \end{bmatrix}$
       
   596 ,\\ Elementwise Product:
       
   597 $\begin{bmatrix}
       
   598 0 & 9 & -60 \\
       
   599 -9 & 0 & -40 \\
       
   600 60 & 40 & 0 \\
       
   601 \end{bmatrix}$
       
   602 ,\\ Matrix product:
       
   603 $\begin{bmatrix}
       
   604 51 & -127 & 56 \\
       
   605 -24 & 49 & -12 \\
       
   606 66 & -35 & -100 \\
       
   607 \end{bmatrix}$
       
   608 \end{frame}
       
   609 
       
   610 \begin{frame}[fragile]
       
   611 \frametitle{Problem 3}
       
   612 Solve the set of equations:
       
   613 \begin{align*}
       
   614   x + y + 2z -w & = 3\\
       
   615   2x + 5y - z - 9w & = -3\\
       
   616   2x + y -z + 3w & = -11 \\
       
   617   x - 3y + 2z + 7w & = -5\\
       
   618 \end{align*}
       
   619 \inctime{10}
       
   620 \end{frame}
       
   621 
       
   622 \begin{frame}[fragile]
       
   623 \frametitle{Solution}
       
   624 Use \kwrd{solve()}
       
   625 \begin{align*}
       
   626   x & = -5\\
       
   627   y & = 2\\
       
   628   z & = 3\\
       
   629   w & = 0\\
       
   630 \end{align*}
       
   631 \end{frame}
   477 \end{frame}
   632 
   478 
   633 \section{Summary}
   479 \section{Summary}
   634 \begin{frame}
   480 \begin{frame}
   635   \frametitle{What did we learn??}
   481   \frametitle{What did we learn??}