[R] Minimizing two non-linear functions with genoud - Trying to minimize or converge near zero

Guillaume Théroux Rancourt Guillaume.Theroux-Rancourt at fsaa.ulaval.ca
Thu Feb 4 21:00:18 CET 2010


Hello R users,

I am trying to minimize two functions with genoud. It is actually one function with two sets of data, each of them having two unknown variables (called Vcmax and gi) which have the same value in each of the function. They are called f.1 and f.2 in the code below.

My objective to minimize the functions in order to get the two variables equal in each of the functions. Furthermore, I have a measured comparison value for each of the function expression, and the results of f.1 and f.2 should be very close or equal to their measured value, so that  measured.1 - f.1 = 0.

I have been able to run genoud with the code below. However, I haven't been able to restrain the values of the difference between the measured and estimated value to 0. I am fairly new at writing R functions and I think there might be something I haven't written that makes the output parameters of genoud not replicable.

I have made several runs of this function and when comparing with the measured value, I got answers between 1 and 12, where it should have been very close to 7.47.

This example has already been solved with the solver Excel add-in and theh result are:
Vcmax = 104.32, gi = 0.11

The values were also estimated using another approach and they are:
Vcmax = 64.48, gi = 0.28


Here is my code. 


######

f=function(x) { 

x = c(0.16,80)
Vcmax = x[2]
gi = x[1]

# First dataset
f.1=function(x){
(-(((Vcmax-0.89189)/gi)+164.6573+272.38*(1+21*10/165.82))+sqrt((((Vcmax-0.89189)/gi)+164.6573+272.38*(1+21*10/165.82))^2-4*(-1/gi)*(0.89189*(164.6573+272.38*(1+21*10/165.82))-Vcmax*(164.6573-(5*21/2.605459)))))/(-2/gi)
}

# Second data set
f.2=function(x){
(-(((Vcmax-0.89189)/gi)+164.3077+272.38*(1+2*10/165.82))+sqrt((((Vcmax-0.89189)/gi)+164.3077+272.38*(1+2*10/165.82))^2-4*(-1/gi)*(0.89189*(164.3077+272.38*(1+2*10/165.82))-Vcmax*(164.3077-(5*2/2.605459)))))/(-2/gi)
}

# Values here are the measured values. f.1 and f.2 should be equal or close to the value on their left.
y.1 = (7.478327 - f.1(x))
y.2 = (12.73134 - f.2(x))

# This should be close to 0.
y = y.1 - y.2

return(y)
}

dom = matrix(c(0,0,200,1.5), 2, 2)

res = genoud(f, nvars=2, max=FALSE,Domains=dom,pop.size=5000,print.level=0)


# In order to test the results to see I the estimated variables make the "test" function = 7.478327 or near.
# This is the same as f.1

test=function(Vcmax, gi){
(-(((Vcmax-0.89189)/gi)+164.6573+272.38*(1+21*10/165.82))+sqrt((((Vcmax-0.89189)/gi)+164.6573+272.38*(1+21*10/165.82))^2-4*(-1/gi)*(0.89189*(164.6573+272.38*(1+21*10/165.82))-Vcmax*(164.6573-(5*21/2.605459)))))/(-2/gi)
}

test(res$par[1],res$par[2])

## End 


Thank you for your help!


Guillaume Théroux Rancourt
Ph.D. candidate --- Plant Biology
Université Laval, Québec, QC, Canada
guillaume.theroux-rancourt.1 at ulaval.ca



More information about the R-help mailing list