program ex071 c c This program gives the inverse function c tanh^{-1}(x) c by solving the equation, y = tanh(x) for given y values. implicit real*8 (a-h,o-z) c c Statement function f(x)= y - tanh(x) df(x)= - 1.0d0/(cosh(x))**2 c eps = 1.0d-10 ! 数値解の誤差 nmax = 100 dy = 1.0d0/nmax ! y のきざみ幅 x = 0.0d0 c do m = 0,nmax-1 ! y = 1 を避ける y = m*dy ! さまざまな y について調べる。 c x = 0.0d0 n1 = 1 do n=1,1000 fx = f(x) n1 = n if(abs(fx).lt.eps) goto 20 dx = -fx/df(x) ! Newton 法 x = x + dx enddo c 20 continue write(*,100) y, x, n1 ! 最終的な答えを書く end do c stop 100 format(2(1x,f15.7),1x,i4) end