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

6 ビュー (過去 30 日間)
Obed James
Obed James 2021 年 5 月 7 日
コメント済み: Steven Lord 2021 年 5 月 7 日
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 件のコメント
Steven Lord
Steven Lord 2021 年 5 月 7 日
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
John D'Errico 2021 年 5 月 7 日
編集済み: John D'Errico 2021 年 5 月 7 日
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 件のコメント
Obed James
Obed James 2021 年 5 月 7 日
Yeah this is for experience, you don't have to burst my bubble man. I really appreciate your help with this. Thanks

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeGet Started with MATLAB についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by