1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

「一から始める数学⑩>余弦定理」を参考にSymPyでやってみた。

Last updated at Posted at 2021-07-08

(オリジナルポスト)

Pycharmで(加法定理の証明?)

半径1の円に点A(cosα、sinα)、点B(cosβ、sinβ)
A,B二点間の距離は.....

コーディングしていて、「鶏が先か、卵が先か」のような気もします。

from sympy import *
var('α β')
var('b c A x')
var('ca sa cb sb')
myLAB=(cos(α)-cos(β))**2+(sin(α)-sin(β))**2
myLYO=(b**2+c**2-2*b*c*cos(α-β)).subs({b:1,c:1})
print("#myLAB=",myLAB)
print("#myLYO=",myLYO)
myGosa=expand(myLAB-myLYO)
myGosa=myGosa.subs({sin(α)**2+cos(α)**2:1,sin(β)**2 + cos(β)**2:1})
myGosa=myGosa.subs({cos(α):ca,sin(α):sa,cos(β):cb,sin(β):sb})
myGosa=solve(myGosa,cos(α-β))[0]
myGosa=myGosa.subs({ca:cos(α),sa:sin(α),cb:cos(β),sb:sin(β)})
print("#cos(α-β)=",myGosa)
#myLAB= (sin(α) - sin(β))**2 + (cos(α) - cos(β))**2
#myLYO= 2 - 2*cos(α - β)
#cos(α-β)= sin(α)*sin(β) + cos(α)*cos(β)

Pycharmで(加法定理です。)

from sympy import *
var('α β')
myAB=expand_trig(cos(α-β))
print("#",myAB)
print("#",trigsimp(myAB))
# sin(α)*sin(β) + cos(α)*cos(β)
# cos(α - β)

#SymPy Liveで エラーがでます。

    myAB=expand_trig(cos(α-β))
                         ^
SyntaxError: invalid syntax

#SymPy Liveで(英小文字にしました。)
以下のソースコードを貼り付けて、Evaluateです。

from sympy import *
var('a b')
myAB=expand_trig(cos(a-b))
print("#",myAB)
print("#",trigsimp(myAB))
# ('#', sin(a)*sin(b) + cos(a)*cos(b))
# ('#', cos(a - b))

参考

>東大でも出題された

1
1
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
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?