how to solve system of linear equations to fit the set of constraints i have

3 次查看(过去 30 天)

I have a program that need to check for each set of values- bound limits and coupled constraints. But every time i try to run it it may go beyond the limits or the constraints are not satisfied. What modification i can do. The code goes like this:-

function [ gout ] = c(gac,cy)
gout=gac;
%% Uncoupled Constraints 
lbac=[220 260 50 25];                     
ubac=[260 1000 400 600];                      
U=(gac>ubac);
gout(U)=ubac(U);
gout(~U)=gac(~U);
L=(gac<lbac);
gout(L)=lbac(L);
%% Coupled constraints
if gout(2)-gout(3)-gout(4)-20<0 
 [~,I]=max(abs([ gout(3) gout(4) gout(2)]-[ lbac(3) lbac(4) ubac(2)]));
  switch I
      case 1
          gout(3)=gout(2)-gout(4)-20; 
          if (gout(3)>ubac(3) || gout(3)<lbac(3))
            gout(3)=min((gout(2)-gout(4)-20),lbac(3));
          end 
        case 2
            gout(4)=gout(2)-gout(3)-20; %modification related to hc
            if (gout(4)>ubac(4) || gout(3)<lbac(3))
             gout(4)=min((gout(2)-gout(3)-20),lbac(4));
            end 
        case 3 
            gout(2)= gout(2)+(gout(3)+gout(4)-gout(2)); 
             if gout(2)-gout(3)-gout(4)-20<0
                gout(2)=min((gout(3)+gout(4)),ubac(2));
            end 
    end 
end 
gout = ceil(gout);
end

I am getting a gac vector and want to fit in with all the constraints and pass the modified value to other function.

  2 个评论
Walter Roberson
Walter Roberson 2015-12-4
Which linear solver are you using?
If the coupled constraints are linear then you should be able to express them using A and b matrices of one of the linear solvers; if the constraints are not linear then you cannot use a linear solver but you can use fmincon which accepts nonlinear constraints.
John D'Errico
John D'Errico 2015-12-4
I don't think it is a linear solver that is being employed here, and I think lsqlin would not work on this problem.
The linear constraints are applied (or not) as a nonlinear function of the values of the parameters themselves. So this means that LSQLIN (or any tool lie it) is not appropriate. Likewise, fmincon MUST fail at least some of the time, because it cannot handle non-differentiable constraint systems. A piecewise constraint system as this is, is such a problem.
So the only option is a stochastic solver of some ilk. A genetic solver is possible, and naming the variables gac and gout suggests to me that this is what the OP is using.
What I don't know is if the problem as posed even has a feasible solution. That may be the issue here, that no solution exists as it is posed. It may mean simply that the code written implements a perfectly valid set of constraints improperly, i.e., this may be buggy code. Or, it may mean that the starting values chosen are not feasible, and the code is unable to find a valid set from that start point. I don't think we have enough information to know the answer yet.

请先登录,再进行评论。

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Solver Outputs and Iterative Display 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by