問題文
曲線 $y=\log(1+\cos x)$ の $0 \leqq x \leqq \frac{\pi}{2}$ の部分の長さを求めよ。
(2021 京都大学 理系第4問)
$$\log(3+2\sqrt{2})$$
※ この答えは学校側が公表したものではありません。個人が作成した非公式の答えです。
コード
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.animation as ani
import matplotlib.gridspec as gridspec
from matplotlib.colors import ListedColormap

#紙の準備
fig = plt.figure()
fig.canvas.draw()
fig.suptitle("2021京大数学 理系第4問",
             color="0.5",ha="right",x=0.95,y=0.95,zorder=-1)
gs = gridspec.GridSpec(1,10)
ax1 = fig.add_subplot(gs[0,0:3])
ax1.set_xlim(-np.pi/12,7*np.pi/12)
ax1.set_ylim(-0.2,1.0)
ax1.set_xticks([np.pi/2])
ax1.set_xticklabels(["$\\frac{\\pi}{2}$"])
ax1.set_yticks([np.log(2)])
ax1.set_yticklabels(["$\\log2$"])
ax1.spines["left"].set_position(("data",0))
ax1.spines["bottom"].set_position(("data",0))
ax1.spines["left"].set_color("0.5")
ax1.spines["bottom"].set_color("0.5")
ax1.plot(1,0,">",color="0.5",transform=ax1.get_yaxis_transform(),clip_on=False)
ax1.plot(0,1,"^",color="0.5",transform=ax1.get_xaxis_transform(),clip_on=False)
ax1.spines["top"].set_visible(False)
ax1.spines["right"].set_visible(False)
ax1.set_aspect("equal")
ax2 = fig.add_subplot(gs[0,4:])
width = 8
height = 4
ax2.set_xlim(0,width)
ax2.set_ylim(0,height)
ax2.set_aspect("equal")
ax2.axis("off")

#フォント辞書たち
linedic={
"usetex" : True,
"clip_on" : True,
"animated" : True,
"fontsize" : 16,
"verticalalignment" : "baseline",
}
commentdic={
"ha" : "center",
"va" : "center",
"size" : 20,
"color" : "white",
"animated" : True,
"fontfamily": "Meiryo",
}
commentbgdic={
"facecolor" : "black",
"pad" : 300,
}

#台本
comment="""\
曲線 $y=\\log(\\,1+\\cos x\\,)$ の

$(\\,0\\,\\leqq\\,x\\,\\leqq\\,\\frac{\\pi}{2}\\,)$ の部分の長さ

ヲモトメヨ
"""
lines=[
r"= \! \int_0^\frac{\pi}{2} \! \sqrt{1+\left( \frac{dy}{dx} \right)^2} \, dx",
r"= \! \int_0^\frac{\pi}{2} \! \sqrt{1+\left( \frac{-\sin x}{1+\cos x} \right)^2} \, dx",
r"= \! \int_0^\frac{\pi}{2} \! \sqrt{\frac{(1+\cos x)^2 + \sin^2 x}{(1+\cos x)^2}} \, dx",
r"= \! \int_0^\frac{\pi}{2} \! \sqrt{\frac{2 + 2\cos x}{(1+\cos x)^2}} \, dx",
r"= \! \int_0^\frac{\pi}{2} \! \sqrt{\frac{2}{1+\cos x}} \, dx",
r"= \! \int_0^\frac{\pi}{2} \! \sqrt{\frac{1}{\cos^2\frac{x}{2}}} \, dx",
r"= \! \int_0^\frac{\pi}{2} \frac{1}{\cos\frac{x}{2}} \,\, dx",
r"= \! \int_0^\frac{\pi}{2} \frac{\cos\frac{x}{2}}{\cos^2\frac{x}{2}} \,\, dx",
r"= \! \int_0^\frac{\pi}{2} \frac{\cos\frac{x}{2}}{1-\sin^2\frac{x}{2}} \,\, dx",
r"= \! \int_0^\frac{\pi}{2} \! \left(\! \frac{\frac{1}{2}\cos\frac{x}{2}}{1+\sin\frac{x}{2}} \!+\! \frac{\frac{1}{2}\cos\frac{x}{2}}{1-\sin\frac{x}{2}} \right)\! dx",
r"= \!\! \int_0^\frac{\pi}{2} \!\!\left\{\! \frac{(1\!\!+\!\sin\!\frac{x}{2})^{\prime}}{1\!+\!\sin\!\frac{x}{2}} \!-\! \frac{(1\!\!-\!\sin\!\frac{x}{2})^{\prime}}{1\!-\!\sin\!\frac{x}{2}} \!\right\}\! dx",
r"= \!\! \left[ \log\!\left|1\!+\!\sin\!\frac{x}{2}\right| \!-\! \log\!\left|1\!-\!\sin\!\frac{x}{2}\right| \right]_{\!0}^{\!\frac{\pi}{2}}",
r"= \log\!\left|1\!+\!\sin\!\frac{\pi}{4}\right| \!-\! \log\!\left|1\!-\!\sin\!\frac{\pi}{4}\right|",
r"= \log\left|1\!+\!\frac{\sqrt{2}}{2}\,\right| \!-\! \log\left|1\!-\!\frac{\sqrt{2}}{2}\,\right|",
r"= \log\left| \frac{1\!+\!\frac{\sqrt{2}}{2}\,}{1\!-\!\frac{\sqrt{2}}{2}\,} \right|",
r"= \log\left| \frac{2+\!\sqrt{2}\,}{2-\!\sqrt{2}\,} \right|",
r"= \log \frac{(2+\!\sqrt{2}\,)^2}{2}",
r"= \log\,(3+2\sqrt{2}\,)",
]

