Hi there,

I'm trying to solve 2 nonlinear equations in 2 unknowns using the BB
package.

The first part of my program solves 3 ODEs using the deSolve package. This
part works. The output is used as parameter values in the functions I need
to solve.

The second part is to solve 2 equations in 2 unknowns. This does not work. I
get the error message "unexpected end of input". So what inputs am I missing
here? As I understand it the arguments I have excluded from dfsane(), such
as control, are set to default?

parameters <- c(K_vv    =     0.0047,
                K_rv    =    -0.0268,
                K_rr    =    0.3384,
                theta_v    =    107.4039,
                theta_r =    5.68,
                Sigma_rv=    0.0436,
                Sigma_rr=    0.1145,
                lambda_v=    0,
                lambda_r=    -0.0764
                )
state <- c(b_1 = 0,
            b_2 = 0,
            a = 0)
Kristian <- function(t, state, parameters){
    with(as.list(c(state, parameters)),{
        db_1 =
-((K_vv+lambda_v)*b_1+(K_rv+Sigma_rv*lambda_v+Sigma_rr*lambda_r)*b_2+0.5*(b_1)^2+Sigma_rv*b_1*b_2+0.5*((Sigma_rv)^2+(Sigma_rr)^2)*(b_2)^2
)
        db_2 = -K_rr*b_2+1
        da = K_vv*theta_v*b_1+(K_rv*theta_v+K_rr*theta_r)*b_2
        })
        }
times <- seq(0, 10, by = 0.5)
library(deSolve)
out <- ode(y = state, times = times, func = Kristian, parms = parameters)
# constructing output as a matrix
outmat <- as.matrix(out)
library(BB) #loading BB package
Bo <- function(x, s){
f <- rep(NA, length(x))
f[1] <- (1-exp(outmat[4,4]-outmat[4,3]*x[1]-outmat[4,2]*x[2]))/
( exp(-outmat[1,4]-outmat[1,3]*x[1]-outmat[1,2]*x[2])
+ exp(-outmat[2,4]-outmat[2,3]*x[1]-outmat[2,2]*x[2])
+ exp(-outmat[3,4]-outmat[3,3]*x[1]-outmat[3,2]*x[2])
+ exp(-outmat[4,4]-outmat[4,3]*x[1]-outmat[4,2]*x[2]))-s[1]

f[2] <-(1-exp(-outmat[20,4]-outmat(20,3)*x[1]-outmat[20,2]*x[2]))/
( exp(-outmat[1,4]-outmat[1,3]*x[1]-outmat[1,2]*x[2])
+ exp(-outmat[2,4]-outmat[2,3]*x[1]-outmat[2,2]*x[2])
+ exp(-outmat[3,4]-outmat[3,3]*x[1]-outmat[3,2]*x[2])
+ exp(-outmat[4,4]-outmat[4,3]*x[1]-outmat[4,2]*x[2])
+ exp(-outmat[5,4]-outmat[5,3]*x[1]-outmat[5,2]*x[2])
+ exp(-outmat[5,4]-outmat[5,3]*x[1]-outmat[5,2]*x[2])
+ exp(-outmat[6,4]-outmat[6,3]*x[1]-outmat[6,2]*x[2])
+ exp(-outmat[7,4]-outmat[7,3]*x[1]-outmat[7,2]*x[2])
+ exp(-outmat[8,4]-outmat[8,3]*x[1]-outmat[8,2]*x[2])
+ exp(-outmat[9,4]-outmat[9,3]*x[1]-outmat[9,2]*x[2])
+ exp(-outmat[10,4]-outmat[10,3]*x[1]-outmat[10,2]*x[2])
+ exp(-outmat[11,4]-outmat[11,3]*x[1]-outmat[11,2]*x[2])
+ exp(-outmat[12,4]-outmat[12,3]*x[1]-outmat[12,2]*x[2])
+ exp(-outmat[13,4]-outmat[13,3]*x[1]-outmat[13,2]*x[2])
+ exp(-outmat[14,4]-outmat[14,3]*x[1]-outmat[14,2]*x[2])
+ exp(-outmat[15,4]-outmat[15,3]*x[1]-outmat[15,2]*x[2])
+ exp(-outmat[16,4]-outmat[16,3]*x[1]-outmat[16,2]*x[2])
+ exp(-outmat[17,4]-outmat[17,3]*x[1]-outmat[17,2]*x[2])
+ exp(-outmat[18,4]-outmat[18,3]*x[1]-outmat[18,2]*x[2])
+ exp(-outmat[19,4]-outmat[19,3]*x[1]-outmat[19,2]*x[2])
+ exp(-outmat[20,4]-outmat[20,3]*x[1]-outmat[20,2]*x[2])) -s[2]
f
s <- c(0.03, 0.045)
p<-c(0.5, 0.5)
ans <- dfsane(par=p, fn=Bo, s=s)
ans$par

Any help will be much appreciated!

Thank you,

Kristian Lind

	[[alternative HTML version deleted]]

