# How to neatly or properly display the answers for simultaneous equations?

2 views (last 30 days)
Obed James on 7 May 2021
Commented: Steven Lord on 7 May 2021
Anyone who knows what they are doing can look at the answer and decipher the answers for this. But i can't help but feel like there's a better way, that even a primary school child with experience with matrices can look and understand these are the answers for these specific variables.
A = [2 3 5; 3 4 7; 1 1 1];
B = [5;10;13];
ANS = inv(A)*B
Steven Lord on 7 May 2021
Instead of computing the inverse and multiplying (which may have been the main way you were taught to solve a system of equations) I recommend using the backslash operator \ to solve the system.
format longg
A = [2 3 5; 3 4 7; 1 1 1];
B = [5; 10; 13];
x = A\B
x = 3×1
18 3.00000000000001 -8
% check
allElementsShouldBeSmall = A*x-B
allElementsShouldBeSmall = 3×1
7.105427357601e-15 0 1.77635683940025e-15
I'd say residuals on the order of 1e-15 counts as small for most purposes.

John D'Errico on 7 May 2021
Edited: John D'Errico on 7 May 2021
You may want to learn how to use the symbolic toolbox, which can display answers in a form you may want.
A = [2 3 5; 3 4 7; 1 1 1];
B = [5;10;13];
syms x y z
[x,y,z] = solve(A*[x;y;z] == B,x,y,z)
x =
18
y =
3
z =
But the fact is, most problems are not 3x3 matrices when you get into the real world. What may seem easy to read for 3 variables is no longer easy to read when you have hundreds, or worse, tens of thousands of unknowns.
Once you learn to use matrices and vectors, that vector of results IS the easy way to look at and USE the results. This is not a question about teaching a child to use the tool, but merely getting the experience with using the language and learning to solve problems.
Obed James on 7 May 2021
Yeah this is for experience, you don't have to burst my bubble man. I really appreciate your help with this. Thanks