三角函數與柯西不等式 === ## 正弦與餘弦 - $\sin\theta$ 與 $\cos\theta$ 的定義: - 考慮**單位圓**(半徑為1的圓)上的圓弧$\overset{\LARGE{\frown}}{AB}$,其中B點的座標為$(1,0)$,弧長為 $\theta$,則我們定義 $\cos\theta$ 為 A 點對應的 $x$ 座標,$\sin\theta$ 為 A 點對應的 $y$ 座標。 - 根據畢氏定理,$\sin^2\theta+\cos^2\theta=1$。 - $\cos (-\theta)=\cos \theta$ and $\sin(-\theta)=-\sin \theta$. - $\sin\theta = \cos (\pi/2-\theta)$. ![unit_circle_theta (6)](https://hackmd.io/_uploads/BJRIoidPeg.png) ```python= import matplotlib.pyplot as plt import numpy as np from matplotlib.patches import FancyArrowPatch # 角度 θ theta = np.pi / 3 # 60 degrees # 建立圖形與座標軸 fig, ax = plt.subplots(figsize=(6, 6)) ax.set_aspect('equal') ax.grid(True, which='both') # 畫單位圓 circle = plt.Circle((0, 0), 1, color='blue', fill=False) ax.add_artist(circle) # 原點 O O = (0, 0) ax.plot(*O, 'ko') ax.text(-0.05,-0.05, 'C', fontsize=12, verticalalignment='top', horizontalalignment='right') # 點 A(60 度) A = (np.cos(theta), np.sin(theta)) ax.plot(*A, 'ro') offset_x = 0.08 ax.text(A[0] + offset_x, A[1], r'$A=(\cos\theta,\sin\theta)$', fontsize=12, color='brown') # 點 B (1, 0) B = (1, 0) ax.plot(*B, 'bo') ax.text(B[0] + 0.05, B[1] + 0.05, r'B=(1,0)', fontsize=12, color='brown') # OA 向量 arrow = FancyArrowPatch(posA=O, posB=A, arrowstyle='->', color='green', mutation_scale=15, linewidth=2) ax.add_patch(arrow) # 圓弧 AB angle_arc = np.linspace(0, theta, 100) arc_radius = 1.0 arc_x = arc_radius * np.cos(angle_arc) arc_y = arc_radius * np.sin(angle_arc) ax.plot(arc_x, arc_y, 'purple') # 標記圓弧長 θ mid_theta = theta / 2 label_radius = 1.05 label_x = label_radius * np.cos(mid_theta) label_y = label_radius * np.sin(mid_theta) ax.text(label_x, label_y, r'$\theta$', fontsize=14, color='purple') # 座標軸設定 ax.set_xlim(-1.2, 1.4) ax.set_ylim(-0.2, 1.2) ax.axhline(0, color='black', linewidth=0.5) ax.axvline(0, color='black', linewidth=0.5) ax.set_xticks(np.arange(-1, 2, 1)) ax.set_yticks(np.arange(-1, 2, 1)) ax.spines['top'].set_visible(False) ax.spines['right'].set_visible(False) ax.spines['left'].set_visible(False) ax.spines['bottom'].set_visible(False) # 顯示圖形 plt.savefig("unit_circle_theta.png", dpi=300) plt.show() ``` ## 正弦定理 - 考慮一個圓內接三角形ABC。則我們可以證明 $$\frac{\overline{BC}}{\sin\angle A}=\text{外接圓的直徑}.$$ - 假設圓半徑為 $r$,角 A 為 $\theta$ 度,邊長BC為 $a$ 且平行於 $y$ 軸。由於圓心角為圓周角的兩倍,且OBC為等腰三角形。因此OB線段的輔角為 $\theta$ 度。此時,$B$ 的座標為 $(r\cos\theta,r\sin \theta)$。也因此 $$\begin{align}a&=2r\sin\theta\\ \frac{a}{\sin\theta}&=2r\end{align}$$ ![image](https://hackmd.io/_uploads/SJB_atgLWe.png) ```python= import matplotlib.pyplot as plt import numpy as np from matplotlib.patches import Arc def draw_clean_geometry_diagram(): # 1. 設定參數 r = 5 # 圓半徑 theta_deg = 35 # 設定 theta 為 35 度 (B在第一象限) theta_rad = np.radians(theta_deg) # A點在第二象限 angle_a_deg = 165 angle_a_rad = np.radians(angle_a_deg) # 2. 計算座標 O = np.array([0, 0]) B = np.array([r * np.cos(theta_rad), r * np.sin(theta_rad)]) C = np.array([r * np.cos(theta_rad), -r * np.sin(theta_rad)]) # C對稱於B A = np.array([r * np.cos(angle_a_rad), r * np.sin(angle_a_rad)]) # 3. 建立畫布 fig, ax = plt.subplots(figsize=(8, 8)) # 4. 畫圖形物件 # 畫圓 circle = plt.Circle((0, 0), r, color='gray', fill=False, linestyle='--', alpha=0.5) ax.add_patch(circle) # 畫三角形 ABC triangle_x = [A[0], B[0], C[0], A[0]] triangle_y = [A[1], B[1], C[1], A[1]] ax.plot(triangle_x, triangle_y, color='blue', linewidth=1.5) # 畫輔助線 OB 和 OC ax.plot([O[0], B[0]], [O[1], B[1]], color='green', linestyle='--', linewidth=1) ax.plot([O[0], C[0]], [O[1], C[1]], color='green', linestyle='--', linewidth=1) # 5. 設定座標軸 (隱藏刻度) ax.spines['left'].set_position('center') ax.spines['bottom'].set_position('center') ax.spines['right'].set_color('none') ax.spines['top'].set_color('none') # --- 關鍵修改:隱藏座標軸上的刻度與數字 --- ax.set_xticks([]) ax.set_yticks([]) # ------------------------------------- # 設定顯示範圍 (保持正方形比例) limit = r + 2 ax.set_xlim(-limit, limit) ax.set_ylim(-limit, limit) ax.set_aspect('equal') # 6. 標記文字與符號 # 原點 O ax.text(-0.5, -0.5, r'$O$', fontsize=12) # 座標軸名稱 (選擇性加入,讓圖更完整) ax.text(limit - 0.5, -0.5, r'$x$', fontsize=12) ax.text(0.2, limit - 0.5, r'$y$', fontsize=12) # 頂點 A, B, C ax.text(A[0]-0.6, A[1]+0.2, r'$A$', fontsize=12, color='blue') ax.text(B[0]+0.2, B[1]+0.2, r'$B=(r\cos\theta,r\sin\theta)$', fontsize=12, color='blue') ax.text(C[0]+0.2, C[1]-0.5, r'$C$', fontsize=12, color='blue') # B點座標 #ax.text(B[0]+0.3, B[1], r'$(r\cos \theta, r\sin \theta)$', fontsize=11) # 邊長標記 a, b, c ax.text(B[0] + 0.3, 0.3, r'$a$', fontsize=12, color='red', va='center') # BC邊 mid_ac = (A + C) / 2 ax.text(mid_ac[0] - 0.6, mid_ac[1] - 0.6, r'$b$', fontsize=12, color='red') # AC邊 mid_ab = (A + B) / 2 ax.text(mid_ab[0] - 0.3, mid_ab[1] + 0.4, r'$c$', fontsize=12, color='red') # AB邊 # 半徑標記 r (OB) mid_ob = (O + B) / 2 ax.text(mid_ob[0]-0.2, mid_ob[1] + 0.4, r'$r$', fontsize=12, color='green') # 半徑標記 r (OC) mid_oc = (O + C) / 2 ax.text(mid_oc[0]+0.2, mid_oc[1] + 0.2, r'$r$', fontsize=12, color='green') # 7. 標記角度 theta # (1) 原點處的 theta arc_O = Arc((0, 0), 2.5, 2.5, angle=0, theta1=0, theta2=theta_deg,color='purple') ax.add_patch(arc_O) ax.text(1.5 * np.cos(theta_rad/2), 0.8 * np.sin(theta_rad/2), r'$\theta$', fontsize=11,color='purple') # (2) A點處的 theta angle_AB = np.degrees(np.arctan2(B[1]-A[1], B[0]-A[0])) angle_AC = np.degrees(np.arctan2(C[1]-A[1], C[0]-A[0])) arc_A = Arc((A[0], A[1]), 2.5, 2.5, angle=0, theta1=angle_AC, theta2=angle_AB, color='purple') ax.add_patch(arc_A) bisector_rad = np.radians((angle_AB + angle_AC) / 2) label_dist = 1.8 ax.text(A[0] + label_dist * np.cos(bisector_rad), A[1] + label_dist * np.sin(bisector_rad), r'$\theta$', fontsize=11, color='purple') plt.title('Law of Sines', y=1.02) # plt.grid(True) # 隱藏網格讓圖面更乾淨 plt.show() if __name__ == "__main__": draw_clean_geometry_diagram() ``` ## 餘弦定理 - $a^2+b^2-2ab\cos\theta=c^2$. - 現在考慮線段BC長度為$a$,線段AC長度為$b$。由於相似三角形的邊長成比例,A點的座標為$(b\cos\theta,b\sin\theta)$,並且B點的座標為$(a,0)$。 - 計算線段AB的長度平方可得 \begin{align}c^2 &=(b\cos\theta-a)^2+b^2\sin^2\theta\\ &=b^2\cos^2\theta-2ab\cos\theta+a^2+b^2\sin^2\theta\\ &=a^2+b^2(\sin^2\theta+\cos^2\theta)-2ab\cos\theta\\ &=a^2+b^2-2ab\cos\theta. \end{align} ![Law of cosines (2)](https://hackmd.io/_uploads/SJv7cidDee.png) ```python= import matplotlib.pyplot as plt import numpy as np # 參數設定 a = 5.3 b = 6 theta_deg = 60 theta_rad = np.radians(theta_deg) # 三點座標 C = np.array([0, 0]) A = np.array([a * np.cos(theta_rad), a * np.sin(theta_rad)]) B = np.array([b, 0]) # 畫圖 fig, ax = plt.subplots() ax.set_aspect('equal') ax.set_xlim(-1, b + 1) ax.set_ylim(-1, a + 1) # 畫三角形 ax.plot([A[0], B[0], C[0], A[0]], [A[1], B[1], C[1], A[1]], 'k-') # 畫出 x, y 軸 ax.axhline(0, color='black', linewidth=1.2) ax.axvline(0, color='black', linewidth=1.2) # 關閉其他刻度與格線 ax.set_xticks([]) ax.set_yticks([]) ax.grid(False) ax.spines['top'].set_visible(False) ax.spines['right'].set_visible(False) ax.spines['left'].set_visible(False) ax.spines['bottom'].set_visible(False) # 標註點 ax.plot(*A, 'ro') ax.plot(*B, 'ro') ax.plot(*C, 'ro') ax.text(A[0],A[1]+0.1, r'$A=(b\cos\theta, b\sin\theta)$', fontsize=12, ha='left', va='bottom') ax.text(B[0],B[1]-0.1, r'$B=(a,0)$', fontsize=12, ha='left', va='top') ax.text(C[0]-0.1,C[1]-0.1, '$C$', fontsize=12, ha='right', va='top') # 標註邊長 ax.text((A[0] + C[0])/2-0.2,(A[1] + C[1])/2+0.2, '$b$', fontsize=12, color='blue') ax.text((B[0] + C[0])/2,(B[1] + C[1])/2-0.4, '$a$', fontsize=12, color='blue') ax.text((A[0] + B[0])/2+0.1,(A[1] + B[1])/2+0.1, '$c$', fontsize=12, color='blue') # 畫圓 circle = plt.Circle((0, 0), 0.8, color='blue', fill=False) ax.add_artist(circle) # 畫角 θ 弧線與標註 arc_radius = 0.8 arc = np.linspace(0, theta_rad, 100) arc_x = arc_radius * np.cos(arc) arc_y = arc_radius * np.sin(arc) ax.plot(arc_x, arc_y, 'purple') ax.text(arc_radius * np.cos(theta_rad / 2)+0.05, arc_radius * np.sin(theta_rad / 2)+0.05, r'$\theta$', fontsize=14, color='purple') plt.title('Law of Cosines') plt.savefig("Law of cosines.png", dpi=300) plt.show() ``` ## 內積公式和柯西不等式(Cauchy Inequality) - $ab\cos \theta=x_1x_2+y_1y_2$. - 根據餘弦定理, \begin{align} a^2+b^2-2ab\cos\theta&=c^2,\\ x_1^2+y_1^2+x_2^2+y_2^2-2ab\cos\theta&=(x_1-x_2)^2+(y_1-y_2)^2,\\ -2ab\cos\theta&=-2(x_1x_2+y_1y_2),\\ ab\cos\theta&=x_1x_2+y_1y_2. \end{align} - 柯西不等式:$(x_1^2+y_1^2)(x_2^2+y_2^2)\geq (x_1y_1+x_2y_2)^2$. - 因為 $\cos^2\theta\leq\cos^2\theta+\sin^2\theta=1$,根據上面的內積公式可以得到$$(x_1x_2+y_1y_2)^2\leq a^2b^2=(x_1^2+y_1^2)(x_2^2+y_2^2).$$ ![Inner_product (3)](https://hackmd.io/_uploads/B1FFfjdDxx.png) ```python= import numpy as np import matplotlib.pyplot as plt # 設定角度(以弧度) alpha = np.radians(80) beta = np.radians(20) theta = alpha - beta # 向量長度 r = 5 # 三點座標 A = (r * np.cos(alpha), r * np.sin(alpha)) B = ((r+1.3) * np.cos(beta), (r+1.3) * np.sin(beta)) O = (0, 0) # 建立圖形 fig, ax = plt.subplots() ax.set_aspect('equal') # 動態設定邊界,避免遮住文字(特別是 B 點的座標) x_max = max(A[0], B[0]) + 2.2 y_max = max(A[1], B[1]) + 1.5 ax.set_xlim(-1, x_max) ax.set_ylim(-1, y_max) # 畫出 x, y 軸 ax.axhline(0, color='gray', linewidth=1) ax.axvline(0, color='gray', linewidth=1) # 畫三角形邊 ax.plot([O[0], A[0]], [O[1], A[1]], 'b') # OA ax.plot([O[0], B[0]], [O[1], B[1]], 'b') # OB ax.plot([A[0], B[0]], [A[1], B[1]], 'b', linestyle='--', alpha=0.6) # AB # 點標記 ax.plot(*A, 'ro') ax.plot(*B, 'ro') ax.plot(*O, 'ko') # 標註點座標 ax.text(A[0] + 0.2, A[1], r'$A=(x_1, y_1)$', fontsize=12) ax.text(B[0] + 0.2, B[1] + 0.2, r'$B=(x_2, y_2)$', fontsize=12) # 往右上方偏移避免穿出邊界 ax.text(O[0] - 0.4, O[1] - 0.4, r'$O$', fontsize=12) # 標註邊 OA, OB, AB 分別為 a, b, c(置中位置) ax.text((O[0] + A[0]) / 2 - 0.3, (O[1] + A[1]) / 2 + 0.2, r'$a$', fontsize=14, color='black') ax.text((O[0] + B[0]) / 2 + 0.2, (O[1] + B[1]) / 2-0.25, r'$b$', fontsize=14, color='black') ax.text((A[0] + B[0]) / 2, (A[1] + B[1]) / 2 + 0.2, r'$c$', fontsize=14, color='black') # 畫三個角的弧線(依序由內而外:β→α→α-β) radius_beta = 1.4 radius_alpha = 0.8 radius_theta = 1.4 # β 弧線 beta_arc = np.linspace(0, beta, 100) ax.plot(radius_beta * np.cos(beta_arc), radius_beta * np.sin(beta_arc), color='blue') ax.text(radius_beta * np.cos(beta/2) + 0.1, radius_beta * np.sin(beta/2), r'$\beta$', fontsize=12, color='blue') # α 弧線 alpha_arc = np.linspace(0, alpha, 100) ax.plot(radius_alpha * np.cos(alpha_arc), radius_alpha * np.sin(alpha_arc), color='green') ax.text(radius_alpha * np.cos(alpha/2) + 0.1, radius_alpha * np.sin(alpha/2), r'$\alpha$', fontsize=12, color='green') # α - β 弧線 theta_arc = np.linspace(beta, alpha, 100) ax.plot(radius_theta * np.cos(theta_arc), radius_theta * np.sin(theta_arc), color='red') ax.text(radius_theta * np.cos((alpha + beta)/2) + 0.1, radius_theta * np.sin((alpha + beta)/2), r'$\theta=\alpha - \beta$', fontsize=12, color='red') # 關閉其他刻度與格線 ax.set_xticks([]) ax.set_yticks([]) ax.grid(False) ax.spines['top'].set_visible(False) ax.spines['right'].set_visible(False) ax.spines['left'].set_visible(False) ax.spines['bottom'].set_visible(False) # 顯示標題與圖形 plt.title("Inner Prouduct Formula", fontsize=14) plt.savefig("Inner_product.png", dpi=300) plt.show() ``` ## 和角公式 - $\cos(\alpha-\beta)=\cos\alpha\cdot\cos\beta+\sin\alpha\cdot \sin \beta$. - 考慮A, B 兩點都在單位圓上,此時 \begin{align} a&=b=1,\\ (x_1,y_1)&=(\cos\alpha,\sin\alpha),\\ (x_2,y_2)&=(\cos\beta,\sin\beta). \end{align} ![Trigonometric_Additionidentity (3)](https://hackmd.io/_uploads/S1HpQ3_Dgl.png) - 根據內積公式 \begin{align} ab\cos\theta&=x_1x_2+y_1y_2\\ \cos(\alpha-\beta)&=\cos\alpha\cos\beta+\sin\alpha\sin\beta \end{align} - $\cos (\alpha+\beta)=\cos\alpha\cdot \cos \beta-\sin\alpha\cdot\sin \beta$. - 由於 $\cos(-\beta)=\cos\beta,\sin(-\beta)=-\sin\beta$,因此 \begin{align} \cos(\alpha+\beta)&=\cos(\alpha-(-\beta))\\ &=\cos\alpha\cos(-\beta)+\sin\alpha\sin(-\beta)\\ &=\cos\alpha\cos\beta-\sin\alpha\sin\beta. \end{align} - 使用 $\sin\theta=\cos(\pi/2-\theta)$ 證明下面公式: - $\sin(\alpha-\beta)=\sin\alpha\cdot\cos\beta -\cos\alpha\cdot\sin\beta$. - $\sin(\alpha+\beta)=\sin\alpha\cdot\cos\beta+\cos\alpha\cdot\sin\beta$. ```python= import matplotlib.pyplot as plt import numpy as np from matplotlib.patches import FancyArrowPatch # 設定圖形與座標軸 fig, ax = plt.subplots(figsize=(6,6)) ax.set_aspect('equal') ax.grid(True, which='both') # 畫單位圓 circle = plt.Circle((0, 0), 1, color='blue', fill=False) ax.add_artist(circle) # 原點 O O = (0, 0) ax.plot(*O, 'ko') ax.text(*O, 'O', fontsize=12, verticalalignment='top', horizontalalignment='right') # A 點(135 度) alpha = np.pi*3 / 4 A = (np.cos(alpha), np.sin(alpha)) ax.plot(*A, 'ro') # B 點(45 度) beta = np.pi / 4 B = (np.cos(beta), np.sin(beta)) ax.plot(*B, 'ro') # A點向右偏移標籤與座標顯示 offset_x = 0.1 ax.text(A[0] + offset_x, A[1]-0.05, r'$A=(\cos\alpha,\sin\alpha)$', fontsize=12, color='brown') # B點向右偏移標籤與座標顯示 offset_x = 0.05 ax.text(B[0] + offset_x, B[1], r'$B=(\cos\beta,\sin\beta)$', fontsize=12, color='brown') # 使用 FancyArrowPatch 精準畫 OA 向量 arrow = FancyArrowPatch(posA=O, posB=A, arrowstyle='->', color='green', mutation_scale=15, linewidth=2) ax.add_patch(arrow) # 使用 FancyArrowPatch 精準畫 OB 向量 arrow = FancyArrowPatch(posA=O, posB=B, arrowstyle='->', color='green', mutation_scale=15, linewidth=2) ax.add_patch(arrow) # 畫角度弧線_A angle_arc_A = np.linspace(0, alpha, 100) arc_radius = 0.15 arc_x = arc_radius * np.cos(angle_arc_A) arc_y = arc_radius * np.sin(angle_arc_A) ax.plot(arc_x, arc_y, 'purple') ax.text(arc_radius * np.cos(alpha/2), arc_radius * np.sin(alpha/2), r'$\alpha$', fontsize=14) # 畫角度弧線_B angle_arc = np.linspace(0, beta, 100) arc_radius = 0.3 arc_x = arc_radius * np.cos(angle_arc) arc_y = arc_radius * np.sin(angle_arc) ax.plot(arc_x, arc_y, 'green') ax.text(arc_radius * np.cos(beta/2), arc_radius * np.sin(beta/2), r'$\beta$', fontsize=14) # 畫角度弧線_AB angle_arc_AB = np.linspace(beta, alpha, 100) arc_radius = 0.3 arc_x = arc_radius * np.cos(angle_arc_AB) arc_y = arc_radius * np.sin(angle_arc_AB) ax.plot(arc_x, arc_y, 'red') ax.text(arc_radius * np.cos(alpha*6/7)-0.1, arc_radius * np.sin(alpha*6/7)+0.05, r'$\theta=\alpha-\beta$', fontsize=14) # 座標軸設定 ax.set_xlim(-1.2, 1.4) ax.set_ylim(-0.2, 1.2) ax.set_xticks(np.arange(-1, 2, 1)) ax.set_yticks(np.arange(-1, 2, 1)) ax.axhline(0, color='black', linewidth=0.5) ax.axvline(0, color='black', linewidth=0.5) #ax.grid(False) ax.spines['top'].set_visible(False) ax.spines['right'].set_visible(False) ax.spines['left'].set_visible(False) ax.spines['bottom'].set_visible(False) plt.title('Trigonometric Additionidentity Formula') plt.savefig("Trigonometric_Additionidentity.png", dpi=300) plt.show() ``` ## Cauchy–Schwarz Inequality (廣義柯西不等式) - $(x_1^2+x_2^2+\cdots+x_n^2)(y_1^2+y_2^2+\cdots+y_n^2)\geq (x_1y_2+x_2y_2+\cdots+x_ny_n)^2$. - 令 $u=(x_1,\dots,x_n),v=(y_1,\dots,y_n)$,並且定義$n$維向量的內積運算: $$u\cdot v = x_1y_1+\cdots+x_ny_n.$$ - 當 $u\cdot v=0$時,我們可以抽象地說此時$u$和$v$兩向量互相"垂直"! - 令 $\displaystyle w=\frac{u\cdot v}{v\cdot v}v$. - 請檢驗 $(u-w)\cdot v = 0$。 - 當我們將$u$分解為$u=(u-w)+w$時,$w$與$v$平行,$u-w$與$v$垂直。 - 請檢驗 $\displaystyle u\cdot u = (u-w)\cdot (u-w)+w\cdot w\geq w\cdot w=\frac{(u\cdot v)^2}{v\cdot v}$,其中\begin{align*} u\cdot u&=x_1^2+\cdots+x_n^2,\\ v\cdot v&=y_1^2+\cdots+y_n^2,\\ u\cdot v&=x_1y_1+\cdots+x_ny_n. \end{align*} - 由上式可得 $(u\cdot u)(v\cdot v)\geq (u\cdot v)^2$。