Solve the system of three equations and three unknowns

1 view (last 30 days)
Hannah Mohebi
Hannah Mohebi on 1 Jul 2022
Edited: John D'Errico on 1 Jul 2022
I have three equations, my variables are x,y,z and my constants (A,B,C,E) are matrices with on row and 61200 columns. I want to solve these equations.
for i=1:61200

Answers (2)

John D'Errico
John D'Errico on 1 Jul 2022
Edited: John D'Errico on 1 Jul 2022
The answer is actually pretty easy. First, you need to understand that those who are answering your question do not seem to appreciate the linear algebra of the problem. That is, EVERY one of these equations is of the form
M*[x,y,z] = [0;0;0]
This is called a homogeneous linear system of equations. Homogenous means the problem has a zero right hand side, so NO constant terms. If the matrix M is not singular, then there exists ONLY one solution, it is the vector [0;0;0]. No other solution exists. Again, that is linear algebra 101.
If the matrix is singular, then there will be infinitely many solutions. Here are your equations:
We can write the problem in matrix form as:
M = [A(i), B(i), 1;
C(i), 1, D(i);
1, 1, E(i)];
A problem is, for completely general, random A,B,C,D,E. this matrix will usually not be singular. And therefore, your solution will ALWAYS be the unique one of all zeros.
A = randn(1,61200);
B = randn(1,61200);
C = randn(1,61200);
D = randn(1,61200);
E = randn(1,61200);
Now, for example, with i = 1, we might have:
M = [A(i), B(i), 1;
C(i), 1, D(i);
1, 1, E(i)];
M =
0.53767 1.7782 1
-0.19115 1 0.5921
1 1 0.1066
ans =
And, since M has full rank (thus 3) no solution can exist besides the all zero solution.
I would point out that in your comments, you keep getting the zero solution.
So no matter what you THINK the solution should be, this is the best you can do. If you wanted a solution that comes as close as possible to solving all of those equations, then the SVD will give it to you. This:
[U,S,V] = svd(M)
U =
-0.79619 -0.17052 -0.58052
-0.39493 -0.58041 0.71215
-0.45837 0.79627 0.39478
S =
2.6402 0 0
0 0.92575 0
0 0 0.14854
V =
-0.30716 0.88094 -0.35999
-0.85945 -0.094357 0.50243
-0.40864 -0.46372 -0.78611
You will need the column vector of V that corresponds to the SMALLEST singular value of M. As we can see, the smallest singular value here is relatively small compared to the others, so that means you will not do too badly here.
xyz = V(:,3)
xyz =
ans =
Remember that we wanted the result to be all zeros. This is the best we can possibly do, in a least squares sense, for THIS PARTICULAR matrix M, so that set of numbers I chose for A,B,C,D,E.
So you might do this:
xyz = zeros(3,61200); % preallocating the array for speed
for i=1:61200
M = [A(i), B(i), 1; C(i), 1, D(i); 1, 1, E(i)];
[U,S,V] = svd(M);
xyz(:,i) = V(:,3);
The result for this loop will be the set of vectors [x;y;z] as the columns of xyz that solve the problem in a least squares sense, minimizing the errors of those three equations to whatever extent is possible.

Star Strider
Star Strider on 1 Jul 2022
Solve the system symbolically, then plug in the various values for x, y, and z to get values for A, C, and E
syms A B C D E x y z
Eq1 = A*x+B*y+z==0
Eq1 = 
Eq2 = C*x+y+D*z==0
Eq2 = 
Eq3 = x+y+E*z==0
Eq3 = 
[A,B,C,D,E] = solve([Eq1;Eq2;Eq3],[A,B,C,D,E])
A = 
B = 
C = 
D = 
E = 
John D'Errico
John D'Errico on 1 Jul 2022
Star, you are not focusing on the real issue. Do you understand this is a problem of the form:
M*[x;y;z] = [0;0;0]
You are trying to just do algebra, and hoping that something that makes sense will come out.
This is a homogeneous linear system of equations. THE ONLY solution is all zeros. Read the comment from Hannah.
" I ran the code ,but x,y,z are obtained zero."
If a non-trivial solution exists, then there are infinitely many non-trivial solutions. That can only happen if the matrix M I wrote is singular. But from the comment, it is clear the matrices formed are NOT singular. You cannot solve that system if the matrix is not singular and get anything other than al zeros. Don't just throw algebra at it without thinking.

Sign in to comment.




Community Treasure Hunt

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

Start Hunting!

Translated by