mml-book / mml-book.github.io

Companion webpage to the book "Mathematics For Machine Learning"
12.91k stars 2.39k forks source link

Example 2.23 (Basis Change) #697

Closed FarzadMinooei closed 1 year ago

FarzadMinooei commented 2 years ago

Hi,

Regarding example 2.23 (version 2021-07-29, chapter 2, page 53-54), here is a complete answer using python:

As question said, we have:

import numpy as np A = np.array([[2, 1], [1, 2]]) B = np.array([[1, 1], [1, -1]])

So the transformation matrix based on equation 2.105, would be:

T_inv A_phi S = T_inv @ A @ S

S = B T_inv = np.linalg.inv(B)

which results in:

array([[3., 0.], [0., 1.]])

farid-moradi commented 1 year ago

We have two bases: B and E. B is the new basic and E is the old one (R2 canonical).

We can think about the transformation algorithmically as follows:

1- First, we take every vector from B to E using the matrix B. For example, (1, 0) with respect to B becomes (1, 1) with respect to E. Both of these coordinates represent the same vector.

2- Next, we perform the transformation using the matrix A. Now every vector of B is transformed, but their coordinate representations are based on E.

3- Finally, we return to the world of our new basic B. For this, we need to have the reverse matrix of A. The resulting matrix transforms the vector space in the same way A does but with respect to our new basis.

Your solution didn't perform the last step.