Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Find matrix satisfying conditions

I'm looking to solve the following problem in MATLAB, but don't know which command to use.

Find a matrix B, s.t. A * B = I and 0 <= B*a <= b

Where A and B are matrices and a and b are vectors. I is the identity matrix.

Any idea what to use? fsolve didn't work and I don't know how to formulate this in linprog.

Example:

A = [1 0 -1; 0 1 1];
a = [8; 6];
b = [15; 10; 10];

Solution using cvx:

cvx_begin
variable B(3,2)
min (B)
subject to
    A*B == diag(ones(2,1));
    0 <= B*a;
    b >= B*a;
cvx_end
like image 402
Sniep Avatar asked Dec 14 '25 16:12

Sniep


1 Answers

In order to solve those problem with linprog you have to list:

  • The equalities
  • The unequalities

So we have six unknowns:

B = [x1 x2
     x3 x4
     x5 x6]

The unequalities are:

enter image description here

and

enter image description here

In the format supported by linprog (A*x <= b) that give us:

A = [8  6  0  0  0  0
     0  0  8  6  0  0
     8  6  0  0  8  6
    -8 -6  0  0  0  0
     0  0 -8 -6  0  0
     0  0  0  0 -8 -6];

b = [15 10 10 0 0 0]

noticed that in order to transform the >=0 in <=0 have multiplied both side by -1.

The equalities are:

enter image description here

In the format supported by linprog (Aeq*x == beq) that give us:

Aeq = [1  0  0  0 -1  0
       0  1  0  0  0 -1
       0  0  1  0  1  0
       0  0  0  1  0  1]

beq = [1 0 0 1]

We can consider that all the variable have the same "weight", our objective function can be defined by f = [1 1 1 1 1 1]. But it will also work (and will provide another solution) if you change those weights. You can see this as the shape of your 6D space where some dimension can be compressed or stretched out (but not bended). For example f = [1 0.25 1 1 -1 1/2] is also an option...

f = [1 1 1 1 1 1] %which correspond to [x1 x2 x3 x4 x5 x6]

s = linprog(f, A,b,Aeq,beq,-10,10) %solve the problem with arbitrary lower and upper boundary.

One possible result:

s = [ 10
     -12 
      9
      13 
      9 
     -12]

Which give:

B = [10 -12
     9   13
     9   -12]

Automation for larger problem:

% B Matrix size
s1 = 3;
s2 = 2;

% Variable
A  = [1 0 -1; 0 1 1];
B  = sym('X', [s1 s2])
ax = [8; 6];
bx = [15; 10; 10];

% Convert linear equations to matrix form
[Aeq,beq] = equationsToMatrix(A*B == eye(s2))
[A1,b1]   = equationsToMatrix(B*ax == bx)
[A2,b2]   = equationsToMatrix(-B*ax == 0)

% Solve the problem
%      (      f      ,          A            ,            b           ,       Aeq  ,      beq  ,  lb,ub)
linprog(ones(s1*s2,1),[double(A1);double(A2)], [double(b1);double(b2)], double(Aeq),double(beq), -10,10)
like image 55
obchardon Avatar answered Dec 18 '25 03:12

obchardon



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!