0
0

三角関数の合成「2024 慶應義塾大学 経済[1](2)」をsympyとグラフ作図をやってみたい。

Last updated at Posted at 2024-02-26

パイソニスタの方へ
・三角関数の合成を探しています。
 見つからなかったので自作(def mySinCosSin(A,B):)しました。
??? >三角関数の合成
https://math-fun.net/20211224/21139/#i-6

オリジナル

問題[1](2)
https://www.yomiuri.co.jp/nyushi/sokuho/s_mondaitokaitou/keio/mondai/img/keio_213_sugaku_mon.pdf#page=1
 
解答
https://www.yomiuri.co.jp/nyushi/sokuho/s_mondaitokaitou/keio/kaitou/img/keio_213_sugaku_kai.pdf#page=1
< 2024 慶應義塾大学 経済 < 読売新聞オンライン 様のページ
https://www.yomiuri.co.jp/nyushi/sokuho/s_mondaitokaitou/keio/1376715_5113

上と同じです。大学入試数学問題集成 様>テキスト
未登録(2024/02/26)

公式ホームページ
未登録(2024/02/26)

解答解説

めぐろ塾 様
操作はスクロールして下さい。ジャンプしません。[1] (2)

sympyで

・ver0.1 という事で。めぐろ塾 様を参考にしました。
・sympyで、yの最大値、最小値を求めるだけなら、tanへ置換は不要です。
 
・Returns the maximum value of a function in the given domain.
https://docs.sympy.org/latest/modules/calculus/index.html#sympy.calculus.util.maximum
・Lowering the degree of cos(x)**2.
https://docs.sympy.org/latest/modules/simplify/fu.html#sympy.simplify.fu.TR7
・Returns the n-th coefficient of f where N are the exponents of the generators in the term of interest.
https://docs.sympy.org/latest/modules/polys/reference.html#sympy.polys.polytools.Poly.nth

# ver0.1
from sympy import *
from sympy.simplify.fu import TR7
import re
var('x,y'  ,real=True)
var('θ,α',real=True)
var('f1213,cosα,sinα',real=True,positive=True)
def myPoly(y):
     q, r = div(numer(y), denom(y), domain ='QQ')   
     y1 =q+r/denom(y)    
     y2 =y1-q
     expr = numer(y2)	            # 式を定義
     expr_poly = poly(expr, x)	    # x1,x2,x3に着目した多項式オブジェクトを作成
     x1_coef   = expr_poly.nth(1)	# x1の係数
     constant  = expr_poly.nth(0)	# 定数 
     return q,x1_coef, constant
def mySinCosSin(A,B):
     sol=solve( [Eq(f1213*sinα,A),Eq(f1213*cosα,B),Eq(sinα**2+cosα**2,1)],[f1213,sinα,cosα] )[0]
     return sol[0],sol[1],sol[2]
def mySinCosSin(A,B):
     sol=solve( [Eq(f1213*sinα,A),Eq(f1213*cosα,B),Eq(sinα**2+cosα**2,1)],[f1213,sinα,cosα] )[0]
     return sol[0],sol[1],sol[2]
def myy3y4(y3):
     expr_poly = poly(y3, sin(2*θ),cos(2*θ))	    # x1,x2,x3に着目した多項式オブジェクトを作成
     x1_coef   = expr_poly.nth(1,0)	# x1の係数
     x2_coef   = expr_poly.nth(0,1)	# x1の係数
     constant  = expr_poly.nth(0,0)	# 定数 
     f1213,cosalpha,sinalpha=mySinCosSin(x1_coef,x2_coef)
     return f1213*sin(2*θ+α)+constant,cosalpha,sinalpha
# 
rep   ={x:tan(θ)}
f0809L=(x/(x**2+1))                                     
f0809R=f0809L.subs(rep).simplify()                     
f1011L=1/(x**2+1)                                        
f1011R=f1011L.subs(rep)               
f1011R=(      TR7(numer(f1011R)*cos(θ)**2)
        /simplify(denom(f1011R)*cos(θ)**2)).factor() 
# 
y1 =(x**2+3*x+5)/(x**2+1)   
sol=myPoly(y1)
y2 =sol[0]+sol[1]*x/denom(y1)+sol[2]/denom(y1)
rep={f0809L:f0809R,f1011L:f1011R}
y3 =y2.subs(rep).simplify()                   #;print(y3)             
sol_c_s=myy3y4(y3)
# sol=solveset(Le(abs(tan(θ)),1),θ,Interval(-pi/2,pi/2))     
# sol=solveset(Eq(abs(tan(θ)),1),θ,Interval(-pi/2,pi/2))     
sol=solveset(Eq(      tan(θ) ,1),θ,Interval(-pi/2,pi/2)).args[0]     
#  
print("# 0809  ",Eq(f0809L,f0809R))
print("# 1011  ",Eq(f1011L,f1011R))
print("# 121314",Eq(y    ,sol_c_s[0] ))
print("# 1516  ",Eq(cosα,sol_c_s[1] ))
print("# 1718  ",Eq(sinα,sol_c_s[2] ))
print()
print("# 19    ",      -  sol," "*13           ,"≦ θ   ≦",        sol)    
print("# 19    ",float(-2*sol+acos(sol_c_s[1])),"≦2θ+α≦",float(2*sol+acos(sol_c_s[1])))
print("# 19    ","y=",y3)
print("# 202122",maximum(5*sin(x)/2 + 3,x,Interval(-2*sol+acos(sol_c_s[1]),2*sol+acos(sol_c_s[1])))  )
print("# 202122",minimum(5*sin(x)/2 + 3,x,Interval(-2*sol+acos(sol_c_s[1]),2*sol+acos(sol_c_s[1])))  )
print()
print("# 202122",maximum(y1,x,Interval(-1,1))   ,float( maximum(y1,x,Interval(-1,1)) ))
print("# 2324  ",minimum(y1,x,Interval(-1,1)),"",float( minimum(y1,x,Interval(-1,1)) ))
# 
from sympy.plotting import plot
plot(0,y1,(x,-1,1),aspect_ratio=(1.0,1.0))

# 0809   Eq(x/(x**2 + 1), sin(2*θ)/2)
# 1011   Eq(1/(x**2 + 1), (cos(2*θ) + 1)/2)
# 121314 Eq(y, 5*sin(α + 2*θ)/2 + 3)
# 1516   Eq(cosα, 3/5)
# 1718   Eq(sinα, 4/5)

# 19     -pi/4               ≦ θ   ≦ pi/4
# 19     -0.6435011087932844 ≦2θ+α≦ 2.498091544796509
# 19     y= 3*sin(2*θ)/2 + 2*cos(2*θ) + 3
# 202122 11/2
# 202122 3/2

# 202122 11/2 5.5
# 2324   3/2  1.5

グラフ作図

1.png

いつもの? sympyの実行環境と 参考のおすすめです。

(テンプレート)

いつもと違うおすすめです。

・div

・??? 定角 で

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