Loading content...
In linear algebra, different bases provide alternative ways to represent vectors in a vector space. A change of basis matrix (also called a transition matrix) allows us to convert the coordinate representation of a vector from one basis to another.
Consider a 3-dimensional real vector space R³. Given two different bases B and C for this space, any vector v can be expressed using coordinates relative to either basis. The change of basis matrix P from basis B to basis C transforms coordinates expressed in B to their equivalent representation in C.
Mathematical Foundation: If the bases are given as matrices where each row represents a basis vector, then:
The change of basis matrix P from B to C is computed as:
$$P = C^{-1} \cdot B$$
This matrix has the property that for any vector v: $$[v]_C = P \cdot [v]_B$$
where [v]_B denotes the coordinate vector of v with respect to basis B, and [v]_C denotes the coordinate vector with respect to basis C.
Your Task: Write a Python function that takes two 3×3 matrices representing bases B and C (where each row is a basis vector), and returns the 3×3 change of basis matrix P that transforms coordinates from basis B to basis C. Round each entry of the resulting matrix to 4 decimal places.
B = [[1.0, 0.0, 0.0], [0.0, 1.0, 0.0], [0.0, 0.0, 1.0]]
C = [[1.0, 2.3, 3.0], [4.4, 25.0, 6.0], [7.4, 8.0, 9.0]][[-0.6772, -0.0126, 0.2342], [-0.0184, 0.0505, -0.0275], [0.5732, -0.0345, -0.0569]]Here, basis B is the standard basis (identity matrix), and C is a custom basis.
When B is the standard basis, the change of basis matrix P = C⁻¹ · B simplifies to C⁻¹.
Computing the inverse of C using matrix inversion techniques (such as Gaussian elimination or the adjugate method), we get the result matrix P.
Each entry is rounded to 4 decimal places as required.
B = [[1.0, 0.0, 0.0], [0.0, 1.0, 0.0], [0.0, 0.0, 1.0]]
C = [[2.0, 1.0, 0.0], [0.0, 2.0, 1.0], [0.0, 0.0, 2.0]][[0.5, -0.25, 0.125], [0.0, 0.5, -0.25], [0.0, 0.0, 0.5]]Basis B is again the standard basis, and C is an upper triangular matrix.
For upper triangular matrices, the inverse is also upper triangular and can be computed efficiently.
The resulting transition matrix P = C⁻¹ transforms standard coordinates to coordinates in basis C.
B = [[1.0, 1.0, 0.0], [1.0, 0.0, 1.0], [0.0, 1.0, 1.0]]
C = [[2.0, 0.0, 1.0], [1.0, 3.0, 0.0], [0.0, 1.0, 2.0]][[0.5385, 0.2308, -0.1538], [0.1538, -0.0769, 0.3846], [-0.0769, 0.5385, 0.3077]]This example involves two non-standard bases B and C.
First, we compute C⁻¹ using matrix inversion. Then, we multiply C⁻¹ by B to get the change of basis matrix P.
The result P = C⁻¹ · B correctly transforms coordinates from basis B to basis C, with all entries rounded to 4 decimal places.
Constraints