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

6 Ansichten (letzte 30 Tage)
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
  1 Kommentar
Steven Lord
Steven Lord am 7 Mai 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.

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

John D'Errico
John D'Errico am 7 Mai 2021
Bearbeitet: John D'Errico am 7 Mai 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.
  1 Kommentar
Obed James
Obed James am 7 Mai 2021
Yeah this is for experience, you don't have to burst my bubble man. I really appreciate your help with this. Thanks

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Get Started with MATLAB finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by