0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

複素数平面「(その1/4)【1問多解】2025年 京都大(理系) 複素数の絶対値の最大・最小」様を参考にsympyでやってみた。

Last updated at Posted at 2025-04-10

長文です。 以下、高校数学の範囲外が含まれています。
・参照サイトは、ページの最後です。
・matplotlibで作図しました。
一次分数変換(linear fractional transformation)もわからずに、投稿している私の無謀さに気づきました。

オリジナル

・Youtube
 KATSUYA【東大数学9割】様 (0:00〜24:51)
 【1問多解】 2025年 京都大(理系) 複素数の絶対値の最大・最小
 https://youtu.be/jWE6EVA_0SQ

・web
 代々木ゼミナール 様
 https://qiita.com/mrrclb48z/items/6bd182b3d13cb19a6433#%E3%82%B5%E3%83%B3%E3%83%97%E3%83%AB%E3%83%87%E3%83%BC%E3%82%BF

・問題文(mathjax テキスト形式)
 大学入試数学問題集成 様。いつもお世話になっております。
 2025 京都大学 前期MathJax理系【1】問1
 https://mathexamtest.web.fc2.com/2025/202510541/2025105410100mj.html
 https://mathexamtest.web.fc2.com/daigakubetumj/10541index.html#y2025

sympyのweb上での実行方法

 SymPy Live Shellで。
 https://qiita.com/mrrclb48z/items/00dd08b0317069be9342#web%E4%B8%8A%E3%81%AE%E5%AE%9F%E8%A1%8C%E6%96%B9%E6%B3%95sympy-live-shell%E3%81%A7
 

WolframAlpha で

・KATSUYA【東大数学9割】様の yuyasato4132 様のコメントより
 ??? カエルの気持ちで。作図をして検証中です。
https://www.wolframalpha.com/input?i=2-1%2F2%2C2%2B1%2F2&lang=ja
結果 {3/2, 5/2}

sympyで(KATSUYA【東大数学9割】様 の方法を参考に)

 このセクションは、私の勉強用です。
 プログラムではありません。
 プログラムは、次のセクションsympyで(いつもの方法で)です。

ver0.1 [解1] 00:44

・1次分数変換

# 次はプログラムではありません。
# ver0.1 [解1] 00:44
from sympy import *
var('z',complex=true)
var('θ',real   =true)
myInterval=Interval(0,2*pi)
w= z-I/z              ;print("#",w)
print("#",abs(w))
z=2*(cos(θ)+I*sin(θ)) ;print("#",z)
print("#",  I/z)
print("#",( (I*conjugate(z)).simplify()
           /(z*conjugate(z)).simplify()))
w=z-      ( (I*conjugate(z)).simplify()
           /(z*conjugate(z)).simplify())
print("#",w)
w_abs2=(w*conjugate(w)).simplify()
print("#",w_abs2)
w_abs2_min=minimum(w_abs2,θ,myInterval)
w_abs2_max=maximum(w_abs2,θ,myInterval)
print("#",sqrt(w_abs2_min),sqrt(w_abs2_max)) 
print("#",solveset(Eq(w_abs2,w_abs2_min),θ,myInterval),
          solveset(Eq(w_abs2,w_abs2_max),θ,myInterval) )
# z - I/z
# Abs(z - I/z)
# 2*I*sin(θ) + 2*cos(θ)
# I/(2*I*sin(θ) + 2*cos(θ))
# sin(θ)/2 + I*cos(θ)/2
# -sin(θ)/2 + 2*I*sin(θ) + 2*cos(θ) - I*cos(θ)/2
# 17/4 - 2*sin(2*θ)
# 3/2 5/2
# {pi/4, 5*pi/4} {3*pi/4, 7*pi/4}

ver0.2 [解2] 09:56

# 次はプログラムではありません。
# ver0.2 [解2] 09:56
from sympy import *
var('z',complex=true)
var('θ',real   =true)
myInterval=Interval(0,2*pi)
w= z-I/z                           ;print("#",w)
w_abs2=(w*conjugate(w)).simplify() ;print("#",w_abs2.expand())
rep   ={z:2*(cos(θ)+I*sin(θ))}
maru1 =z*conjugate(z)+ 1/(z*conjugate(z))
print("#",maru1)
maru1 =(maru1.subs(rep)).simplify()
print("#",maru1)
maru2B= z/conjugate(z) 
print("#",maru2B)
maru2B=(maru2B.subs(rep)).simplify()
print("#",maru2B)
print("#",re(maru2B.simplify()) + im(maru2B.simplify())*I) 
print("#",re(maru2B.simplify()) - im(maru2B.simplify())*I) 
maru2=    re(maru2B.simplify()) + im(maru2B.simplify())*I \
        -(re(maru2B.simplify()) - im(maru2B.simplify())*I) 
print("#",maru2)
print("#",maru1+maru2*I)
# >以下省略させていただきます。
# z - I/z
# z*conjugate(z) + I*z/conjugate(z) - I*conjugate(z)/z + 1/(z*conjugate(z))
# z*conjugate(z) + 1/(z*conjugate(z))
# 17/4
# z/conjugate(z)
# exp(2*I*θ)
# I*sin(2*θ) + cos(2*θ)
# -I*sin(2*θ) + cos(2*θ)
# 2*I*sin(2*θ)
# 17/4 - 2*sin(2*θ)

