Pfaff, Bernhard
2002-Dec-19 16:57 UTC
[R] optimize() - Solution is invariant with respect to parame ters - l exical function
Solved the problem myself, thks, for any efforts taken! -----Original Message----- From: Pfaff, Bernhard [mailto:Bernhard.Pfaff at drkw.com] Sent: 19 December 2002 14:58 To: r-help at stat.math.ethz.ch Subject: [R] optimize() - Solution is invariant with respect to parameters - l exical function Dear R-List member, suppose the following single valued functional form is given: y = f(x | a, b, c). Now I want to use optimize to solve for the value of x that satisfy the function. As an example, pls. take a look at the following: input <- function(y,a,b,c){ f <- function(x){ (a + b*x + c*x^2 - y)^2 } optimize(f,c(1,100)) } # # example with x=2 # input(y=7,a=1,b=1,c=1) temp1 <- input(y=7,a=1,b=1,c=1)$minimum temp1 1 + temp1 + temp1^2 # # example with x=3 # input(y=14,a=2,b=1,c=1) temp2 <- input(y=14,a=2,b=1,c=1)$minimum temp2 2 + temp2 + temp2^2 So far, so good(?). Now, the function that I am interesting in has the following form: bsiv.opt <- function(op, s, x, r, tt){ iv <- function(sig){ (s*pnorm((log(s/x)+(r+0.5*sig^2)*tt)/sig*sqrt(tt)) - x*exp(-r*tt)*pnorm((log(s/x)+(r+0.5*sig^2)*(tt))/sig*sqrt(tt)-sig*sqrt(tt)) - op)^2 } optimize(iv,c(1,100)) } # # example 1 # bsiv.opt(4.75, 93.625, 90, 0.0512, 22) # # example 2 # bsiv.opt(4.75, 93.625, 80, 0.0512, 22) My question is as follows: although, I have altered one parameter value, the solved minimum value does not change; how come? What have I made wrong? Any hints and pointers are most welcome. Rgds, Bernhard ---------------------------------------------------------------------- If you have received this e-mail in error or wish to read our e-mail disclaimer statement and monitoring policy, please refer to http://www.drkw.com/disc/email/ or contact the sender. ---------------------------------------------------------------------- ______________________________________________ R-help at stat.math.ethz.ch mailing list http://www.stat.math.ethz.ch/mailman/listinfo/r-help ---------------------------------------------------------------------- If you have received this e-mail in error or wish to read our e-mail disclaimer statement and monitoring policy, please refer to http://www.drkw.com/disc/email/ or contact the sender. ----------------------------------------------------------------------