Rev 71179 | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed
c-----------------------------------------------------------------------cc R : A Computer Language for Statistical Data Analysisc Copyright (C) 1977 B.D. Ripleyc Copyright (C) 1999 the R Core Teamcc This program is free software; you can redistribute it and/or modifyc it under the terms of the GNU General Public License as published byc the Free Software Foundation; either version 2 of the License, orc (at your option) any later version.cc This program is distributed in the hope that it will be useful,c but WITHOUT ANY WARRANTY; without even the implied warranty ofc MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See thec GNU General Public License for more details.cc You should have received a copy of the GNU General Public Licensec along with this program; if not, a copy is available atc https://www.R-project.org/Licenses/cc-----------------------------------------------------------------------csubroutine eureka (lr,r,g,f,var,a)cc solves Toeplitz matrix equation toep(r)f=g(1+.)c by Levinson's algorithmc a is a workspace of size lr, the numberc of equationscinteger lr,l,l1,l2,i,j,kdouble precision r(lr+1), g(lr+1), f(lr,lr), a(lr), var(lr)double precision v, d, q, holdv = r(1)d = r(2)a(1) = 1.0d0f(1,1) = g(2)/vq = f(1,1)*r(2)var(1) = (1 - f(1,1)*f(1,1))*r(1)if (lr .eq. 1) returndo 60 l = 2, lra(l) = -d/vif (l .gt. 2) thenl1 = (l - 2)/2l2 = l1 + 1do 10 j = 2, l2hold = a(j)k = l - j + 1a(j) = a(j) + a(l)*a(k)a(k) = a(k) + a(l)*hold10 continueif (2*l1 .ne. l - 2) a(l2+1) = a(l2+1)*(1.0d0 + a(l))endifv = v + a(l)*df(l,l) = (g(l+1) - q)/vdo 40 j = 1, l-1f(l,j) = f(l-1, j) + f(l, l)*a(l-j+1)40 continuec estimate the innovations variancevar(l) = var(l-1) * (1 - f(l,l)*f(l,l))if (l .eq. lr) returnd = 0.0d0q = 0.0d0do 50 i = 1, lk = l-i+2d = d + a(i)*r(k)q = q + f(l,i)*r(k)50 continue60 continuereturnend