error in fmincon problem
이전 댓글 표시
Hello!
I have to solve a system of non linear equalities and inequalities. First I used fsolve, but it only works with non linear equalities. So I found that to include also inequalities I should use fmincon.
My system depends on the unknown vector "a" (what I want to find out by solving the system) and a matrix "X" of random variables that I would like to generate in advance, and fix, so that the system is solved only with respect to the vector "a".
Now maybe I have a little bit of confusion about the objective function that I should indicate to fmincon. I mean I want to solve a system, so should the objective function be the system itself?
The main script is the following "Main Program"
X = binornd(5,0.6,5,2);
a0 = 100*randn(14,1);
opts = optimset('Algorithm','interior-point','Display','off');
x = fmincon(minconstr,a0,[],[],[],[],[],[],[],opts)
---------------------------------------------------------------------
where "minconstr" should be the objective function, therefore my system of non linear equalities and inequalities, is it correct? Here I use "global X" to try to fix the matrix X generated in the previous script. Am I right?
function [c, ceq]=minconstr(a)
global X;
b=[1;1;1;1;1;1;1;0;0;0;0;0;0;0;0];
ceq=confun(a);
c=[-a(5)-b(1);-a(6)-b(1);-a(4)+a(5)-b(2);-a(4)+a(6)-b(2);-a(3)+a(4)-b(3);
-a(2)+a(3)-b(4);-a(1)+a(2)-b(5);-a(7)-b(8);-a(8)-b(9);-a(9)-b(10);
-a(10)-b(11);-a(11)-b(12);-a(12)-b(13);-a(13)-b(14);-a(14)-b(15)
];% Linear inequalities
--------------------------------------------------------------
where "confun" is a function that creates the vector of all the non linear equalities of my system. Here again I use "global X" to try to fix the matrix X generated in the previous script. The code of this function is quite long, but it is something like
function F = confun(a)
global X;
...
....
...
% Nonlinear equality constraints
F = [dY(1);
dc(1); dc(2); dc(3); dc(4); dLambda;
dmi(1);dmi(2);
dmi2(1);dmi2(2);dmi2(3)];
------------------------------------------------------------------------
If I run my "Main Program" script, the error says
??? Input argument "a" is undefined.
Error in ==> minconstr at 7
ceq=confun(a);
Error in ==> MainProgram at 9
x = fmincon(minconstr,a0,[],[],[],[],[],[],[],opts)
"a" should be the unknown of my system of which I already provided an initial guess "a0". Does anyone know where could it be the problem?
Thank you all!
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Linear Least Squares에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!