day2/session1.tex
changeset 96 a749db24e73b
parent 95 691608044ae7
child 97 555237dbce44
equal deleted inserted replaced
95:691608044ae7 96:a749db24e73b
   235 \end{frame}
   235 \end{frame}
   236 
   236 
   237 \begin{frame}[fragile]
   237 \begin{frame}[fragile]
   238   \frametitle{Array math cont.}
   238   \frametitle{Array math cont.}
   239   \begin{itemize}
   239   \begin{itemize}
   240   \item Logical operations: \typ{np.equal (==)}, \typ{np.not\_equal (!=)},
   240   \item Logical operations: \typ{==}, \typ{!=},
   241     \typ{np.less (<)}, \typ{np.greater (>)} etc.
   241     \typ{<}, \typ{>} etc.
   242   \item Trig and other functions: \typ{np.sin(x),}
   242   \item Trig and other functions: \typ{np.sin(x),}
   243         \typ{np.arcsin(x), np.sinh(x),}
   243         \typ{np.arcsin(x), np.sinh(x),}
   244       \typ{np.exp(x), np.sqrt(x)} etc.
   244       \typ{np.exp(x), np.sqrt(x)} etc.
   245   \end{itemize}
   245   \end{itemize}
   246 \begin{lstlisting}
   246 \begin{lstlisting}
   247 >>> np.greater(a,4)
   247 >>> a<4, a!=3
   248 >>> np.sqrt(a)
   248 >>> np.sqrt(a)
   249 \end{lstlisting}
   249 \end{lstlisting}
   250 \inctime{10}
   250 \inctime{10}
   251 \end{frame}
   251 \end{frame}
   252 
   252 
   258     \item \typ{np.array(object,dtype=None,...)}
   258     \item \typ{np.array(object,dtype=None,...)}
   259     \begin{lstlisting}
   259     \begin{lstlisting}
   260 >>> np.array([2,3,4])  
   260 >>> np.array([2,3,4])  
   261 array([2, 3, 4])
   261 array([2, 3, 4])
   262     \end{lstlisting}
   262     \end{lstlisting}
   263     \item \typ{np.linspace(start,stop,...)}
   263     \item \typ{np.linspace(start,stop,num)}
   264     \begin{lstlisting}
   264     \begin{lstlisting}
   265 >>> np.linspace(0, 2, 4)   
   265 >>> np.linspace(0, 2, 4)   
   266 array([0.,0.6666667,1.3333333,2.])
   266 array([0.,0.6666667,1.3333333,2.])
   267     \end{lstlisting}
   267     \end{lstlisting}
   268     \item Also try \typ{np.arange}
   268     \item Also try \typ{np.arange}
   272 \begin{frame}[fragile]
   272 \begin{frame}[fragile]
   273   \frametitle{Array creation functions cont.}
   273   \frametitle{Array creation functions cont.}
   274   \begin{itemize}  
   274   \begin{itemize}  
   275   \item \typ{np.ones(shape, dtype=None, ...)}  
   275   \item \typ{np.ones(shape, dtype=None, ...)}  
   276   \begin{lstlisting} 
   276   \begin{lstlisting} 
   277 >>>np.ones([2,2])
   277 >>>np.ones((2,2))
   278 array([[ 1.,  1.],
   278 array([[ 1.,  1.],
   279      [ 1.,  1.]])
   279      [ 1.,  1.]])
   280   \end{lstlisting}  
   280   \end{lstlisting}  
   281   \item \typ{np.identity(n)} 
   281   \item \typ{np.identity(n)} 
   282   \item \typ{np.ones\_like(x)}  
   282   \item \typ{np.ones\_like(x)}  
   374 >>> plot(x, sin(x), 'ro')
   374 >>> plot(x, sin(x), 'ro')
   375 >>> xlabel(r'$\chi$', color='g')
   375 >>> xlabel(r'$\chi$', color='g')
   376 # LaTeX markup!
   376 # LaTeX markup!
   377 >>> ylabel(r'sin($\chi$)', color='r')
   377 >>> ylabel(r'sin($\chi$)', color='r')
   378 >>> title('Simple figure', fontsize=20)
   378 >>> title('Simple figure', fontsize=20)
   379 >>> savefig('/tmp/test.eps')
   379 >>> savefig('/tmp/test.png')
   380 \end{lstlisting}
   380 \end{lstlisting}
   381 \begin{itemize}
   381 \begin{itemize}
   382   \item Also: PNG, PDF, PS, EPS, SVG, PDF
   382   \item Also: PDF, PS, EPS, SVG, PDF
   383 \end{itemize}
   383 \end{itemize}
   384 \inctime{5}
   384 \inctime{5}
   385 \end{frame}
   385 \end{frame}
   386        
   386        
   387 \subsection{Plots - Lines, Labels and Legends}
   387 \subsection{Plots - Lines, Labels and Legends}
   784 \frametitle{Problem Set}
   784 \frametitle{Problem Set}
   785   \begin{columns}
   785   \begin{columns}
   786     \column{0.6\textwidth}
   786     \column{0.6\textwidth}
   787     \small{
   787     \small{
   788     \begin{enumerate}
   788     \begin{enumerate}
   789       \item Consider the iteration $x_{n+1} = f(x_n)$ where $f(x) =
   789       \item Consider the iteration $x_{n+1} = f(x_n)$ where $f(x) = kx(1-x)$.  Plot the successive iterates of this process.
   790           kx(1-x)$.  Plot the successive iterates of this process.
       
   791       \item Plot this using a cobweb plot as follows:
   790       \item Plot this using a cobweb plot as follows:
   792           \begin{enumerate}
   791           \begin{enumerate}
   793               \item Start at $(x_0, 0)$
   792               \item Start at $(x_0, 0)$
   794               \item Draw line to $(x_i, f(x_i))$; 
   793               \item Draw line to $(x_i, f(x_i))$; 
   795               \item Set $x_{i+1} = f(x_i)$
   794               \item Set $x_i = f(x_i)$
   796               \item Draw line to $(x_i, x_i)$
   795               \item Draw line to $(x_i, x_i)$
   797               \item Repeat from 2 for as long as you want 
   796               \item Repeat from 2 for as long as you want 
   798           \end{enumerate}
   797           \end{enumerate}
   799     \end{enumerate}}
   798     \end{enumerate}}
   800     \column{0.35\textwidth}
   799     \column{0.35\textwidth}