Commit ec0fff34 authored by Thibaut.Lunet's avatar Thibaut.Lunet

TL: maj

parent 248c5130
......@@ -34,16 +34,10 @@ nl = [['vive', 'la'], ['saucisse', 2], 'Toulouse']
# Access sublist element : nl[0] = ['vive', 'la']
# Access final element : nl[0][1] = 'la', nl[1][0] = 'saucisse'
# List definition
l1 = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
# -- equivalent (shorter) formulation
l1 = [i for i in range(10)]
# List operation
l11 = [i + 1 for i in l1]
# List comprehension
l2 = [3 * n + 1 for n in l1 if n % 2 == 0]
l1 = [i**2 for i in range(10)]
# l1 = [0, 1, 4, 9, 16, 25, 36, 49, 64, 81]
l2 = [3*n + 1 for n in range(10) if n % 2 == 0]
# l2 = [7, 13, 19, 25, 31]
# %% Slide: Dictionaries
......@@ -92,7 +86,9 @@ def add(a, b=1): # NO NEED to define the type, b has a default value
# Possibility of having a variable number of parameters and outputs
def doSomething(x, y, z, p1=1, p3='red'):
return p1*(x+y), p3+str(z) # returns a list of two elements
out1 = p1*(x+y)
out2 = p3+str(z)
return out1, out2 # returns a list of two elements
out = doSomething(1, 2, 3) # out[0] = 3, out[1] = 'red3'
# -- shorter equivalent way
......@@ -218,6 +214,14 @@ plt.title('Cosine')
plt.show()
if 1 == 2 \
or 1 == 3 \
or 's'.startswith('s') \
and 's'.startswith('s') \
and 's'.startswith('s') \
and 's'.startswith('s'):
pass
pass
# %% Slide: Sympy
......
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Mon Mar 19 09:49:39 2018
@author: lunet
"""
import numpy as np
import scipy.optimize as sco
import matplotlib.pyplot as plt
x = np.linspace(0, 1, num=200)
alphaTh = 0.6
betaTh = 0.9
def law(x, alpha=alphaTh, beta=betaTh):
return alpha*np.exp(beta*x)
nMeasure = 50
noiseAmplitude = 0.08
xMeasure = np.linspace(0, 1, num=nMeasure)
yMeasure = law(xMeasure) + np.random.randn(nMeasure)*noiseAmplitude
def minFunc(alpha, beta):
return np.linalg.norm(law(xMeasure, alpha, beta))
sco.minimize
plt.figure('Data regerssion')
plt.plot(x, law(x), '-', label='Exact data')
plt.plot(xMeasure, yMeasure, 'o', label='Noisy data')
plt.legend()
plt.show()
\ No newline at end of file
......@@ -28,7 +28,7 @@ schemeY = 'U1'
schemeZ = 'U1'
# Script actions
plotMatrix = False
plotMatrix = True
saveFig = False
# Initial velocity fields
......@@ -171,6 +171,7 @@ def computeJacobian(u, rhs):
uPerturb[i] = u[i]
return jacobian
# Compute the Jacobie matrix of each RHS function
print('Compute 1D Jacobi matrix')
A1D = computeJacobian(u01D, rhs1D)
......
......@@ -6,15 +6,18 @@
# Create a 8x8 matrix with a chessboard pattern with numbers 1 and 0.
import numpy as np
import matplotlib.pyplot as plt
def chessboard():
M = np.zeros((8,8))
for i in np.arange(0,8):
for j in np.arange(0,8):
M = np.zeros((8, 8))
for i in np.arange(0, 8):
for j in np.arange(0, 8):
M[i, j] = (i + j) % 2
return M
print(chessboard())
M = chessboard()
print(M)
plt.imshow(M, cmap='binary')
No preview for this file type
......@@ -37,31 +37,6 @@
\begin{document}
\maketitle
\begin{frame}{How to get Python (+ useful packages ...)}
We are going to use the \textbf{miniconda} installer, which is cross-platform and provides package management, together with the \textbf{spyder} IDE.
\begin{enumerate}
\item Go to \href{https://conda.io/miniconda.html}{https://conda.io/miniconda.html} \\ (or Google search : "miniconda download")
\item Depending on the operating system, download installer (Python 2.7)
\item Install Python and required packages
\begin{itemize}
\item Mac OS X or Unix:
\begin{enumerate}
\item Open a terminal
\item Run "bash Miniconda[...].sh", and yes for all ...
\item Open a new terminal, or run "source $\sim$/.bashrc"
\item Run "\textbf{conda install spyder numpy scipy matplotlib sympy}"
\end{enumerate}
\item Windows:
\begin{enumerate}
\item Double-click on the .exe file, and yes for all ...
\item Open "conda prompt" terminal (installed with miniconda)
\item Run "\textbf{conda install spyder numpy scipy matplotlib sympy}"
\end{enumerate}
\end{itemize}
\end{enumerate}
\end{frame}
\begin{frame}{What are we talking about}
\begin{block}{A little history}
......@@ -158,35 +133,6 @@
\vspace{-10pt}
\end{frame}
\begin{frame}{Hello World!}
\begin{center}
All the examples and python files are available at: \\
\href{https://gitlab.unige.ch/Thibaut.Lunet/python-math}{https://gitlab.unige.ch/Thibaut.Lunet/python-math}
\end{center}
\begin{block}{A first easy step ...}
\begin{enumerate}
\item Launch Spyder
\begin{itemize}
\item Windows : double click on an icon somewhere ...
\item Mac OS X or Unix : run "spyder" in terminal
\end{itemize}
\item Discover a wonderful environment \#woaaah
\item Go to lower right corner $\rightarrow$ IPython console
\begin{itemize}
\item write "1+1"
\item press enter ...
\end{itemize}
\item Go to text editor (middle)
\begin{itemize}
\item write "print('hello world')
\item save and run the file ...
\end{itemize}
\end{enumerate}
\end{block}
\end{frame}
%\defverbatim[colored]\pythonCode{
%\begin{pythoncode}
......@@ -317,16 +263,18 @@
\begin{itemize}
\item Data are stored in contiguous memory location
\item Operations on arrays are done in C
\item Rely on BLAS implementation for algebraic computation
\item Uses optimized C library for algebraic computation (BLAS)
\end{itemize}
\end{block}
\end{block}See also \href{https://docs.scipy.org/doc/scipy/reference/tutorial/}{Scipy tutorials} on the Internet
\begin{block}{Scipy : companion package for scientific computing}
\begin{itemize}
\item Many functions for linear algebra, optimization, interpolation, fft...
\item Many functions for linear algebra, optimization, interpolation, ...
\item Interface with C and Fortran optimized routine\\
(LAPACK, FFTW, QUADPACK, ... and many others !)
\end{itemize}
\end{block}
\vspace*{-10pt}
See also \href{https://docs.scipy.org/doc/scipy/reference/tutorial/}{Scipy tutorials} on the Internet
\end{frame}
\begin{frame}{Numpy basics I}
......@@ -362,7 +310,6 @@
\vspace*{-7pt}
... and more in
\href{https://gitlab.unige.ch/Thibaut.Lunet/python-math/tree/master/examples/scipy}{python-math/examples/scipy} directory \\
See also \href{https://docs.scipy.org/doc/scipy/reference/tutorial/}{Scipy tutorials} on the Internet
\end{frame}
......@@ -426,7 +373,62 @@
\bfseries
Thanks for watching ! \\
... we hope you enjoy at least some parts ...
\\ Now you can play with !
\end{center}
\end{frame}
\begin{frame}{How to get Python (+ useful packages ...)}
We are going to use the \textbf{miniconda} installer, which is cross-platform and provides package management, together with the \textbf{spyder} IDE.
\begin{enumerate}
\item Go to \href{https://conda.io/miniconda.html}{https://conda.io/miniconda.html} \\ (or Google search : "miniconda download")
\item Depending on the operating system, download installer (Python 2.7)
\item Install Python and required packages
\begin{itemize}
\item Mac OS X or Unix:
\begin{enumerate}
\item Open a terminal
\item Run "bash Miniconda[...].sh", and yes for all ...
\item Open a new terminal, or run "source $\sim$/.bashrc"
\item Run "\textbf{conda install spyder numpy scipy matplotlib sympy}"
\end{enumerate}
\item Windows:
\begin{enumerate}
\item Double-click on the .exe file, and yes for all ...
\item Open "conda prompt" terminal (installed with miniconda)
\item Run "\textbf{conda install spyder numpy scipy matplotlib sympy}"
\end{enumerate}
\end{itemize}
\end{enumerate}
\end{frame}
\begin{frame}{Hello World!}
\begin{center}
All the examples and python files are available at: \\
\href{https://gitlab.unige.ch/Thibaut.Lunet/python-math}{https://gitlab.unige.ch/Thibaut.Lunet/python-math}
\end{center}
\begin{block}{A first easy step ...}
\begin{enumerate}
\item Launch Spyder
\begin{itemize}
\item Windows : double click on an icon somewhere ...
\item Mac OS X or Unix : run "spyder" in terminal
\end{itemize}
\item Discover a wonderful environment \#woaaah
\item Go to lower right corner $\rightarrow$ IPython console
\begin{itemize}
\item write "1+1"
\item press enter ...
\end{itemize}
\item Go to text editor (middle)
\begin{itemize}
\item write "print('hello world')
\item save and run the file ...
\end{itemize}
\end{enumerate}
\end{block}
\end{frame}
\end{document}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment