diff options
-rw-r--r-- | day1/session4.tex | 146 |
1 files changed, 110 insertions, 36 deletions
diff --git a/day1/session4.tex b/day1/session4.tex index c126cbf..576c759 100644 --- a/day1/session4.tex +++ b/day1/session4.tex @@ -74,7 +74,7 @@ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % Title page -\title[Matrices \& Equations]{Python for Science and Engg: Matrices \& Solution of equations} +\title[Matrices \& Equations]{Python for Science and Engg: Matrices, Least Square Fit, \& Solution of equations} \author[FOSSEE] {FOSSEE} @@ -128,11 +128,9 @@ \begin{frame} \frametitle{Matrices: Introduction} -Let us now look at matrices in detail.\\ \alert{All matrix operations are done using \kwrd{arrays}} \end{frame} -\subsection{Initializing} \begin{frame}[fragile] \frametitle{Matrices: Initializing} \begin{lstlisting} @@ -150,28 +148,103 @@ array([[ 1, 1, 2, -1], \end{frame} \begin{frame}[fragile] - \frametitle{Accessing elements of matrices} -\begin{small} + \frametitle{Accessing elements} \begin{lstlisting} In []: C = array([[1,1,2], [2,4,1], [-1,3,7]]) + +In []: C[1][2] +Out[]: 1 + In []: C[1,2] Out[]: 1 In []: C[1] Out[]: array([2, 4, 1]) + \end{lstlisting} +\end{frame} +\begin{frame}[fragile] + \frametitle{Changing elements} + \begin{small} + \begin{lstlisting} In []: C[1,1] = -2 In []: C Out[]: array([[ 1, 1, 2], [ 2, -2, 1], [-1, 3, 7]]) + +In []: C[1] = [0,0,0] +In []: C +Out[]: +array([[ 1, 1, 2], + [ 0, 0, 0], + [-1, 3, 7]]) + \end{lstlisting} + \end{small} +How to change one \alert{column}? +\end{frame} + +\begin{frame}[fragile] + \frametitle{Slicing} +\begin{small} + \begin{lstlisting} +In []: C[:,1] +Out[]: array([1, 0, 3]) + +In []: C[1,:] +Out[]: array([0, 0, 0]) + +In []: C[0:2,:] +Out[]: +array([[1, 1, 2], + [0, 0, 0]]) + +In []: C[1:3,:] +Out[]: +array([[ 0, 0, 0], + [-1, 3, 7]]) + \end{lstlisting} +\end{small} +\end{frame} + +\begin{frame}[fragile] + \frametitle{Slicing \ldots} +\begin{small} + \begin{lstlisting} +In []: C[:2,:] +Out[]: +array([[1, 1, 2], + [0, 0, 0]]) + +In []: C[1:,:] +Out[]: +array([[ 0, 0, 0], + [-1, 3, 7]]) + +In []: C[1:,:2] +Out[]: +array([[ 0, 0], + [-1, 3]]) \end{lstlisting} + \end{small} \end{frame} +\begin{frame}[fragile] + \frametitle{Striding} + \begin{lstlisting} + \end{lstlisting} +\end{frame} + +\begin{frame}[fragile] + \frametitle{Slicing \& Striding Exercises} + \begin{lstlisting} + \end{lstlisting} +\end{frame} + \subsection{Basic Operations} \begin{frame}[fragile] @@ -279,47 +352,47 @@ Out[]: array([-1., 8., -1.]) \end{small} \end{frame} -\begin{frame}[fragile] -\frametitle{Computing Norms} -\begin{lstlisting} -In []: norm(E) -Out[]: 8.1240384046359608 -\end{lstlisting} -\end{frame} - -\begin{frame}[fragile] - \frametitle{Singular Value Decomposition} - \begin{small} - \begin{lstlisting} -In []: svd(E) -Out[]: -(array( -[[ -6.66666667e-01, -1.23702565e-16, 7.45355992e-01], - [ -3.33333333e-01, -8.94427191e-01, -2.98142397e-01], - [ -6.66666667e-01, 4.47213595e-01, -5.96284794e-01]]), - array([ 8., 1., 1.]), - array([[-0.66666667, -0.33333333, -0.66666667], - [-0. , 0.89442719, -0.4472136 ], - [-0.74535599, 0.2981424 , 0.59628479]])) - \end{lstlisting} - \end{small} -\inctime{15} -\end{frame} +%% \begin{frame}[fragile] +%% \frametitle{Computing Norms} +%% \begin{lstlisting} +%% In []: norm(E) +%% Out[]: 8.1240384046359608 +%% \end{lstlisting} +%% \end{frame} + +%% \begin{frame}[fragile] +%% \frametitle{Singular Value Decomposition} +%% \begin{small} +%% \begin{lstlisting} +%% In []: svd(E) +%% Out[]: +%% (array( +%% [[ -6.66666667e-01, -1.23702565e-16, 7.45355992e-01], +%% [ -3.33333333e-01, -8.94427191e-01, -2.98142397e-01], +%% [ -6.66666667e-01, 4.47213595e-01, -5.96284794e-01]]), +%% array([ 8., 1., 1.]), +%% array([[-0.66666667, -0.33333333, -0.66666667], +%% [-0. , 0.89442719, -0.4472136 ], +%% [-0.74535599, 0.2981424 , 0.59628479]])) +%% \end{lstlisting} +%% \end{small} +%% \inctime{15} +%% \end{frame} \section{Least Squares Fit} \begin{frame}[fragile] -\frametitle{Least Squares Fit} +\frametitle{$L$ vs. $T^2$} \vspace{-0.15in} \begin{figure} -\includegraphics[width=4in]{data/L-Tsq-Line.png} +\includegraphics[width=4in]{data/L-Tsq-points.png} \end{figure} \end{frame} \begin{frame}[fragile] -\frametitle{Least Squares Fit} +\frametitle{$L$ vs. $T^2$} \vspace{-0.15in} \begin{figure} -\includegraphics[width=4in]{data/L-Tsq-points.png} +\includegraphics[width=4in]{data/L-Tsq-Line.png} \end{figure} \end{frame} @@ -383,7 +456,8 @@ In []: A = A.T \item Along with a lot of things, it returns the least squares solution \end{itemize} \begin{lstlisting} -In []: coef, res, r, s = lstsq(A,TSq) +In []: result = lstsq(A,TSq) +In []: coef = result[0] \end{lstlisting} \end{frame} |