Python 量子運算(一六):和角
2023/01/24
-----
Fig. 1. Angle sum.
-----
和角 angle sum
和角公式 angle sum formula
差角 angle difference
差角公式 angle difference formula
「Along with angle difference formulas, we have angle sum formulas as well.」[1]。
-----
代碼 16.1
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 | # Program 16.1:Angle sum import numpy as np import matplotlib as mpl import matplotlib.pyplot as plt # defined by angle class PointT1: def __init__(self, t, r): self.t = t # theta self.r = r # radius self.x = r * np.cos(t) self.y = r * np.sin(t) # defined by points class PointT2: def __init__(self, x, y): self.x = x self.y = y def Subplot_1(): ax = plt.subplot(111) # circle c = np.linspace(0, np.pi*2, 100) r = 1 c_x = r * np.cos(c) c_y = r * np.sin(c) ax.plot(c_x, c_y, 'g', linestyle='--') # points t_A = (31/24) * np.pi # theta A setting PA = PointT1(t_A, r) # A PC = PointT1(t_A-np.pi, r) # C, determined by A ax.plot([PA.x, PC.x], [PA.y, PC.y], 'purple', linewidth=5.0) # AC ax.text(PA.x-0.1, PA.y-0.1, 'A') ax.text(PC.x+0.05, PC.y+0.05, 'C') PB = PointT2(PC.x, PA.y) # B, determined by A, C ax.plot([PA.x, PB.x], [PA.y, PA.y], 'r', linestyle='--') # AB ax.plot([PB.x, PB.x], [PB.y, PC.y], 'purple', linestyle='--') # BC ax.text(PB.x+0.05, PB.y-0.1, 'B') PG = PointT2(PA.x, PC.y) # G, determined by A, C ax.plot([PA.x, PG.x], [PA.y, PG.y], 'purple', linestyle='--') # AG ax.plot([PC.x, PG.x], [PC.y, PG.y], 'purple', linestyle='--') # CG ax.text(PG.x-0.1, PG.y+0.05, 'G') t_E = (47/24) * np.pi # theta E setting PE = PointT1(t_E, r) # E ax.plot([PA.x, PE.x], [PA.y, PE.y], 'r', linewidth=5.0) # AE ax.plot([PC.x, PE.x], [PC.y, PE.y], 'b', linewidth=5.0) # CE ax.text(PE.x+0.05, PE.y, 'E') PD = PointT2(PE.x, PC.y) # D, determined by C, E ax.plot([PC.x, PD.x], [PC.y, PD.y], 'b', linestyle='--') # CD ax.plot([PD.x, PE.x], [PD.y, PE.y], 'b', linestyle='--') # DE ax.text(PD.x+0.05, PD.y+0.05, 'D') PF = PointT2(PE.x, PB.y) # F, determined by B, E ax.plot([PB.x, PF.x], [PB.y, PF.y], 'r', linestyle='--') # BF ax.plot([PE.x, PF.x], [PE.y, PF.y], 'r', linestyle='--') # EF ax.text(PF.x+0.05, PF.y-0.1, 'F') # angles ax.text(PA.x+0.25, PA.y+0.20, r'$\alpha$') ax.text(PA.x+0.35, PA.y+0.05, r'$\beta$') ax.text(PE.x-0.08, PE.y+0.25, r'$\beta$') ax.text(PC.x-0.35, PC.y-0.10, r'$\alpha+\beta$') # edges ax.text((PA.x+PE.x)/2-0.2, (PA.y+PE.y)/2, r'$\cos\alpha$', color='r') ax.text((PA.x+PF.x)/2-0.1, (PA.y+PF.y)/2, r'$\cos\alpha\cos\beta$', color='r') ax.text((PE.x+PF.x)/2, (PE.y+PF.y)/2, r'$\cos\alpha\sin\beta$', color='r') ax.text((PC.x+PE.x)/2-0.2, (PC.y+PE.y)/2, r'$\sin\alpha$', color='b') ax.text((PD.x+PE.x)/2, (PD.y+PE.y)/2, r'$\sin\alpha\cos\beta$', color='b') ax.text((PC.x+PD.x)/2-0.15, (PC.y+PD.y)/2, r'$\sin\alpha\sin\beta$', color='b') ax.text((PC.x+PG.x)/2-0.2, (PC.y+PG.y)/2, r'$\cos(\alpha+\beta)$', color='purple') ax.text((PA.x+PG.x)/2-0.4, (PA.y+PG.y)/2, r'$\sin(\alpha+\beta)$', color='purple') ax.set_aspect(1) # height : width ax.set_axis_off() return mpl.rcParams['text.usetex'] = True mpl.rcParams['text.latex.preamble'] = r'\usepackage{{amsmath}}' mpl.rcParams['font.size'] = 40 fig = plt.figure(figsize=(16, 16)) Subplot_1() # plt.savefig('/content/drive/My Drive/pqc/0016_001.png') plt.show() |
解說:
-----
References
[1] What are Angle Difference Formulas? Examples
https://www.cuemath.com/angle-difference-formula/
[2] 7.2: Sum and Difference Identities - Mathematics LibreTexts
[3] 三角函數的和差角公式
http://www.mathland.idv.tw/fun/triiden.htm
# dashed
[4] How to use linestyles in Matplotlib
https://www.educative.io/answers/how-to-use-linestyles-in-matplotlib
# grey
[5] matplotlib.pyplot.plot — Matplotlib 3.6.3 documentation
https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.plot.html
[6] 如何在 Matplotlib 圖例中設定線的線寬 | D棧 - Delft Stack
# class、object、__init__()、method、self、del
[7] Python Classes
https://www.w3schools.com/python/python_classes.asp
# inheritance、parent class、child class、super()
[8] Python Inheritance
https://www.w3schools.com/python/python_inheritance.asp
-----
Python 量子運算(目錄)
https://mandhistory.blogspot.com/2022/01/quantum-computing.html
-----
沒有留言:
張貼留言
注意:只有此網誌的成員可以留言。