How can I solve a system of linear equations in Excel
-
01-10-2019 - |
Question
I am having some trouble finding a solution for a system of equations using excel.
The system is of the form Ax=b
, with A
a matrix and x
and b
vectors. Obviously, the goal is to find x.
The system does not necessarily have the same number of equations and unknowns. An exact solution is not always possible. Therefor I want to find the best approximation, possibly using least squares.
Are there standard methods in Excel to do that?
If not, can someone provide me with a macro that does that or explain how I can write my own?
Thanks
Solution
Check the LINEST()
function.
OTHER TIPS
You can use the pseudoinverse and Excel's matrix functions. Suppose there is a named range _A
containing your matrix, and another named range _b
containing your vector, then you can select an appropriately shaped set of cells and enter the formula:
=MMULT((MINVERSE(MMULT(TRANSPOSE(_A); _A))); MMULT(TRANSPOSE(_A); _b))
Remember to press Control-Shift-Enter to enter this formula as it is an array formula. It will appear with braces around it when you select the cells.