I have a system of three unknown, let's say x
, y
, z
. I want to solve the following nonlinear system:
f1(x,y,z) = 0
f2(x,y,z) = 0
Since I have 3 unknown, but 2 equations, I want to result to have say z
maximized.
And there are the three constraints:
x > 0
y > 0
z > 0
How can I solve this problem? To summarize:
- I have 3 unknowns
- I have 2 equality equations, and 3 constraints
- I want 1 of the unknowns to be as large as possible
Edit
This is what I have done so far with the fmincon
:
% objective function
% Want to minimize the function 1/z (so maximize the variable)
function f = objFun(arg)
x = arg(1);
y = arg(2);
z = arg(3);
f = 1/z;
end
% My two nonlinear equalities f1, f2
function [c, ceq] = NLPart(arg, someInput)
% dont want to get into the detail of the equation since it is
% very long, but at the end:
x = arg(1);
y = arg(2);
z = arg(3);
c = 0;
% The equations below are dummy. they are just some nonlinear combination of the three
ceq(1) = x*y*z;
ceq(2) = x/y + z^2;
end
Then in MATLAB, I ran the following:
system = @ (arg) NLPart(arg, [1 2 3]);
obj = @ (arg) objFun(arg);
fmincon(obj, init_state, [], [], [], [], [0 0 0], [], system);
This gave me the following error:
Error using svd Input to SVD must not contain NaN or Inf.
Error in pinv (line 29) [U,S,V] = svd(A,0);
Error in qpsub (line 463) projSD = pinv(projH)*(-Zgf);
Error in nlconst (line 618) [SD,lambda,exitflagqp,outputqp,howqp,ACTIND] ...
Error in fmincon (line 794) [X,FVAL,LAMBDA,EXITFLAG,OUTPUT,GRAD,HESSIAN]=...
BTW, my objective 1/z
, I want it to equal to zero (by maximizing z
). I don't know if I have written this right
linprog
? mathworks.com/help/optim/ug/linprog.html . Also, placing your systems here would be awesome as we can recreate your problem and can solve it. BTW, I answered a couple of your questions in the past, but you haven't accepted any answers.... not pushing, but I'm just curious if I have helped you at all. – rayryeng