# -*- coding: utf-8 -*- # -*- coding: latin-1 -*- #definition d'une fonction def f(x): return 2 * x + 1 #utilisation de la fonction print(f(4)) print( f(1) , f(2) , f(3) , f(4) , f(5) , f(6)) print( type(f)) # definition d'une seconde fonction def hi(name): print("hello " + name + " from Python!!!") #exemple d'utilisation hi("Mark") #definition d'une trosieme fonction from random import choice def lettre(): return choice('abcdefghijklmnopqrstuvwxyz') #exemple d'utilisation lettre() #definition d'une liste de fonctions mes_fonctions = [f,hi,lettre] #utilisation mes_fonctions[1]("Dominique") mes_fonctions[2]() from IPython.display import Image Image(filename='kick.jpg') from IPython.display import Image Image(filename='masse-ressort-amortisseur.jpg') nb_repetitions = 3 i = 1 while i <= nb_repetitions : print "Et "+str(i)+"!" i = i+1 print "Zéro!" nb_repetitions = 3 i = 1 while i <= nb_repetitions : print "Et "+str(i)+"!" i = i+1 if i==3: break print "Zéro!" % matplotlib inline from math import * import numpy as np import matplotlib.pyplot as plt t = np.linspace(0,10,400) # Création d'une array numpy : Temps = Abscisses def U(t,Q): return np.exp(-2/Q*t)*np.cos(2*pi*t) # Fonction U dépendant d'un paramètre Q # Plot1 avec Q = 2 et édition du label correspondant Q=2.0 plt.plot(t,U(t,Q),label="Q=" + str(Q)) # Plot2 avec Q = 10 et édition du label correspondant Q=10.0 plt.plot(t,U(t,Q),label="Q=" + str(Q)) plt.legend(loc='upper right') # Appel de la légende plt.show() import numpy as np val=np.linspace(0,7,500) val_max = np.amax(val) print(val_max) from IPython.display import Image Image(filename='bielle.jpg') import numpy as np #définition d'une matrice avec numpy tableau = np.array ([[0 ,1 ,2] ,[1,2,3], [4,6,12], [44 ,55 ,56]]) print(tableau) n=tableau[3,0] # copier un element du tableau , tableau[num. ligne][num. colonne] print(n) c=tableau[:,0] # copier une colonne du tableau print(c) d=tableau[:2,:2] # copier une colonne du tableau print(d) tableau = tableau + 2 #ajouter 2 aux éléments du tableau print(tableau) tableau2 = np.zeros((4,3)) #définition d'une matrice composée de zéros print(tableau2) import numpy as np my_mat = np.random.random((50, 80)) #création d'une matrice aléatoire de 80x50 elements plt.matshow(my_mat) # représentation graphique plt.xticks(range(0,80,10)) # définition des marqueurs en x plt.yticks(range(0,50,10)) # définition des marqueurs en y plt.colorbar() plt.show() from IPython.core.display import HTML def css_styling(): styles = open('custom.css', 'r').read() return HTML(styles) css_styling()