-1

I have a 2 variable function in R which I want to integrate w.r.t one of them and then optimize it w.r.t the other one. How can I do this?

Hamz Don
  • 1
  • 1
  • Welcome to Stack Overflow. Please provide a [Reproducible Example](http://stackoverflow.com/q/5963269/4752675) of what you are trying to do. In this case, can you provide us with an example function that you would like to integrate? – G5W Apr 14 '17 at 16:04
  • Possible duplicate of [Coding a multiple integral function in R](http://stackoverflow.com/questions/42095957/coding-a-multiple-integral-function-in-r) – tmrlvi Apr 14 '17 at 17:10

1 Answers1

1

You do not provide an example of the sort of function that you would like to integrate and then optimize, so I will use a somewhat arbitrary choice as an example.

f(y) = ∫0y (y-1) x2 dx

You can write this function in R using the integrate function and then use optimize to find a minimum over some specified range.

DefInt = function(y) { integrate(function(x) { (y-1)*x*x },0,y)$value }
optimize(DefInt, c(-2,2))
$minimum
[1] 0.7499972
$objective
[1] -0.03515625
G5W
  • 36,531
  • 10
  • 47
  • 80