Using Matlab Fmincon as a substitute for Excel solver tool

4 ビュー (過去 30 日間)
Ben
Ben 2013 年 10 月 17 日
コメント済み: Matt J 2013 年 10 月 17 日
I'm an amateur Matlab user. I turned to Matlab as the solver in excel restricts how many variables can be used variables. I'm trying to maximise a function subject to constraints using Fmincon. However I'm getting an error when I try to run it.
My code is:
% Objective function m file:
function f = objectivefunction3(x)
f = -FinalAlphas*x'+ x*VCV*x'
% Code to run Fmincon:
[x, fval] = fmincon(@objectivefunction2,x0,A,B)
I get the following error when running it:
Error in objectivefunction3 (line 2)
f = FinalAlphas*x'- x*VCV*x'
Error in fmincon (line 631)
initVals.f = feval(funfcn{3},X,varargin{:});
  1 件のコメント
Matt J
Matt J 2013 年 10 月 17 日
Since your function is a quadratic (and possibly a linear least squares) objective and your constraints are linear, it would be better to use QUADPROG or LSQLIN, rather than FMINCON.

サインインしてコメントする。

回答 (1 件)

Daniel Shub
Daniel Shub 2013 年 10 月 17 日
My guess is your objective function is not valid
% Objective function m file:
function f = objectivefunction3(x)
f = -FinalAlphas*x'+ x*VCV*x'
unless you are using nested functions, FinalAlphas and VCV are not dfined.

カテゴリ

Help Center および File ExchangeLinear Least Squares についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by