day2/session2.tex
changeset 84 338b85a9c864
parent 82 e352b67ab357
child 96 a749db24e73b
equal deleted inserted replaced
83:be8c9a71135f 84:338b85a9c864
   336 \begin{frame}[fragile]
   336 \begin{frame}[fragile]
   337   \frametitle{Integrate \ldots}
   337   \frametitle{Integrate \ldots}
   338   Numerically solve ODEs\\
   338   Numerically solve ODEs\\
   339   \begin{align*}
   339   \begin{align*}
   340   \frac{dx}{dt}&=-e^{-t}x^2\\ 
   340   \frac{dx}{dt}&=-e^{-t}x^2\\ 
   341            x(0)&=2    
   341            x&=2 \quad at \ t=0
   342   \end{align*}
   342   \end{align*}
   343   \begin{lstlisting}
   343   \begin{lstlisting}
   344 >>> def dx_dt(x,t):
   344 >>> def dx_dt(x,t):
   345         return -np.exp(-t)*x**2
   345         return -np.exp(-t)*x**2
   346 
   346 >>> t=np.linspace(0,2,100)
   347 >>> x=integrate.odeint(dx_dt, 2, t)
   347 >>> x=integrate.odeint(dx_dt, 2, t)
   348 >>> plt.plot(x,t)
   348 >>> plt.plot(x,t)
   349   \end{lstlisting}
   349   \end{lstlisting}
   350 \inctime{10}
   350 \inctime{10}
   351 \end{frame}
   351 \end{frame}
   370 
   370 
   371 \begin{frame}[fragile]
   371 \begin{frame}[fragile]
   372   \frametitle{Interpolation - Splines}
   372   \frametitle{Interpolation - Splines}
   373   Plot the Cubic Spline of $sin(x)$
   373   Plot the Cubic Spline of $sin(x)$
   374   \begin{lstlisting}
   374   \begin{lstlisting}
   375 >>> x = np.arange(0,2*np.pi,np.pi/4)
       
   376 >>> y = np.sin(x)
       
   377 >>> tck = interpolate.splrep(x,y)
   375 >>> tck = interpolate.splrep(x,y)
   378 >>> X = np.arange(0,2*np.pi,np.pi/50)
   376 >>> X = np.arange(0,2*np.pi,np.pi/50)
   379 >>> Y = interpolate.splev(X,tck,der=0)
   377 >>> Y = interpolate.splev(X,tck,der=0)
   380 >>> plt.plot(x,y,'o',x,y,X,Y)
   378 >>> plt.plot(x,y,'o',x,y,X,Y)
   381 >>> plt.show()
   379 >>> plt.show()