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

3 次查看(过去 30 天)
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.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Get Started with MATLAB 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by