How can I solve a system of linear equations in Excel?

e.James picture e.James · Feb 12, 2010 · Viewed 32.4k times · Source

I have a system of 22 linear equations (exactly 22 equations and 22 unknowns) which are dynamically generated in an Excel spreadsheet. Is there a way to have Excel solve the system and produce a value for each of the unknown variables?

Another SO question has a lot of good information about the algorithms used to solve such equations. Cramer's rule in particular looks promising, but I'm not sure how to implement it in Excel.

Any help is appreciated!

Answer

Peter picture Peter · Feb 12, 2010

This page gives the following simple method:

  1. Enter the coefficient matrix in an nxn range.

  2. Enter in the vector of constants in a n-tall column. Select a blank n-tall column. It is important that you not have only one cell selected.

  3. Type, =MMULT(MINVERSE(coefficients_matrix_range), constants_vector_range) in the formula text box and press [CTRL][SHIFT][ENTER]. It is important that you not simply press [ENTER].

This should work adequately, since you only have a small system (22x22). While, ideally, you wouldn't invert the matrix directly, it shouldn't matter in this case.

You definitely don't want Cramer's rule. Due to its fairly poor numerical properties, it's more of theoretical than practical interest.