Sin Waves and Cos Waves

 Sin Waves and Cos Waves
I wrote some code about Sin waves and Cos waves. I hope you can enjoy this figures.


    import numpy as np
    import matplotlib.pyplot as plt
    
    # データ生成
    x = np.linspace(-3.15, 3.15, 100)
    y1 = np.sin(x)
    y2 = -y1
    y3 = y1 / 2
    y4 = - y3
    y5 = y3 / 2
    y6 = -y5
    y7 = y5 / 2
    y8 = -y7
    y9 = y7 / 2
    y10 = -y9
    
    # グラフ描画
    plt.figure(figsize=(8, 6))
    plt.plot(x, y1)
    plt.plot(x, y2)
    plt.plot(x, y3)
    plt.plot(x, y4)
    plt.plot(x, y5)
    plt.plot(x, y6)
    plt.plot(x, y7)
    plt.plot(x, y8)
    plt.plot(x, y9)
    plt.plot(x, y10)
    plt.xlabel("x")
    plt.ylabel("y")
    plt.title("Sin Waves")
    plt.legend()
    plt.grid(True)
    plt.show()
    
    # データ生成
    x = np.linspace(-3.15, 3.15, 100)
    y1 = np.cos(x)
    y2 = -y1
    y3 = y1 / 2
    y4 = - y3
    y5 = y3 / 2
    y6 = -y5
    y7 = y5 / 2
    y8 = -y7
    y9 = y7 / 2
    y10 = -y9
    
    # グラフ描画
    plt.figure(figsize=(8, 6))
    plt.plot(x, y1)
    plt.plot(x, y2)
    plt.plot(x, y3)
    plt.plot(x, y4)
    plt.plot(x, y5)
    plt.plot(x, y6)
    plt.plot(x, y7)
    plt.plot(x, y8)
    plt.plot(x, y9)
    plt.plot(x, y10)
    plt.xlabel("x")
    plt.ylabel("y")
    plt.title("Cos Waves")
    plt.legend()
    plt.grid(True)
    plt.show()

Popular posts from this blog

Difference between Type Stack (S) and Type Queue (Q)