1
2

pythonで双曲線の書き方

Posted at

特殊相対論でもよく出てくる双曲線。

初めに設定を描く。
文書は書くのは今回初めてでたぶん汚いコードだけどなんかあれば
無視してください。あくまでも参考程度の
感想文より技術文書のほうが書きやすいけどw
まずは設定

import numpy as np
import matplotlib.pyplot as plt
plt.figure(figsize=(10, 10))
plt.grid()
plt.xlim(-3,3)#x=3からx=3までの範囲を表示
plt.ylim(-3,3)

次にx軸,y軸

xx=np.linspace(-5,5)

#y軸
y=0*xx
plt.plot(xx,y)

#x軸
xx=np.repeat(0,50)#xを50個0を作る
y4=np.linspace(-5,5)
plt.plot(xx,y4)

次に二次曲線

\frac{x^2}{a^2}-\frac{y^2}{b^2}=1

移行すると

y^2=\frac{b}{a}\sqrt{x^2-a^2}



"""
二次曲線を描く
"""
import math


#y=sqrt(x*x-1)
def square_root_function(x):
    return np.sqrt(x*x-1)

#
def square_root_function2(x):
    return np.sqrt(x*x-2*2)


# xの範囲を指定 (xは非負である必要があります)
x_values = np.linspace(1, 5, 100)

# 平方根関数の計算
y_values = square_root_function(x_values)

# グラフの描画
plt.plot(x_values, y_values, label='y = sqrt(x)')
plt.plot(x_values, -y_values, label='y = sqrt(x)')

plt.plot(-x_values, y_values, label='y = sqrt(x)')
plt.plot(-x_values, -y_values, label='y = sqrt(x)')

ここまで
f1.png
双曲線をもう2つ書く
a=2 b=2とa=1.5とb=1.5の時の曲線

a=2
b=2
x = np.linspace(2, 5, 100)
#x*x/a/a-y*y/b/b=1
y=b/a*np.sqrt(x*x/a/a-b/a)
# グラフの描画
plt.plot(x, y)
plt.plot(x, -y)
plt.plot(-x, y)
plt.plot(-x, -y)

a=1.5
b=1.5
x = np.linspace(1.5, 5, 100)
#x*x/a/a-y*y/b/b=1
y=b/a*np.sqrt(x*x/a/a-b/a)
# グラフの描画
plt.plot(x, y)
plt.plot(x, -y)
plt.plot(-x, y)
plt.plot(-x, -y)


#y=x y=-x
xx=np.linspace(-3,3)
plt.plot(xx, xx, label='y = sqrt(x)')
plt.plot(xx, -xx, label='y = sqrt(x)')

f2.png
最後に
双曲線から接線の式を描く
x=2での接線
双曲線の式は

\frac{x^2}{1^2}-\frac{y^2}{1^2}=1

#------------------------------------------
#双曲線上で接する直線
#x=2での接線
#式はy-y1=x1/y1(x-x1)
#------------------------------------------
xx=np.linspace(0,3)
y=2/31.732xx-1.732/3
plt.plot(xx, y)

plt.title('curve double')

plt.grid(True)
plt.show()

![f3.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/354057/9a550ec6-bbeb-976b-6c32-54ad5481838a.png)
1
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
2