2014-수학-B형-홀수-18

문제

2014-수학-B형-홀수-18

풀이

%%capture
!pip install --upgrade sympy watermark
from sympy import *
an = symbols('an')

각 자연수 \(n\)에 대하여, \(a_n\)\(\tan(a_n) = n, \, a_n\in ((n-1)\pi, (n-1/2)\pi)\)을 만족시킨다.

def a_val(n):
  expr = sin(an)-n*cos(an)
  return nsolve(expr, an, N((n-3/4)*pi))

\(a_n = (n-1/2)\pi-\epsilon_n\)라 쓰면, \(\epsilon_n>0\)은 0으로 수렴하는 감소수열임을 관찰할 수 있다.

for n in range(1,20):
  print(N((n-1/2)*pi)-a_val(n))
0.785398163397448
0.463647609000806
0.321750554396642
0.244978663126863
0.197395559849880
0.165148677414628
0.141897054604165
0.124354994546763
0.110657221173895
0.0996686524911610
0.0906598872007436
0.0831412318884404
0.0767718912697788
0.0713074647852849
0.0665681637758269
0.0624188099959611
0.0587558227157245
0.0554985052457226
0.0525830616109388
a_val(1000)/1000
\[\displaystyle 3.14002085726333\]

##scipy를 이용한 수치해

import numpy as np
from scipy.optimize import fsolve

def a_val2(n):
  eqn = lambda x : np.tan(x) - n
  x_initial_guess = (n-3/4)*np.pi
  x_solution = fsolve(eqn, x_initial_guess)
  return x_solution[0]
a_val2(1000)/1000
/home/cftnt/venvs/gichul/lib/python3.8/site-packages/scipy/optimize/minpack.py:175: RuntimeWarning: The iteration is not making good progress, as measured by the 
  improvement from the last five Jacobian evaluations.
  warnings.warn(msg, RuntimeWarning)
3.0771496834848304

##실행환경

%load_ext watermark
%watermark -m -v --iversions
Python implementation: CPython
Python version       : 3.8.6
IPython version      : 7.19.0

Compiler    : GCC 7.5.0
OS          : Linux
Release     : 4.14.117-grsec-grsec+
Machine     : x86_64
Processor   : x86_64
CPU cores   : 8
Architecture: 64bit

sympy: 1.7.1
numpy: 1.19.4