Derive the value of a parameter to reach a specific result of a function in R (v.4.2.1)

Viewed 14

I need to find the value of a parameter which make my function produce a specific result.

I write down something like this:

## Defining the function
f = function(a, b, c, x) sqrt(t(c(a, b, c, x)) %*% rho %*% c(a, b, c, x))
## Set di input needed
rho <- matrix(c(1,0.3,0.2,0.4,
                0.3,1,0.1,0.1,
                0.2,0.1,1,0.5,
                0.4,0.1,0.5,1), 
              nrow = 4, ncol = 4)

target <- 10000
## Optimize
output <- optimize(f, c(0, target), tol = 0.0001, a = 1000, b = 1000, c = 1000, maximum = TRUE)

I would like to derive di value of x related to the maximum of my function (the target value).

Thanks,

Ric

0 Answers
Related