41 lines
1.1 KiB
Python
41 lines
1.1 KiB
Python
|
#!/usr/bin/env python3
|
||
|
|
||
|
"""
|
||
|
1) créer 2 vecteurs et calculer le produit scalaire entre les 2 vecteurs
|
||
|
comparer avec dot
|
||
|
|
||
|
2) calculer l'angle entre 2 vecteurs
|
||
|
|
||
|
3) afficher les vecteurs
|
||
|
|
||
|
Pour l'affichage → utilisation de matplotlib
|
||
|
exemple
|
||
|
plt.plot([0, 1, 2], [4, 8, 16], "r+")
|
||
|
plt.show()
|
||
|
"""
|
||
|
import numpy as np
|
||
|
|
||
|
|
||
|
def truc1():
|
||
|
a = np.random.random(2)
|
||
|
b = np.random.random(2)
|
||
|
print(a, b, a.shape)
|
||
|
print(f"{(a*b).sum()=} \n{np.dot(a, b)=}")
|
||
|
|
||
|
# truc1()
|
||
|
import matplotlib.pyplot as plt
|
||
|
|
||
|
def truc2():
|
||
|
a = np.array([0, 1]) #np.random.random(2)
|
||
|
b = np.array([1, 1]) #np.random.random(2)
|
||
|
alpha = np.math.degrees(np.math.acos(np.dot(a, b) / (np.linalg.norm(a) * np.linalg.norm(b))))
|
||
|
print(f"{a=} {b=} {alpha=}")
|
||
|
n = 500
|
||
|
x = a.dot(b) / (np.linalg.norm(a) * np.linalg.norm(b))
|
||
|
new_a = np.math.pi / 2 - sum(np.math.factorial(2*n) / (2**n * np.math.factorial(n))**2 * (x**(2*n+1)) / (2*n+1) for _ in range(n))
|
||
|
print(np.math.degrees(new_a))
|
||
|
# print(np.linalg.norm(a) == (a**2).sum() ** .5)
|
||
|
plt.plot(a/np.linalg.norm(a), b/np.linalg.norm(b), "r+")
|
||
|
plt.show()
|
||
|
|
||
|
truc2()
|