How to define an objective function in the fmincon?

조회 수: 10 (최근 30일)
Mingyang Sun
Mingyang Sun 2021년 12월 7일
댓글: Matt J 2021년 12월 7일
I would like to solve a large scale non-convex QCQP problem using fmincon, such that
min_x x.'H*x
s.t. x.'*R*x = 1
Ax<=b
where H and R are positive definite matrices. Because x has dimension of 5000, how can i define the objective function? I tried to pass
obj = @(x)x.'*H*x;
to the fmincon, it won't work.
many thanks
  댓글 수: 1
Matt J
Matt J 2021년 12월 7일
There's nothing obviously incorrect in what you've described. You should attach a .mat file with your H,R,A,b matrices and demonstrate what you've done using the Run button

댓글을 달려면 로그인하십시오.

답변 (1개)

Rik
Rik 2021년 12월 7일
Your objective function should return a scalar. To borrow a term from machine learning: it is a cost function.
One of the often used functions to compute a single cost for a set of observations is the ordinary least squares:
OLS=@(x) sum((fun(x)-target).^2);
  댓글 수: 2
Mingyang Sun
Mingyang Sun 2021년 12월 7일
thank you for your replying, if x is a 5000 x 1 vector, then x.'H*x is a scalar. Because of the dimension of the x, it is impossible to define the objective function using anonymous function such that
@(x) x(1) + x(2) + x(3).....
how can I define the objective function efficiently?
Rik
Rik 2021년 12월 7일
If it already returns a scalar, what is your question?
From the documentation:
fun Function to minimize
Function to minimize, specified as a function handle or function name. fun is a function that accepts a vector or array x and returns a real scalar f, the objective function evaluated at x.
fmincon passes x to your objective function and any nonlinear constraint functions in the shape of the x0 argument. For example, if x0 is a 5-by-3 array, then fmincon passes x to fun as a 5-by-3 array. However, fmincon multiplies linear constraint matrices A or Aeq with x after converting x to the column vector x(:).

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Solver Outputs and Iterative Display에 대해 자세히 알아보기

태그

제품


릴리스

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by