I'm new to Matlab. I was trying to perform optimisation on "8w+7x+15y+12z=0" but I got this error.
Not enough input arguments.
Error in sec2_4>@(w,x,y,z)(8*w)+(7*x)+(15*y)+(12*z)
Error in fmincon (line 536)
initVals.f = feval(funfcn{3},X,varargin{:});
Error in sec2_4 (line 20)
fmincon(f,x0,A,b,Aeq,beq,lb,ub)
Caused by:
Failure in initial objective function evaluation. FMINCON
cannot continue.
The following is my code. I'm not sure is this because I got more than 2 parameters. Is it that I need to get a contour plot and assign better x0? But I don't think fcontour works for my equation.
f = @(w,x,y,z) (8*w)+(7*x)+(15*y)+(12*z);
Aeq = [1,1,1,1];
beq = [140];
lb = [0,0,0,0];
ub = [140,285,90,85];
A = [-1,-1,0,0;1,1,0,0];
b = [-80;40];
x0 = [140,285,90,85];
fmincon(f,x0,A,b,Aeq,beq,lb,ub)

 채택된 답변

Star Strider
Star Strider 2017년 10월 7일
The optimisation routines accept a vector of parameters, so you need to write your function in that context.
Try this:
% % % b(1) = w, b(2) = x, b(3) = y, b(4) = z
f = @(b) (8*b(1))+(7*b(2))+(15*b(3))+(12*b(4));
Aeq = [1,1,1,1];
beq = [140];
lb = [0,0,0,0];
ub = [140,285,90,85];
A = [-1,-1,0,0;1,1,0,0];
b = [-80;40];
x0 = [140,285,90,85];
B = fmincon(f,x0,A,b,Aeq,beq,lb,ub); % Return Optimised Parameters

댓글 수: 2

That works but now it says:
Solver stopped prematurely.
fmincon stopped because it exceeded the function evaluation limit,
options.MaxFunctionEvaluations = 3000 (the default value).
So I thought if I need to use fcontour but then it says
Warning: Error updating FunctionContour.
Index exceeds matrix dimensions.
That simply means that the fmincon solver did not find what it considered the ‘optimum’ in the number of function evaluations allotted to it. you can certainly increase the function evaluation limit in an ‘options’ structure, but I doubt it would significantly improve the outcome.
I do not understand your wanting to use a contour plot. Your function has four parameters, and a contour plot will allow you to evaluate one variable (possibly a parameter in the context of the current problem) as a function of two others.

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

추가 답변 (0개)

카테고리

도움말 센터 및 File Exchange에서 Problem-Based Optimization Setup에 대해 자세히 알아보기

질문:

2017년 10월 7일

댓글:

2017년 10월 7일

Community Treasure Hunt

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

Start Hunting!

Translated by