times = seq(0,20,0.5)
  pars = c(0.2,0.2,3)
  names(pars) = c('a','b','c')
  x0 = c(-1,1)
  names(x0) = c('V','R')
  fhn = make.fhn()
  y = lsoda(x0,times,fhn$fn.ode,pars)
  y = y[,2:3]
 w=rnorm(41,.05)
  z=rnorm(41,.05)
  g=y+w
  assign("y", lsoda(x0,times,fhn$fn.ode,pars)
  )
  y=y[,2:3]
  knots = seq(0,20,0.2)
  norder = 3
  nbasis = length(knots) + norder - 2
  range = c(0,20)
  bbasis = create.bspline.basis(range=range, nbasis=nbasis, norder=norder,
  breaks=knots)
 fd.data = array(data,c(nrow(data),1,ncol(data)))

 
 
 m2<- cbind(.29, 1:41)
  m3=m2[,1]
  m4<-rbind(m3,m3)
   m6<- cbind(.29, 1:82)
   m7<-as.array(m6,dim=c(41,2))
  
  m8<-cbind(.29,1:41)
   m9<-as.array(m8,dim=c(41,2))
 data<-y+m9
 fd.data = array(data,c(nrow(data),1,ncol(data)))
  fd.data = array(data,c(nrow(data),1,ncol(data)))
 varnames=c("V","R")

 DEfd = Data2fd(fd.data, times, bbasis,
  fdnames=list(NULL,NULL,varnames) )
 

 coefs = DEfd$coefs
  colnames(coefs) = varnames
  control=list()
  control$trace = 0
  control$maxit = 1000
  control$maxtry = 10
  control$reltol = 1e-6
  control$meth = "BFGS"
  control.in = control
  control.in$reltol = 1e-12
  control.in$print.level = 0
  control.in$iterlim = 1000
  control.out = control
  control.out$trace = 2
  lambda = c(10000,10000)
  res0 = Profile.LS(fhn,data,times,pars,coefs=coefs,basisvals=bbasis,
  lambda=lambda,in.meth='nlminb',out.meth='ProfileGN',
  control.in=control.in,control.out=control.out)

res1 = Profile.LS(fhn$fn, data, times, pars=spars, coefs=coefs,
 lambda=lambda, in.meth='nlminb', out.meth='nls',
 control.in=control.in, control.out=control.out)

 spars=c(0.3,0.1,2)
 res1 = Profile.LS(fhn$fn, data, times, pars=spars, coefs=coefs,
 lambda=lambda, in.meth='nlminb', out.meth='nls',
 control.in=control.in, control.out=control.out)

 profile.obj = LS.setup(pars=pars, fn=fhn, basisvals=bbasis,
 lambda=10000, times=times, fd.obj=DEfd)
 lik = profile.obj$lik
 proc = profile.obj$proc
 qpts = knots
 qwts = rep(1/length(knots),length(knots))
 qwts = qwts %*% t(lambda)
 weights = array(1,dim(data))
 likmore = make.id()
 likmore$weights = weights
 lik = make.SSElik()
 lik$more = likmore
 lik$bvals = eval.basis(times,bbasis)
 procmore = make.fhn()
 procmore$weights = qwts
 procmore$qpts = qpts
 procmore$names = varnames
 parnames=c("a","b","c")
 procmore$parnames = parnames

 procmore$parnames = parnames
 proc = make.SSEproc()
 proc$more = procmore
 proc$bvals = list(bvals = eval.basis(procmore$qpts,bbasis,0),
 dbvals = eval.basis(procmore$qpts,bbasis,1))
 spars = c(0.3,0.1,2)
 res0 = inneropt(coefs, times=times, data=data, lik=lik, proc=proc,
 pars=spars, in.meth='nlminb', control.in=control.out)

ncoefs = res0$coefs
 res1 = outeropt(data=data, times=times, pars=pars, coefs=coefs,
 lik=lik, proc=proc, in.meth="nlminb", out.meth="nls",
 control.in=control.in, control.out=control.out)
res2 = outeropt(data=data, times=times, pars=pars, coefs=coefs,
 lik=lik, proc=proc,
 in.meth="nlminb", out.meth="nlminb",
 control.in=control.in, control.out=control.out)

 Profile.covariance(pars=res1$pars, times=times, data=data,
 coefs=res1$coefs, lik=lik, proc=proc)
 
 data2 = array(0,c(41,2,2))
 dim(y)
 dim(w)
 m2<- cbind(.29, 1:41)
  m3=m2[,1]
  m4<-rbind(m3,m3)
   m6<- cbind(.29, 1:82)
   m7<-as.array(m6,dim=c(41,2))
  
  m8<-cbind(.29,1:41)
   m9<-as.array(m8,dim=c(41,2))
 data<-y+m9
 data2[,1,] = y+m9
 data2[,2,] = y+m9
 

 fd.data2 = array(data2,c(nrow(data2),2,ncol(data2)))


 DEfd2 = Data2fd(fd.data2, times, bbasis,
 fdnames=list(NULL,NULL,varnames))

rownames(data2)<-rownames(data2, do.NULL = FALSE, prefix = "Obs.")
  colnames(data2)[1:2]=c("one","two")
 varnames(data2)[1:2]=c("V","R")







dimnames(data2)=list(rownames(data2),colnames(data2),varnames)
 data2a<-as.array(data2,dim=c(41,2,2),dimnames=dimnames(data2))




 profile2.obj=LS.setup(pars,DEfd2$coefs,fhn,basisvals=bbasis,lambda,fd.obj=NULL,
 more=NULL,data=data2,weights=NULL,times=times,quadrature=NULL,eps=1e-6,
 posproc=FALSE,poslik=FALSE,discrete=FALSE,names=NULL,sparse=FALSE)

 assign("proc", profile2.obj$proc)
 qpts = knots
 qwts = rep(1/length(knots),length(knots))
 qwts = qwts %*% t(lambda)
 weights = array(1,dim(data2))
 likmore = make.id()
 likmore$weights = weights
 lik = make.SSElik()
 lik$more = likmore
 lik$bvals = eval.basis(times,bbasis)
 procmore = make.fhn()
 procmore$weights = qwts
 procmore$qpts = qpts
 procmore$names = varnames
 procmore$parnames = parnames
 proc = make.SSEproc()
 proc$more = procmore
 proc$bvals = list(bvals = eval.basis(procmore$qpts,bbasis,0),
 dbvals = eval.basis(procmore$qpts,bbasis,1))
 res10 = inneropt(coefs=DEfd2$coefs, times=times, data=data2, lik=lik, proc=proc,
 pars=spars, in.meth='nlminb', control.in=control.out)
