master
parent
95e84afc99
commit
4ecea18b51
@ -0,0 +1,24 @@
|
||||
import matplotlib.pyplot as plt
|
||||
from math import cos, sin, tau
|
||||
|
||||
points = 10
|
||||
frequence = tau / points
|
||||
|
||||
rosace = True
|
||||
|
||||
plt.figure()
|
||||
X=[cos(n * frequence) for n in range(points + 1)]
|
||||
Y=[sin(n * frequence) for n in range(points + 1)]
|
||||
|
||||
if rosace:
|
||||
for i in range(points):
|
||||
o = frequence
|
||||
n = ((points // 2) - 1)
|
||||
X.append(cos(n * frequence))
|
||||
Y.append(sin(n * frequence))
|
||||
|
||||
|
||||
plt.plot(X,Y,color='blue')
|
||||
plt.axis('equal')
|
||||
plt.title('Cercle')
|
||||
plt.show()
|
@ -0,0 +1,17 @@
|
||||
import matplotlib.pyplot as plt
|
||||
from matplotlib import collections as mc
|
||||
|
||||
plt.figure()
|
||||
|
||||
lignes = [[(-1, 0.5), (0, 0)], [(0, -1), (0, 1)], [(0, 0), (1, 0)], [(-1, -2), (0, -1)], [(0, -1), (1, -2)]]
|
||||
lc = mc.LineCollection(lignes, color='red', linewidths=1)
|
||||
fig, ax = plt.subplots()
|
||||
for a, b in lignes:
|
||||
ax.scatter(a[0], a[1], 100, color='red')
|
||||
ax.scatter(b[0], b[1], 100, color='red')
|
||||
ax.add_collection(lc)
|
||||
plt.axis('equal')
|
||||
plt.title('Bonhomme')
|
||||
plt.grid()
|
||||
plt.show()
|
||||
|
@ -0,0 +1,14 @@
|
||||
import matplotlib.pyplot as plt
|
||||
|
||||
frequence = 14
|
||||
hauteur = 0.2
|
||||
|
||||
n = frequence * 2 + 1
|
||||
|
||||
plt.figure()
|
||||
X=[i/frequence for i in range(n)]
|
||||
Y=[hauteur if (i % 2) == 1 else 0 for i in range(n)]
|
||||
plt.plot(X,Y,color='blue')
|
||||
plt.axis('equal')
|
||||
plt.title('Zigzag')
|
||||
plt.show()
|
Binary file not shown.
@ -0,0 +1,51 @@
|
||||
import matplotlib.pyplot as plt
|
||||
import numpy as np
|
||||
import math
|
||||
|
||||
# Tous les passages indiqués "TODO()" sont à remplacer par vos soins
|
||||
def TODO():
|
||||
print("à vous!")
|
||||
exit()
|
||||
|
||||
|
||||
#################################################################################################
|
||||
### EXERCICE 1 : premier exemple de graphe
|
||||
#################################################################################################
|
||||
|
||||
|
||||
print("(1) Définissez un array numpy `x` contenant 100 nombres, allant de -5 (inclus) à 5 (inclus)")
|
||||
x = np.linspace(-5,5,100)
|
||||
print(x)
|
||||
# VOCABULAIRE: On dit que `x` constitue une DISCRÉTISATION de l'intervalle [-5,5] en 100 nombres.
|
||||
|
||||
# -------------- Supprimez cette ligne pour passer à la suite ------------------
|
||||
|
||||
print("(2) Construisez un array numpy `y`, de la même taille que `x`, contenant l'exponentielle de chaque valeur contenue dans `x`")
|
||||
y = np.exp(x)
|
||||
print(y)
|
||||
# (indice : utilisez les fonctions prédéfinies de Numpy.)
|
||||
|
||||
# -------------- Supprimez cette ligne pour passer à la suite ------------------
|
||||
|
||||
print("(3) Affichez le graphe représentant `x` en abscisses et `y` en ordonnées.")
|
||||
plt.plot(x,y)
|
||||
|
||||
|
||||
# -------------- Supprimez cette ligne pour passer à la suite ------------------
|
||||
|
||||
print("(4) Rajoutez une grille de coordonnées.")
|
||||
plt.grid()
|
||||
|
||||
# -------------- Supprimez cette ligne pour passer à la suite ------------------
|
||||
|
||||
print("(5) Rajoutez un label \"x\" sur l'axe des abscisses, et \"exp(x)\" sur l'axe des ordonnées")
|
||||
plt.xlabel("x")
|
||||
plt.xlabel("exp(x)")
|
||||
plt.show()
|
||||
|
||||
# (indice : cherchez les méthodes de matplotlib permettant de rajouter des labels sur les axes)
|
||||
|
||||
#################################################################################################
|
||||
# Félicitations, vous venez de construire votre premier graphe de fonction sous Matplotlib !
|
||||
|
||||
|
@ -0,0 +1,62 @@
|
||||
import matplotlib.pyplot as plt
|
||||
import numpy as np
|
||||
import math
|
||||
|
||||
# Tous les passages indiqués "TODO()" sont à remplacer par vos soins
|
||||
def TODO():
|
||||
print("à vous!")
|
||||
exit()
|
||||
|
||||
|
||||
#################################################################################################
|
||||
### EXERCICE 2 : rentabilité d'un fabricant de processeurs
|
||||
#################################################################################################
|
||||
|
||||
print("(1) Définissez un array numpy `N` contenant les entiers de 1 à 5000")
|
||||
N = np.arange(1,5001)
|
||||
# N = np.linspace(1,5000,1)
|
||||
print(N)
|
||||
|
||||
# -------------- Supprimez cette ligne pour passer à la suite ------------------
|
||||
|
||||
print("(2) Construisez un array numpy `PN`, de la même taille que `N`, donnant le coût de production en fonction du nombre d'unités fabriquées")
|
||||
|
||||
PN = 2000 + 60 * (N)**(2/3)
|
||||
print(PN)
|
||||
|
||||
# -------------- Supprimez cette ligne pour passer à la suite ------------------
|
||||
|
||||
print("(3) Construisez un array numpy `AN`, de la même taille que `N`, donnant le chiffre d'affaires, en fonction du nombre d'unités fabriquées (en supposant que toutes les unités fabriquées sont vendues)")
|
||||
AN = N * 5
|
||||
print(AN)
|
||||
|
||||
# -------------- Supprimez cette ligne pour passer à la suite ------------------
|
||||
|
||||
print("(4) Représentez la courbe P(N) en bleu, et la courbe A(N), en rouge, dans la même figure")
|
||||
plt.figure()
|
||||
plt.plot(N, PN, color='blue', label='coûts de production')
|
||||
plt.plot(N, AN, color='red', label='chiffre d\'affaires')
|
||||
plt.legend() # (utilisera le label associé à chaque courbe au niveau des commandes `plot`)
|
||||
|
||||
|
||||
# -------------- Supprimez cette ligne pour passer à la suite ------------------
|
||||
|
||||
print("(5) Rajoutez\n",
|
||||
"- une grille de coordonnées,\n",
|
||||
"- des labels *au nom approprié* sur l'axe des abscisses et l'axe des ordonnées.")
|
||||
plt.grid()
|
||||
plt.xlabel('coûts de production')
|
||||
plt.ylabel('chiffre d\'affaires')
|
||||
plt.show()
|
||||
|
||||
# -------------- Supprimez cette ligne pour passer à la suite ------------------
|
||||
z = 0
|
||||
|
||||
for i in range(len(N)):
|
||||
if(PN[i]>AN[i]):
|
||||
z = N[i]
|
||||
|
||||
print("(6) Estimez le seuil de rentabilité pour le fabricant, à une unité près:")
|
||||
print("Le seuil de rentabilité est approximativement de", z,"unités journalières")
|
||||
|
||||
|
@ -0,0 +1,23 @@
|
||||
import matplotlib.pyplot as plt
|
||||
import numpy as np
|
||||
from typing import Tuple
|
||||
|
||||
T = np.linspace(-4, 4, 200)
|
||||
|
||||
a, b, c = (2, -1, 2)
|
||||
d, e, f = (-3, -1, -1)
|
||||
|
||||
def parabole(T: np.array) -> Tuple[np.array, np.array]:
|
||||
XT = a + b * T + c * T * T
|
||||
YT = d + e * T + f * T * T
|
||||
return XT, YT
|
||||
|
||||
plt.figure()
|
||||
plt.plot(*parabole(T))
|
||||
plt.grid()
|
||||
|
||||
T = np.arange(-4, 5)
|
||||
plt.scatter(*parabole(T))
|
||||
|
||||
plt.show()
|
||||
|
@ -0,0 +1,34 @@
|
||||
import matplotlib.pyplot as plt
|
||||
import numpy as np
|
||||
from typing import Tuple
|
||||
|
||||
markers = np.arange(-3, 4)
|
||||
def droite(T: np.array, a: int, c: int, b: int, d: int) -> Tuple[Tuple[np.array, np.array], Tuple[np.array, np.array]]:
|
||||
marques = a + b * markers, c + d * markers
|
||||
points = a + b * T, c + d * T
|
||||
return points, marques
|
||||
|
||||
T = np.linspace(-3, 3, 200)
|
||||
|
||||
plt.figure()
|
||||
|
||||
#a = droite(T, 3, 1, 5, 3)
|
||||
#plt.plot(*a[0], color='blue')
|
||||
#plt.scatter(*a[1])
|
||||
a = droite(T, -3, -1, 5, 3)
|
||||
plt.plot(*a[0], color='blue')
|
||||
a = droite(T, -5, 6, 3, -4)
|
||||
plt.plot(*a[0], color='green')
|
||||
a = droite(T, 0, 2, 2, -1)
|
||||
plt.plot(*a[0], color='red')
|
||||
|
||||
plt.grid()
|
||||
|
||||
plt.xlim([-5, 5])
|
||||
plt.ylim([-5, 5])
|
||||
ax = plt.gca()
|
||||
ax.set_xticks(range(-5, 6))
|
||||
ax.set_yticks(range(-5, 6))
|
||||
|
||||
plt.show()
|
||||
|
@ -0,0 +1,31 @@
|
||||
import matplotlib.pyplot as plt
|
||||
import numpy as np
|
||||
from typing import Tuple
|
||||
|
||||
tau = np.pi * 2
|
||||
T = np.linspace(0, tau, 16)
|
||||
|
||||
def lissajous(n: int, m: int) -> Tuple[np.array, np.array]:
|
||||
C = np.cos(n * T)
|
||||
S = np.sin(m * T)
|
||||
return C, S
|
||||
|
||||
def lemniscate_bernouilli() -> Tuple[np.array, np.array]:
|
||||
X = np.sin(T) / (1 + np.cos(T) * np.cos(T))
|
||||
Y = np.sin(T) * np.cos(T) / (1 + np.cos(T) * np.cos(T))
|
||||
return X, Y
|
||||
|
||||
def cardioide() -> Tuple[np.array, np.array]:
|
||||
X = np.cos(T) * (1 + np.cos(T))
|
||||
Y = np.sin(T) * (1 + np.cos(T))
|
||||
return X, Y
|
||||
|
||||
plt.plot(*lissajous(5, 4), label='courbe de Lissajous') # équivalent à plt.plot(*lissajous(10, 8))
|
||||
#plt.plot(*lissajous(7, 3))
|
||||
#plt.plot(*lissajous(1, 1))
|
||||
plt.plot(*lemniscate_bernouilli(), label='lemniscate de Bernoulli')
|
||||
plt.plot(*cardioide(), label='cardioïde')
|
||||
plt.grid()
|
||||
plt.legend()
|
||||
plt.show()
|
||||
|
Loading…
Reference in new issue