MATLAB: How to use fmincon when the objective function is an expression of other functions?.

fmincon

I am trying to minimize a function of two variables (defined over a compact interval [0,1]) using fmincon. However the objective function is really complicated in terms of length. I am trying to avoid writing it entirely by splitting it in shorter expressions. For instance, suppose my objective function is
fun=@(x) (x(1).^2+2)./(sqrt(x(2)+1))
What I am trying to do is to define, say
F1=@(x)(x(1).^2+2)
F2=@(x)(sqrt(x(2)+1))
and then minimize this new objective function fun=@(x)F1./F2
Is it possible to do it?
Thanks in advance
Edoardo

Best Answer

Yes, you just need a minor change: fun=@(x)F1(x)./F2(x)