% Solving Linear Algebraic Systems
% Linear systems arise frequently in numerical problem solving, either because the problem is initially set up as a system of algebraic equations or because something like a differential equation is reduced to a system of algebraic equations through one or more approximations.
% Suppose we want to solve the following set of equations for r, s, and t.
% \begin{array}{l}
% r+2s+t=0\\
% 3r+s+t=1\\
% r+3s+2t=5
% \end{array}
% To do this using the matrix method, you write the system as follows:
% \begin{array}{l}
% \textrm{Ax}=b\\
% A=\left\lbrack \begin{array}{ccc}
% 1 & 2 & 1\\
% 3 & 1 & 1\\
% 1 & 3 & 2
% \end{array}\right\rbrack \\
% b=\left\lbrack \begin{array}{c}
% 0\\
% 1\\
% 5
% \end{array}\right\rbrack \\
% x=\left\lbrack \begin{array}{c}
% r\\
% s\\
% t
% \end{array}\right\rbrack
% \end{array}
% Now the system is easily solved as:
% x=A^{-1} b
% To solve this in Matlab, we could use the built-in function to calculate the inverse of A and multiply by b, but this is inefficient. It's better, computationally, to use the "\" operator os follows:

A=[1 2 1; 3 1 1; 1 3 2]
B=[0; 1; 5]
solution=A\B

% We can check the solution as follows:

A*solution

% © James Blanchard, University of Wisconsin-Madison, blanchard@engr.wisc.edu