Skip to content

Commit 1c46b0f

Browse files
Create Trigonometric_Identity_Animation.py
1 parent 9d4d09e commit 1c46b0f

File tree

1 file changed

+54
-0
lines changed

1 file changed

+54
-0
lines changed
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
import sympy as sp
2+
import numpy as np
3+
import matplotlib.pyplot as plt
4+
from mpl_toolkits.mplot3d import Axes3D
5+
6+
# Define symbols
7+
alpha, beta = sp.symbols('alpha beta')
8+
9+
# Define the identity
10+
lhs = sp.cos(alpha + beta)
11+
rhs = sp.cos(alpha) * sp.cos(beta) - sp.sin(alpha) * sp.sin(beta)
12+
13+
# Check if the identity holds true
14+
identity_holds = sp.simplify(lhs - rhs) == 0
15+
print("Does the identity hold true?", identity_holds)
16+
17+
# Create 3D plot for visualization
18+
alpha_vals = np.linspace(0, 2 * np.pi, 100)
19+
beta_vals = np.linspace(0, 2 * np.pi, 100)
20+
alpha_vals, beta_vals = np.meshgrid(alpha_vals, beta_vals)
21+
22+
lhs_vals = np.cos(alpha_vals + beta_vals)
23+
rhs_vals = np.cos(alpha_vals) * np.cos(beta_vals) - np.sin(alpha_vals) * np.sin(beta_vals)
24+
25+
fig = plt.figure()
26+
ax = fig.add_subplot(111, projection='3d')
27+
ax.plot_surface(alpha_vals, beta_vals, lhs_vals, cmap='coolwarm', label='lhs')
28+
ax.plot_surface(alpha_vals, beta_vals, rhs_vals, cmap='viridis', label='rhs')
29+
30+
ax.set_xlabel('Alpha')
31+
ax.set_ylabel('Beta')
32+
ax.set_zlabel('Value')
33+
ax.set_title('Trigonometric Identity: cos(α±β) = cosαcosβ ∓ sinαsinβ')
34+
35+
from matplotlib.animation import FuncAnimation
36+
37+
fig = plt.figure()
38+
ax = fig.add_subplot(111, projection='3d')
39+
40+
def update(frame):
41+
ax.cla() # Clear the previous frame
42+
new_alpha = alpha_vals + frame * 0.1
43+
new_lhs = np.cos(new_alpha + beta_vals)
44+
new_rhs = np.cos(new_alpha) * np.cos(beta_vals) - np.sin(new_alpha) * np.sin(beta_vals)
45+
ax.plot_surface(alpha_vals, beta_vals, new_lhs, cmap='coolwarm', label='lhs')
46+
ax.plot_surface(alpha_vals, beta_vals, new_rhs, cmap='viridis', label='rhs')
47+
ax.set_xlabel('Alpha')
48+
ax.set_ylabel('Beta')
49+
ax.set_zlabel('Value')
50+
ax.set_title('Trigonometric Identity Animation')
51+
ax.legend()
52+
53+
ani = FuncAnimation(fig, update, frames=50, interval=100)
54+
plt.show()

0 commit comments

Comments
 (0)