Week 3: Exercises#


Exercises – Long Day#

1: Orthonormal Basis (Coordinates). By Hand.#

Question a#

Do the vectors

uu1=(13,23,23),uu2=(23,13,23),uu3=(23,23,13)

constitute an orthonormal basis in R3?

Question b#

Consider the vector xx=[1,2,3]T. Calculate the inner products xx,uuk for k=1,2,3.

Question c#

Let’s denote the basis by β=uu1,uu2,uu3. State the coordinate vector βxx of xx with respect to β. Calculate the norm of both xx and the coordinate vector βxx.

Question d#

Create the 3×3 matrix U=[uu1|uu2|uu3] with uu1,uu2,uu3 as its three columns. Calculate UTxx and compare the result with that from the previous question.

2: Orthonormal Basis (Construction). By Hand.#

Create an orthonormal basis for R3, within which

(22,22,0)

is the first basis vector.

3: Orthonormalization. By Hand.#

Find the solution set to the homogeneous equation

x1+x2+x3=0

and justify that it constitutes a subspace in R3. Find an orthonormal basis for this solution space.

4: Orthogonal Projections#

Let y=(2,1,2)R3 be given. Then the projection of xR3 on the line Y=span{y} is given by:

ProjY(x)=x,yy,yy=x,uu,

where u=y||y||.

Question a#

Let x=(1,2,3)R3. Calculate ProjY(x), ProjY(y) and ProjY(u).

Question b#

As usual, we consider all vectors as column vectors. Now, find the 3×3 matrix P=uuuuT and compute both Px and Py.

5: An Orthonormal Basis for a Subspace of C4#

Question a#

Find an orthonormal basis uu1,uu2 for the subspace Y=span{vv1,vv2} that is spanned by the vectors:

v1 = Matrix([I, 1, 1, 0])
v2 = Matrix([0, I, I, sqrt(2)])

Question b#

Let

xx=[3i32i32i22].

Calculate xx,uu1, xx,uu2 as well as

xx,uu1uu1+xx,uu2uu2.

What does this linear combination give? Does xx belong to the subspace Y?

6: A Python Algorithm#

Question a#

Without running the following code, explain what it does and explain what you expect the output to be. Then run the code in a Jupyter Notebook.

from sympy import *
from dtumathtools import *
init_printing()

x1, x2, x3 = symbols('x1:4', real=True)
eqns = [Eq(1*x1 + 2*x2 + 3*x3, 1), Eq(4*x1 + 5*x2 + 6*x3, 0), Eq(5*x1 + 7*x2 + 8*x3, -1)]
eqns
A, b = linear_eq_to_matrix(eqns,x1,x2,x3)
T = A.row_join(b)  # Augmented matrix

A, b, T

Question b#

We will continue the Jupyter Notebook by adding the following code (as before, do not run it yet). Go through the code by hand (think through the for loops). What T matrix will be the result? Copy-paste the code into an AI tool, such as https://copilot.microsoft.com/ (log in with your DTU account), and ask it to explain the code line by line. Verify the result by running the code in a Jupyter Notebook. Remember that T.shape[0] gives the number of rows in the matrix T.

for col in range(T.shape[0]):
    for row in range(col + 1, T.shape[0]):
        T[row, :] = T[row, :] - T[row, col] / T[col, col] * T[col, :]
    T[col, :] = T[col, :] / T[col, col]

T

Question c#

Write Python code that ensures zeros above the diagonal in the matrix T so that T ends up in reduced row-echelon form.

Note

Do not take into account any divisions by zero (for general T matrices). We will here assume that the computations are possible.

Question d#

What kind of algorithm have be implemented? Test the same algorithm on:

x1, x2, x3, x4 = symbols('x1:5', real=True)
eqns = [Eq(1*x1 + 2*x2 + 3*x3, 1), Eq(4*x1 + 5*x2 + 6*x3, 0), Eq(4*x1 + 5*x2 + 6*x3, 0), Eq(5*x1 + 7*x2 + 8*x3, -1)]
A, b = linear_eq_to_matrix(eqns,x1,x2,x3,x4)
T = A.row_join(b)  # Augmented matrix

