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

조회 수: 3 (최근 30일)
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

채택된 답변

Walter Roberson
Walter Roberson 2017년 3월 2일
Yes, you just need a minor change: fun=@(x)F1(x)./F2(x)

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

태그

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by