#定数の準備
base = height/5
delta = 0.1
colors = [(1,1,1,alpha) for alpha in np.arange(0,11)/10]
cmap = ListedColormap(colors)

#非アニメーション部分の描画(曲線と与式)
x = np.linspace(-np.pi/12,7*np.pi/12,121)
y = np.log(1+np.cos(x))
ax1.plot(x,y,color="forestgreen",linestyle="dotted",alpha=0.5)
x = np.linspace(0,np.pi/2,91)
y = np.log(1+np.cos(x))
ax1.plot(x,y,color="forestgreen",linewidth=2)
ax1.text(7*np.pi/12,1.2,"$\\displaystyle y=\\log(1+\\cos x)$",
         usetex=True,ha="right",va="top",fontsize=10)
ax1.text(7*np.pi/12,0.9,"$\\displaystyle \\left[ 0 \\leq x \\leq \\frac{\\pi}{2} \\right]$",
         usetex=True,ha="right",va="top",fontsize=7)
ax2.text(-0.2,base+height/2,"$L$",fontdict=linedic,
         ha="right",clip_on=False,animated=False)

#数式をLATEX変換する関数
def show_line(y,line,alpha=1.0):
    img = []
    line = "$\\displaystyle " + line + "$" 
    text = ax2.text(0,y,line,alpha=alpha,fontdict=linedic)
    img += [text]
    bbox = text.get_window_extent().transformed(ax2.transData.inverted())
    right = bbox.x1
    return img,right

#余韻を残すための関数
def lingering(imgs,frames):
    img = imgs[-1]
    for i in range(frames):
        imgs.append(img)
        
#数式が徐々に現れる関数
def appearing(i,X,Y):
    C = np.zeros(len(X)-1)
    C[2*i+1:2*i+20] = np.arange(0.05,1.00,0.05)
    C[2*i+20:] = 1
    C = np.reshape(C,(len(X)-1,1))
    img = ax2.pcolormesh(X,Y,C,cmap=cmap,zorder=10)
    return img

#最初の1行目を表示する関数
def show_first_line(imgs,line):
    
    i = 0
    while True:
        img,right = show_line(base+height/2,line)
        X,Y = np.mgrid[-2:right+4:delta,height/2:3*height/2:height/2]
        img += [appearing(i,X,Y)]
        imgs.append(img)
        i += 1
        if 2*i+20 > len(X)-1:
            break

#2行目を表示する関数
def show_second_line(imgs,line1,line2):
    
    i = 0
    while True:
        img1,right1 = show_line(base+height/2,line1)
        img2,right2 = show_line(base,line2)
        img = img1 + img2
        X,Y = np.mgrid[-2:right2+4:delta,0:height:height/2]
        img += [appearing(i,X,Y)]
        imgs.append(img)
        i += 1
        if 2*i+20 > len(X)-1:
            break
        
#次の数式へと進む関数
def go_next_line(imgs,line1,line2):

    for i in range(21):
        alpha = max((10-i)/10,0)
        img1,right1 = show_line(base+height/2+height*i/40,line1,alpha)
        img2,right2 = show_line(base+height*i/40,line2)
        img = img1 + img2
        imgs.append(img)

#数式を読み込む関数
def load_script(imgs,lines):
    
    N = len(lines)
    
    show_first_line(imgs,lines[0])
    
    for k in range(N-2):
        show_second_line(imgs,lines[k],lines[k+1])
        go_next_line(imgs,lines[k],lines[k+1])
        
    show_second_line(imgs,lines[N-2],lines[N-1])
    lingering(imgs,50)

#最初のコメントの部分の関数
def interlude(imgs,str_comment):
    
    for k in range(25):
        interlude=fig.text(0.5,0.5,str_comment[:-6],
                           fontdict=commentdic,bbox=commentbgdic)
        imgs.append([interlude])
    
    for i in range(5):
        for k in range(3):
            interlude=fig.text(0.5,0.5,str_comment[:-5+i],
                               fontdict=commentdic,bbox=commentbgdic)
            imgs.append([interlude])
            
    lingering(imgs,25)

#上演
imgs=[]
interlude(imgs,comment)
load_script(imgs,lines)
mov=ani.ArtistAnimation(fig, imgs, 100)
plt.show()
解説になっているのか?甚だギモンな動画
「高校数学のエアポケット」に戻る