Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.
Matrix solution for a set of linear equations
It can be tedious to solve a set of three or more linear equations. However, the equations can be rewritten in matrix form and solved computationally. Suppose that you want to solve the equations
These equations can be rewritten as
Define the matrices
and
We must solve the following matrix equation
for . If the multiplicative inverse of the matrix is , then the solution is
It is easy to find the solution with numpy as shown below. If the two objects being multiplied are matrices, the multiplication operator (*) performs matrix multiplication. Documentation of the matrix class is available at http://docs.scipy.org/doc/numpy/reference/generated/numpy.matrix.html.
This means that
If the equations to be solved involve physical quantities, you must keep track of units. In that case, it is best to convert all quantities to standard units so that the results will be in standard units. If there is no solution to the equations, the matrix inversion will result in an error.
Alternately, the linear algebra solver in scipy can be used. Documentation is at https://docs.scipy.org/doc/scipy/reference/linalg.html.