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

조회 수: 6 (최근 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.
  댓글 수: 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 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