ver0.3 [解3] 15:30

# 次はプログラムではありません。
# ver0.3 [解3] 15:30
from sympy import *
var('z',complex=true)
w_abs=abs(z**2-I)/2
R4=4
print("#",Rational(1,2)*(R4-1),Rational(1,2)*(R4+1))
# # 3/2 5/2

ver0.4 [解4] 19:06

# 次はプログラムではありません。
# ver0.4 [解4] 19:06 
from sympy import *
var('z')
rep={Abs(z**2):4}
w_abs=abs(z**2-I)/2
left1 = abs(abs(z**2) - abs(I))
left2 =     abs(z**2  -     I)
right =     abs(z**2) + abs(I)
left1_rep=left1.subs(rep)       #;print(left1_rep)
left2_rep=left2.subs(rep)       #;print(left2_rep)
right_rep=right.subs(rep)       #;print(right_rep)
print("#",left1_rep,"<=",left2_rep,"<=",right_rep)
solutions=solve(Eq(z**2, 4*I),z)  # ;print(solutions)
print("#",factor(re(solutions[0]) + im(solutions[0])*I),",",
          factor(re(solutions[1]) + im(solutions[1])*I)) 
solutions=solve(Eq(z**2,-4*I),z)  # ;print(solutions)
print("#",factor(re(solutions[0]) + im(solutions[0])*I),",",
          factor(re(solutions[1]) + im(solutions[1])*I)) 
# 3 <= Abs(z**2 - I) <= 5
# sqrt(2)*(-1 - I) , sqrt(2)*(1 + I)
# sqrt(2)*(-1 + I) , sqrt(2)*(1 - I)

sympyで(いつもの方法で)KATSUYA【東大数学9割】様 の方法を参考に

ver1.1 [解1] 00:44

・>成分θで攻める. 
 ???変数x,yの2個じゃ扱いづらいから、変数1個θにする、(R固定のため)
・ いつものように、倍角公式の手抜きです。

# ver1.1 [解1] 00:44
from sympy import *
var('z'  ,complex=true)
var('θ,R',real   =true)
def myFukusosuAbsθ(myabs,θ):
    return myabs*(cos(θ)+I*sin(θ))
def myFukusosuSyo(w):
    return  (numer(w)*conjugate(denom(w))) \
           /(denom(w)*conjugate(denom(w))).simplify()
myInterval=Interval(0,2*pi)
R         =2
        =myFukusosuAbsθ(R,θ)                          # ;print("#",zθ)    
Izθ       =myFukusosuSyo((I/z).subs({z:})).simplify() # ;print("#",Izθ)
w_abs2    =(abs(-Izθ)**2).simplify()                    ;print("#",w_abs2)
w_abs2_min=minimum(w_abs2,θ,myInterval)
w_abs2_max=maximum(w_abs2,θ,myInterval)
print("#",sqrt(w_abs2_min),sqrt(w_abs2_max)) 
print("#",solveset(Eq(w_abs2,w_abs2_min),θ,myInterval),
          solveset(Eq(w_abs2,w_abs2_max),θ,myInterval) )
# 17/4 - 2*sin(2*θ)
# 3/2 5/2
# {pi/4, 5*pi/4} {3*pi/4, 7*pi/4}

ver1.2 [解2] 09:56

・>途中までzのまま攻める >難しくなったら..

# ver1.2 [解2] 09:56
from sympy import *
var('z',complex=true)
var('θ',real   =true)
def myFukusosuθ(R,θ):
    return R*(cos(θ)+I*sin(θ))
myInterval =Interval(0,2*pi)
R          = 2
rep        ={z*conjugate(z):R**2}
w          = z-I/z
w_abs2     =((w*conjugate(w)).expand()).subs(rep)           #;print("#",w_abs2)
wθ_abs2    =w_abs2.subs({z:myFukusosuθ(R,θ)}).simplify()    #;print("#",w_abs2)
wθ_abs2_min=minimum(wθ_abs2,θ,myInterval)                   #;print("#",wθ_abs2_max)
wθ_abs2_max=maximum(wθ_abs2,θ,myInterval)                   #;print("#",wθ_abs2_min)
print("#",sqrt(wθ_abs2_min),sqrt(wθ_abs2_max)) 
print("#",solveset(Eq(wθ_abs2,wθ_abs2_min),θ,myInterval),
          solveset(Eq(wθ_abs2,wθ_abs2_max),θ,myInterval))
# 3/2 5/2
# {pi/4, 5*pi/4} {3*pi/4, 7*pi/4}

ver1.3 [解3] 15:30

・>zを成分化しない。

# ver1.3 [解3] 15:30 
from sympy import *
var('z',complex=true)
var('θ',real=true)
def myFukusosuθ(R,θ):
    return R*(cos(θ)+I*sin(θ))
def myFukusosuAbsθ(myabs,θ):
    return myabs*(cos(θ)+I*sin(θ))
