-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy path3D_Double_Angle_Trigonometric_Identities.py
More file actions
122 lines (102 loc) · 4.4 KB
/
3D_Double_Angle_Trigonometric_Identities.py
File metadata and controls
122 lines (102 loc) · 4.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
import numpy as np
import pandas as pd
import plotly.express as px
import plotly.graph_objects as go
import sympy as sp
# Double Angle Trigonometric Identities
theta = sp.symbols('theta')
sin_2theta = 2 * sp.sin(theta) * sp.cos(theta)
cos_2theta = sp.cos(theta)**2 - sp.sin(theta)**2
tan_2theta = (2 * sp.tan(theta)) / (1 - sp.tan(theta)**2)
# Create a range of theta values
theta_values = np.linspace(0, 2 * np.pi, 100)
sin_2theta_values = np.array([float(sin_2theta.evalf(subs={theta: t})) for t in theta_values])
cos_2theta_values = np.array([float(cos_2theta.evalf(subs={theta: t})) for t in theta_values])
tan_2theta_values = np.array([float(tan_2theta.evalf(subs={theta: t})) for t in theta_values])
# Create a DataFrame to display the results
data = {
'Theta': theta_values,
'sin(2θ)': sin_2theta_values,
'cos(2θ)': cos_2theta_values,
'tan(2θ)': tan_2theta_values
}
df = pd.DataFrame(data)
# Plotly Interactive Visualization
# Create interactive line plots for sin(2θ), cos(2θ), and tan(2θ)
fig = go.Figure()
fig.add_trace(go.Scatter(x=theta_values, y=sin_2theta_values, mode='lines', name='sin(2θ)'))
fig.add_trace(go.Scatter(x=theta_values, y=cos_2theta_values, mode='lines', name='cos(2θ)'))
fig.add_trace(go.Scatter(x=theta_values, y=tan_2theta_values, mode='lines', name='tan(2θ)'))
fig.update_layout(
title='Double Angle Trigonometric Identities',
xaxis_title='θ',
yaxis_title='Value',
xaxis=dict(dtick=np.pi / 2, tickmode='array', tickvals=[0, np.pi / 2, np.pi, 1.5 * np.pi, 2 * np.pi],
ticktext=['0', 'π/2', 'π', '3π/2', '2π']),
)
# Display the DataFrame
print("Double Angle Trigonometric Identities:")
print(df)
# Show the interactive plot
fig.show()
#-------------------------------------------------------------------------------------------------------------------------------------
import numpy as np
import pandas as pd
import plotly.express as px
import plotly.graph_objects as go
import sympy as sp
import matplotlib.pyplot as plt
import matplotlib.animation as animation
# Double Angle Trigonometric Identities
theta = sp.symbols('theta')
sin_2theta = 2 * sp.sin(theta) * sp.cos(theta)
cos_2theta = sp.cos(theta)**2 - sp.sin(theta)**2
tan_2theta = (2 * sp.tan(theta)) / (1 - sp.tan(theta)**2)
# Create a range of theta values
theta_values = np.linspace(0, 2 * np.pi, 100)
sin_2theta_values = np.array([float(sin_2theta.evalf(subs={theta: t})) for t in theta_values])
cos_2theta_values = np.array([float(cos_2theta.evalf(subs={theta: t})) for t in theta_values])
tan_2theta_values = np.array([float(tan_2theta.evalf(subs={theta: t})) for t in theta_values])
# Create a DataFrame to display the results
data = {
'Theta': theta_values,
'sin(2θ)': sin_2theta_values,
'cos(2θ)': cos_2theta_values,
'tan(2θ)': tan_2theta_values
}
df = pd.DataFrame(data)
# Plotly Interactive Visualization
# Create interactive line plots for sin(2θ), cos(2θ), and tan(2θ)
fig = go.Figure()
fig.add_trace(go.Scatter(x=theta_values, y=sin_2theta_values, mode='lines', name='sin(2θ)'))
fig.add_trace(go.Scatter(x=theta_values, y=cos_2theta_values, mode='lines', name='cos(2θ)'))
fig.add_trace(go.Scatter(x=theta_values, y=tan_2theta_values, mode='lines', name='tan(2θ)'))
fig.update_layout(
title='Double Angle Trigonometric Identities',
xaxis_title='θ',
yaxis_title='Value',
xaxis=dict(dtick=np.pi / 2, tickmode='array', tickvals=[0, np.pi / 2, np.pi, 1.5 * np.pi, 2 * np.pi],
ticktext=['0', 'π/2', 'π', '3π/2', '2π']),
)
# Display the DataFrame
print("Double Angle Trigonometric Identities:")
print(df)
# Show the interactive plot
fig.show()
# Mathematical Calculation: Calculate the integrals of sin(2θ) and cos(2θ)
integral_sin_2theta = sp.integrate(sin_2theta, theta)
integral_cos_2theta = sp.integrate(cos_2theta, theta)
print("\nIntegrals of sin(2θ) and cos(2θ):")
print("∫sin(2θ) dθ =", integral_sin_2theta)
print("∫cos(2θ) dθ =", integral_cos_2theta)
# Additional Visualizations: Create animated plots of sin(2θ) and cos(2θ) over time
def animate_sine_cosine(i):
plt.clf()
plt.plot(theta_values, np.sin(2 * theta_values + i / 10), label='sin(2θ)')
plt.plot(theta_values, np.cos(2 * theta_values + i / 10), label='cos(2θ)')
plt.legend()
plt.title('Sine and Cosine Waves with Changing Phase')
plt.xlabel('θ')
plt.ylabel('Value')
ani = animation.FuncAnimation(plt.gcf(), animate_sine_cosine, interval=100)
plt.show()