How to solve $Ax = b$ for $x$ using MATLAB?
Here, $A$ and $b$ are $2 \times 2$ and $2 \times 1$ matrices, respectively.
How to solve $Ax = b$ for $x$ using MATLAB?
Here, $A$ and $b$ are $2 \times 2$ and $2 \times 1$ matrices, respectively.
On
In Matlab the general matrix equation $Ax = b$ can be solved by the Matlab commmand x = A\b; but that solver doesn't use Gaussian elimination. However it's a good way to check your answer. But here's a link to a numerical methods text that uses matlab. Page 72 introduces Gaussian Elimination and on p.74 or 75 there's code in there that you can just copy and paste into a function in matlab. Should work out. But you should just try writing how you would do the solving by hand, and then think about how you would program each step of that, your method should be nearly identical to the one from the book.
At least two ways:
An efficient way, using the backslash operator:
An understandable way using the inverse operator:
Remarks :
1) one could wonder why the first way has been "invented". It is based on an underlying powerful operator that is Singular Value Decomposition.
2) In order to prove the superiority of the first way, consider the following test program using for $A$ a so-called badly conditionned matrix, i.e., a $10 \times 10$ Cauchy matrix (https://fr.mathworks.com/help/matlab/ref/gallery.html#f84-1019317):
giving the result:
where we see how different $A*x_2$ is from $B$, whereas $A*x_1$ remains close to $B$...