qfun.ord <- function(gamma)
{
        qarr <- array(0, dim = c(3, 4, 4))
        theta <- exp(gamma)
        qarr[1, 1, 1] <-  - theta[1]
        qarr[1, 1, 2] <- theta[1]
        qarr[1, 2, 1] <- theta[2]
        qarr[1, 2, 2] <-  - theta[2] - theta[3] - theta[4]
        qarr[1, 2, 3] <- theta[3]
        qarr[1, 2, 4] <- theta[4]
        qarr[1, 3, 2] <- theta[5]
        qarr[1, 3, 3] <-  - theta[5] - theta[6]
        qarr[1, 3, 4] <- theta[6]
        qarr[2,  ,  ] <- qarr[1,  ,  ]
        qarr[3,  ,  ] <- qarr[1,  ,  ]
        qarr[2, 1, 2] <- qarr[2, 1, 2] * exp(gamma[7])
        qarr[2, 1, 1] <- qarr[2, 1, 1] * exp(gamma[7])
        qarr[3, 1, 1] <- qarr[3, 1, 1] * exp(2 * gamma[7])
        qarr[3, 1, 2] <- qarr[3, 1, 2] * exp(2 * gamma[7])
        return(qarr)
}

gamma.ord<-c(-5,-5.7,-6.5,-9.6,-5.4,-6.61,0.5)

qderiv.ord <- function(gamma)
{
        rmat <- array(0, c(7, 3, 4, 4))
        theta <- exp(gamma)
        rmat[1, 1, 1, 1] <- ( - theta[1])
        rmat[1, 1, 1, 2] <- theta[1]
        rmat[1, 2, 1, 1] <- ( - theta[1] * exp(gamma[7]))
        rmat[1, 2, 1, 2] <- theta[1] * exp(gamma[7])
        rmat[1, 3, 1, 1] <- ( - theta[1] * exp(2 * gamma[7]))
        rmat[1, 3, 1, 2] <- theta[1] * exp(2 * gamma[7])
        rmat[2,  , 2, 1] <- theta[2]
        rmat[2,  , 2, 2] <- ( - theta[2])
        rmat[3,  , 2, 2] <- ( - theta[3])
        rmat[3,  , 2, 3] <- theta[3]
        rmat[4,  , 2, 4] <- theta[4]
        rmat[4,  , 2, 2] <- ( - theta[4])
        rmat[5,  , 3, 3] <- ( - theta[5])
        rmat[5,  , 3, 2] <- theta[5]
        rmat[6,  , 3, 4] <- theta[6]
        rmat[6,  , 3, 3] <- ( - theta[6])
        rmat[7, 2, 1, 1] <- ( - theta[1] * exp(gamma[7]))
        rmat[7, 2, 1, 2] <- theta[1] * exp(gamma[7])
        rmat[7, 3, 1, 1] <- (-2 * theta[1] * exp(2 * gamma[7]))
        rmat[7, 3, 1, 2] <- 2 * theta[1] * exp(2 * gamma[7])
        return(rmat)
}

