Jessica
Jessica

Reputation: 2415

Computationally solve system of equations with singular matrix

I have this singular matrix (I'll call it A)

-3a          1         0    0
 3a    -2a - 1         2    0
 0      2a        -a-b-2    3
 0           0     a+b     -3

I'm trying to solve Ax = 0, such that the sum of the elements in x is 1. I want to solve for x in terms of a and b. I know how to do this by hand (use Gaussian elimination to write all components in terms of the fourth component, then set the fourth component so that the solution is normalized). But is there any way to do this computationally? I would be fine doing it in either Python, Mathematica, or R. (Or MATLAB but I don't think there's a way to do it in MATLAB.)

The code I was copying did it by adding a fifth row to the matrix,

1    1    1    1

and then using QR decomposition to find a least-squares solution. However, I don't think I can do this because I don't have values for a and b, and I want to solve for the solution in terms of a and b.

Upvotes: 4

Views: 1723

Answers (2)

Bill
Bill

Reputation: 3957

In[1]:= A = {{-3a,1,0,0}, {3a,-2a-1,2,0}, {0,2a,-a-b-2,3}, {0,0,a+b,-3}};
x = {p, q, r, s};
sol = Reduce[A.x==0 && p+q+r+s==1 && Det[A]==0, x, Backsubstitution->True]

Out[3]= (1+3*a+3*a^2+a^3+a^2*b) != 0 && 
p == 1/(1+3*a+3*a^2+a^3+a^2*b) && 
q == (3*a)/(1+3*a+3*a^2+a^3+a^2*b) && 
r == (3*a^2)/(1+3*a+3*a^2+a^3+a^2*b) && 
s == (a^3 + a^2*b)/(1+3*a+3*a^2+a^3+a^2*b)

In[4]:= x=x/.ToRules[sol (* Watch out for that denominator!!! *)];
Simplify[A.x]

Out[5]= {0, 0, 0, 0}

In[6]:= Simplify[Total[x]]

Out[6]= 1

Upvotes: 2

Theja Tulabandhula
Theja Tulabandhula

Reputation: 921

There is a way to do it in MATLAB but I couldn't progress further than this.

syms a b
A = [ -3*a,         1,           0,  0;
       3*a, - 2*a - 1,           2,  0;
         0,       2*a, - a - b - 2,  3;
         0,         0,       a + b, -3;
         1,         1,           1,  1];
x = solve(A,[0 0 0 0 1]')

I got the following warnings:

Warning: 20 equations in 2 variables. 
Warning: Explicit solution could not be found. 

Upvotes: 0

Related Questions