how to solve system of linear equations with unorganized unknowns?

20 views (last 30 days)
hi everybody. I have a system of n equations n unknowns and there are two forms of this system. in the first form the system of equations is in the form of A*X=Y. in the second form the system of equations is in the form of A*X=B*Y. A and B are the matrix of constant factors. some of the unknowns are in the matrix X and the others are in the matrix Y(X and Y are columns). so the problem is that unknowns are not in one matrix so they are unorganized. i can define unknowns as zero. if there is another way to define unknowns, please let me know. so how can i solve these systems? please guide me how to solve these systems and how to define unknowns? there are several ways to organize unknowns and put them in just one matrix but i want to know if there is any way to solve the system without organizing unknowns. if all the unknowns were in one matrix then it would be easy to solve the system with linsolve in matlab.

Accepted Answer

John D'Errico
John D'Errico on 23 Mar 2015
Edited: John D'Errico on 23 Mar 2015
Just move all of the unknowns to the left hand side.
A*X - B*Y = 0
Think of it like
[A,-B]*[X;Y] = 0
Any knowns in that set among the a and y variables, you move to the right hand side and sum them up. They are all constants. I fail to see the problem. How would you solve it using pencil and paper? (Answer: Exactly the same way.)
My guess is you are getting confused because you think you have TWO sets of unknowns, mixed in with knowns, in both X and Y. In fact, you can do the entire procedure in only several lines of code, fully vectorized. TRY IT! You might surprise yourself. (Take a shot and try it. REALLY. See how it goes. If you still get confused, then just comment here and I'll show you how.)
  5 Comments
John D'Errico
John D'Errico on 23 Mar 2015
In the example I just gave, here is my solution...
AB = [A,-B];
XY(unknowns) = AB(:,unknowns)\(-AB(:,knowns)*XY(knowns))
XY =
1
14.625
-2.5
4.875
7
10
(As I said, two lines of code.)
As a test to confirm this is indeed a solution...
A*XY(1:3) - B*XY(4:6)
ans =
0
0
0
In the other case, where you have
A*X = Y
with some elements of both X and Y unknown, this is IDENTICAl to the above more general problem, except that here we have B=eye(numel(Y)). No penalty functions are needed. That is simply a bad idea when the solution is so trivial. Honestly, this really is not hard to do. I call it trivial, but I've been writing the linear algebra code for things like this for years now. No matter what, it is still easy.

Sign in to comment.

More Answers (1)

Omidreza Ghafarinejad
Omidreza Ghafarinejad on 24 Mar 2015
thanks. it seems that it works. i tested your method on one of my previous problems and the answers was the same except one(the right answer was 31.3936 but the answer obtained from this method was 31.3963). maybe this little error is not important but i will test this method on other problems too. again thanks.
  2 Comments
Omidreza Ghafarinejad
Omidreza Ghafarinejad on 24 Mar 2015
I tested your method for AX=Y. i have not tested for the second form yet. but i will do it as soon as possible. I should mention that i have the exact answers from Ansys. the two sets of answers from ansys and penalty method are exactly the same. but one of the answers of your method has error. I should mention that I have 35 answers that only one of them is not exactly the same. the others are correct.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!