# Nakafa Framework: LLM
URL: /en/subject/university/bachelor/ai-ds/linear-methods/cramer-rule
Source: https://raw.githubusercontent.com/nakafaai/nakafa.com/refs/heads/main/packages/contents/subject/university/bachelor/ai-ds/linear-methods/cramer-rule/en.mdx
Output docs content for large language models.
---
export const metadata = {
    title: "Cramer's Rule",
    description: "Solve linear systems using determinants with Cramer's rule. Learn complementary matrices, inverse formulas, and step-by-step examples for AI applications.",
    authors: [{ name: "Nabil Akbarazzima Fatih" }],
    date: "07/12/2025",
    subject: "Linear Methods of AI",
};
## Solving Linear Systems
Cramer's rule is a method for solving systems of linear equations using determinants. This method provides a direct way to calculate solutions of linear equation systems when the coefficient matrix is invertible.
This method is very useful for understanding the relationship between determinants and solutions of linear systems, although it is computationally less efficient compared to Gaussian elimination for large systems.
## Complementary Matrix
Before discussing Cramer's rule, we need to understand the concept of **complementary matrix** which forms the basis of this method.
For matrix , the complementary matrix is defined as:
with elements:
Note that the indices in  are swapped (not ).
The complementary matrix  is a matrix consisting of **cofactors** of matrix , but with transposed positions.
### Structure of Complementary Matrix
The complementary matrix has the following structure:
Each element is calculated by taking the determinant of the corresponding submatrix, then given a sign based on the checkerboard pattern .
## Fundamental Properties of Complementary Matrix
One of the most important properties of the complementary matrix is its relationship with the original matrix:
In other words:
This property is very important because it provides a direct relationship between the matrix, its complementary matrix, and its determinant.
## Matrix Inverse Formula
From the fundamental property above, we can derive the **matrix inverse formula** using the complementary matrix.
If matrix  is invertible, then:
However, calculating matrix inverse using this formula is much less efficient compared to Gaussian elimination for large matrices.
### Example for 2×2 Matrix
For matrix :
Its determinant is:
Its complementary matrix is:
So its inverse is:
We can verify that:
## Theorem Statement
Now we can formulate Cramer's rule for solving systems of linear equations.
Let  be an invertible matrix and  be the columns of . For vector , the solution  of the linear equation system  is given by:
for .
To calculate the -th component of solution , we replace the -th column of matrix  with vector , then calculate the determinant of this modified matrix and divide it by the determinant of the original matrix .
## Proof Using Laplace Expansion
The proof of Cramer's rule uses Laplace expansion and properties of the complementary matrix.
For :
based on Laplace expansion with respect to the -th column.
## Application Example
Let's look at a concrete example of applying Cramer's rule:
Since:
matrix  is invertible and the system has a unique solution.
According to Cramer's rule:
Verification shows that .
## Solution Properties for Integer Matrices
If  is an invertible matrix with integer elements and  is a vector with integer elements, then the elements of the inverse  and solution  of the system  are rational numbers with denominator that (if not reduced) equals .
This occurs because determinant calculation only involves addition, subtraction, and multiplication operations, so the determinant of an integer matrix is always an integer. In the inverse formula and Cramer's rule, the only division operation is division by .