Search code examples
pythonmatrixequation-solving

Python Matrix solving {A}[x] = [B] where parts of x and B are known


In python it is possible to solve {A}[x]=[B] where A is a known matrix, B a known vector and x an unknown vector.

But is it possible to solve {A}[x]=[B] if A is a know 3x3 matrix, x = [V1 5 V3] and B = [0 I2 0] ?

Thank you very much for your help.


Solution

  • It's certainly feasible to reduce columns and rows and go down this route but I would rather suggest an alternative approach here. Reformulate your problem as a quadratic problem in 3n unknowns. Use cvxopt to solve it. Essentially you are trying to minimize the 2-norm of the residual r = Ax-b where x and b are vector in n variables. So define

    0 = row_i of A * x - b_i - r_i

    introduce constraints on

    x and b

    e.g. b_1 = 0 x_2 = 0.3*x1 etc.

    and minimize

    sum r_i^2
    

    You could also do something like sum abs(r_i) and introduce another set of n variables and solve a linear problem in 4n dimensions