Introduction
A system of linear equations (or linear system) is a collection of one or more linear equations involving the same variables. By representing these systems as matrices, you can leverage NumPy’s efficient computational tools to find solutions quickly.This guide demonstrates how to model systems of linear equations as matrices, solve them using NumPy, and understand the relationship between matrix properties and solution existence.
Setup
Load the required packages:Understanding Linear Systems
What is a Linear System?
Consider this example system: This system has:- Two equations
- Two unknown variables: and
- A solution is values for and that satisfy both equations simultaneously
A linear system is singular if it has no unique solution (either no solution or infinitely many solutions). Otherwise, it is non-singular.
Matrix Representation
Full System Matrix
The complete system can be represented as an augmented matrix: Each row represents one equation. Columns represent:- Column 1: Coefficients of
- Column 2: Coefficients of
- Column 3: Constants (right side of equations)
Coefficient Matrix and Vector
We can separate the system into:- Coefficient Matrix A
- Constant Vector b
Creating Matrices in NumPy
Checking Dimensions
Solving Linear Systems
Using np.linalg.solve()
NumPy’s linear algebra package provides a fast, reliable solver:
Verification
Substitute and into the original equations:- Equation 1: ✓
- Equation 2: ✓
Matrix Determinants
Understanding Determinants
For square matrices, the determinant is a scalar value that characterizes matrix properties.A linear system has one unique solution if and only if the coefficient matrix has a non-zero determinant.
Calculating Determinants
Visualizing Linear Systems
Creating the Augmented Matrix
Use
.reshape((2, 1)) to convert the 1-D vector into a 2-D column vector before stacking.Extracting Rows
Plotting the Solution
Each equation represents a line in 2D space. The solution is their intersection point:Systems with No Solutions
Example: Parallel Lines
Consider the system:Attempting to Solve
Visualization
Systems with Infinite Solutions
Example: Coincident Lines
Modify the system to make the equations proportional:Understanding the Solution
The second equation is just times the first equation. This reduces to: The solution is: where can be any real number.When equations are proportional, they represent the same line. Every point on this line is a solution, resulting in infinitely many solutions.
Plotting
Summary Table
| Determinant | System Type | Number of Solutions | Geometric Interpretation |
|---|---|---|---|
| Non-singular | One unique solution | Lines intersect at one point | |
| Singular | Zero or infinite | Lines are parallel or coincident |
Key Takeaways
Matrix Representation
Matrix Representation
- Systems can be represented as coefficient matrix and constant vector
- Augmented matrix combines both:
- Each row is an equation, each column is a variable’s coefficients
Solving Systems
Solving Systems
- Use
np.linalg.solve(A, b)for systems with unique solutions - Always check the determinant first
- Verify solutions by substitution
Determinant Significance
Determinant Significance
- Non-zero determinant: unique solution exists
- Zero determinant: no solution or infinitely many solutions
- Calculate with
np.linalg.det(A)
Geometric Interpretation
Geometric Interpretation
- Each equation is a line (in 2D) or hyperplane (in higher dimensions)
- Solution is the intersection of all lines/planes
- Parallel lines = no solution
- Coincident lines = infinite solutions
Next: Matrix Operations
Master matrix multiplication and essential operations for linear algebra