def myAbs(w):
    return numer(w)/abs(denom(w))
myInterval  =Interval(0,2*pi)
R           =2
rep         ={Abs(z):R}                                   # ;print("#",w)
w           =z-I/z                                        # ;print("#",w)
w_abs       =abs(factor(myAbs(cancel(w)).subs(rep)))      # ;print("#",w_abs)
w_absθ      =w_abs.subs({z:myFukusosuθ(R,θ)}).simplify()  # ;print("#",w_absθ)
w_absθ_min=minimum(w_absθ,θ,myInterval)                   # ;print("#",wθ_abs2_max)
w_absθ_max=maximum(w_absθ,θ,myInterval)                   # ;print("#",wθ_abs2_min)
print("#",                   w_absθ_min,w_absθ_max) 
print("#",solveset(Eq(w_absθ,w_absθ_min),θ,myInterval),
          solveset(Eq(w_absθ,w_absθ_max),θ,myInterval))
# 3/2 5/2
# {pi/4, 5*pi/4} {3*pi/4, 7*pi/4}

ver1.4 [解4] 19:06

・>三角不等式 (θを使っていない)

# ver1.4 [解4] 19:06
from sympy import *
var('z')
rep={Abs(z**2):4}
left1 = abs(abs(z**2) - abs(I))
left2 =     abs(z**2  -     I)
right =     abs(z**2) + abs(I)
# 
left1_rep=left1.subs(rep)         ;print("#",left1_rep)
left2_rep=left2.subs(rep)         ;print("#",left2_rep)
right_rep=right.subs(rep)         ;print("#",right_rep)
# 
solutions=solve(Eq(z**2, 4*I),z)  # ;print(solutions)
print("#",factor(re(solutions[0]) + im(solutions[0])*I),",",
          factor(re(solutions[1]) + im(solutions[1])*I)) 
solutions=solve(Eq(z**2,-4*I),z)  # ;print(solutions)
print("#",factor(re(solutions[0]) + im(solutions[0])*I),",",
          factor(re(solutions[1]) + im(solutions[1])*I)) 
# 3
# Abs(z**2 - I)
# 5
# sqrt(2)*(-1 - I) , sqrt(2)*(1 + I)
# sqrt(2)*(-1 + I) , sqrt(2)*(1 - I)

sympyで(代ゼミ 様の方法で)

ver2.1 代ゼミ 様 複素数平面のθで

・次のコードだとエラーがでます。

# ver2.1 代ゼミ 様 複素数平面のθで 
from sympy import *
var('z,w',complex=true)
var('θ'  ,real   =true)                                 0<=θ<2*πを省略です
R=2
z=R*(cos(θ)+I*sin(θ))
w=z-I/z                                                #;print(w)
w_abs=abs(w)
print("#",maximum(w_abs,θ,Interval(0,2*pi)),minimum(w_abs,θ,Interval(0,2*pi)))
# ...ValueError: The argument '6.3 + 0.e-10*I' is not comparable.

ver2.2 代ゼミ 様 複素数平面のθで

・R x R → R 
・実部x虚部 → 実数 
・複素数平面のconjugateとcancelとθで。sin2θを使っていません。勉強中。
 maximum関数、minimum関数で。

# ver2.2 代ゼミ 様 複素数平面のθで
from sympy import *
var('z,w',complex=true)
var('θ'  ,real=true)
R=2
z=R*(cos(θ)+I*sin(θ))
w=z-I/z                                                #;print(w)
w=cancel(w)
w_numer=(numer(w)*conjugate(denom(w))).simplify()      #;print(w_numer)
w_denom=(denom(w)*conjugate(denom(w))).simplify()      #;print(w_denom)
w_abs  =sqrt(re(w_numer)**2+im(w_numer)**2)/w_denom    #;print(w_abs)
print("#",maximum(w_abs,θ,Interval(0,2*pi)),minimum(w_abs,θ,Interval(0,2*pi)))
plot(w_abs,(θ,0,2*pi))
# 5/2 3/2

・matplotlibで
111.png

ver2.3 代ゼミ様 複素数平面の三角不等式で

# ver2.3 代ゼミ様 複素数平面の三角不等式で 
勉強中ChatGPT先生に聞いて
(省略)

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

(テンプレート)

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

ver0.1 ver1.1

・次は私には、難しい。
https://qiita.com/mrrclb48z/items/9ae08175f7e6df5da3e7
https://qiita.com/mrrclb48z/items/55369e77c253389d337e

ver0.2 ver1.2

ver0.3 ver1.3

ver0.4 ver1.4

本投稿を含めて複素数平面 3部作

https://qiita.com/mrrclb48z/items/53217e7e6c0f2222dd6e
https://qiita.com/mrrclb48z/items/90aea6a68504466c320f#ver03-%E8%A4%87%E7%B4%A0%E6%95%B0%E5%B9%B3%E9%9D%A2-%E8%A7%A3%E6%B3%953

copilot先生へ

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

(テンプレート)
https://qiita.com/mrrclb48z/items/b6351b48e47bcf6265c0

出題範囲(単元)

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

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?