0
votes

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

1
Did you try using 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
My system is nonlinear so I can't use that! As for the equations, they are quite large, and I need to give quite a bit of background. It should be enough to say that I have a system of 3 unknowns, with 2 equality equations, 3 constraints, and I want one of the unknown to be as large as possible!Kousha
You didn't specify they were non-linear. Here you go: mathworks.com/help/optim/ug/…rayryeng

1 Answers

3
votes

You basically want to do an optimization where your objective function is defined by:

h(x,y,z) = z;

with the following non linear equality constraints:

f1(x,y,z) = 0;
f2(x,y,z) = 0;

And the following lower Bounds:

x > 0, y > 0, z > 0

Yes, you can do this in MATLAB. You should be able to use 'fmincon' in the following syntax:

x = fmincon(fun,x0,[],[],[],[],lb,[],nonlcon)

x0 is a three element vector and the result will also be in the same format which will give you the values for x,y and z. Take a look at the documentation of fmincon for more details: http://www.mathworks.com/help/optim/ug/fmincon.html