My problem is probably common, but I don't know how to adapt the answer to this problem
I have a function F with two parameters (a,b) and I have to find the maximum of this function.
For now, I do that :
optimization_of_F<-function(a,b){
solution=c(0,0,0) #initialization
a=seq(0, 5, by=0.1)
b=seq(0.1, 5, by =0.1)
for (d in a){
for (k in b){
if ( F(d, k) > solution[1] ) {
solution[1]= F(d,k)
solution[2]= d
solution[3]= k
}
}
}
return(solution)
}
But this way is too long and I'd like to optimize it. How can I do that ?
Try this, where F
is your function, c(0,0)
an initial guess, c=2
and d=pi/3
are fixed parameters fed to F
,
optim(c(0,0), F, c=2, d=pi/3)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With