7: Orthogonal Polynomials#

This is an exercise from the textbook. You can find help there.

Consider the list α=1,x,x2,x3 of polynomials in P3([1,1]) equipped with the L2 inner product.

Question a#

Argue that α is a list of linearly independent vectors.

Question b#

Apply the Gram-Schmidt procedure on α and show that the procedure yields a normalized version of the Legendre polynomials.


Exercises – Short Day#

1: Matrix Multiplications. By Hand.#

Define

A=[123456784444],xx=[x1x2x3x4]=[1211].

Let aa1,aa2,aa3,aa4 denote the columns in A. Let bb1,bb2,bb3 denote the rows in A. We now calculate Axx in two different ways.

Question a#

Method 1: As a linear combination of the columns. Calculate the linear combination

x1aa1+x2aa2+x3aa3+x4aa4.

Question b#

Method 2: As “dot product” of the rows in A with x. Calculate

[bb1xxbb2xxbb3xx].

Note

Since bbk is a row vector, (bbk)T is a column vector. Hence, the product bbkxx corresponds to the dot product of xx and (bbk)T.

Question c#

Calculate Axx in Sympy and compare with your calculations from the previous questions.

2: A Subspace in C4 and its Orthogonal Compliment#

Let the following vectors be given in C4:

vv1=(1,1,1,1),vv2=(3i,i,i,3i),vv3=(2,0,2,4)andvv4=(43i,2i,i,63i).

A subspace Y in C4 is determined by Y=span{vv1,vv2,vv3,vv4}.

Question a#

v1 = Matrix([1,1,1,1])
v2 = Matrix([3*I,I,I,3*I])
v3 = Matrix([2,0,-2,4])
v4 = Matrix([4-3*I,2-I,-I,6-3*I])

Run the command GramSchmidt([v1,v2,v3,v4], orthonormal=True) in Python. What does Python tell you?

# GramSchmidt([v1, v2, v3, v4], orthonormal = True)   

Question b#

Now show that (vv1,vv2,vv3) constitute a basis for Y, and find the coordinate vector of vv4 with respect to this basis.

Question c#

Provide an orthonormal basis for Y.

Question d#

Determine the coordinate vector of vv4Y with respect to the orthonormal basis for Y.

Question e#

Determine the orthogonal complement Y in C4 to Y.

Question f#

Choose a vector yy in Y and choose a vector xx in Y. Calculate xx, yy and xx+yy. Check that xx2+yy2=xx+yy2.

3: Orthogonal Projection on a Plane#

Let the matrix U=[uu1,uu2] be given by:

U=[33223303322].

Question a#

Show that uu1,uu2 is an orthonormal basis for Y=span{uu1,uu2}.

Question b#

Let P=UUR3×3. As explained in this section of the textbook, this will give us a projection matrix that describes the orthogonal projection xxPxx, R3R3 on the plane Y=span{uu1,uu2}. Verify that P2=P, Puu1=uu1, and Puu2=uu2.

Question c#

Choose a vector xxR3, that does not belong to Y and find its projection projY(xx) af xx down on the plane Y. Illustrate xx, Y and projY(xx) in a plot.

Question d#

Show that xxprojY(xx) belongs to Y.

4: Unitary Matrices#

Let a matrix F be given by:

n = 4
F = 1/sqrt(n) * Matrix(n, n, lambda k,j: exp(-2*pi*I*k*j/n))
F
[1212121212i212i21212121212i212i2]

State whether the following propositions are true or false:

  1. F is unitary

  2. F is invertible

  3. F is orthogonal

  4. F is symmetric

  5. F is Hermitian

  6. The columns in F constitute an orthonormal basis for C4

  7. The columns in F constitute an orthonormal basis for R4

  8. F=F1