1.MATH347 Homework 1

Topic: Linear combinations, measuring vectors
Post date: May 17, 2024
Due date: May 21, 2024

1.1.Background

This homework is meant as a tutorial on matrix computations, in particular:

1.2.Theoretical questions

1.2.1.Vector addition and scaling

Problem

Consider n gray-scale images of size p×q pixels, where the brightness value of pixel at position (i,j), 1ip, 1jq is 0bij(l)<2R+1, 1ln, R+.

  1. Represent the images as column vectors 𝒂k of a matrix 𝑨=[ 𝒂1 𝒂n ]=[akl]. What is the matrix size?

  2. Construct a composite image 𝒃 obtained by taking fractions 0xl1 of image l, 1ln, xl[0,1].

Answer

1.2.2.Norms in Em

Problem

Verify whether for a1,a2>0, f:2+ defined by

f(𝒙)=a1x12+a2x22,

is a norm in E2.

Answer

1.2.3.Norms in Em

Problem

Verify whether for a1,a2>0, f:2+ defined by

f(𝒙)=a1x12-a2x22

is a norm in E2.

Answer

1.2.4.Inner product in Em

Problem

Verify whether for a1>0,a2>0, s:2×2 defined by

s(𝒙,𝒚)=a1x1y1+a2x2y2,

is a scalar product in E2.

Answer

1.2.5.Inner product in Em

Problem

Verify whether for a1,a2>0, s:2×2 defined by

s(𝒙,𝒚)=a1x1y1-a2x2y2,

is a scalar product in E2.

Answer

1.2.6.Matrix-matrix products

Problem

Verify that the “row-over-columns” matrix multiplication rule is equivalent to columns of matrix-vector multiplications, i.e., for 𝑨m×n, 𝑩n×p, 𝑪m×p

𝑨𝑩=[ a11 a12 a1n a21 a22 a2n am1 am2 amn ][ b11 b12 b1p b21 b22 b2p bn1 bn2 bnp ]=𝑨[ 𝒃1 𝒃2 𝒃p ]=[ 𝑨𝒃1 𝑨𝒃2 𝑨𝒃p ]

Answer

1.2.7.

Linear mapping representation

Problem

Determine the matrix 𝑪 of the linear mapping 𝒉:22 representing rotation of a vector by angle θ followed by reflection across the x2-axis. Let 𝑨,𝑩 denote the matrices of the mappings 𝒇,𝒈 corresponding to: (1) reflection by angle θ; (2) reflection across the x2-axis. Verify that 𝒉=𝒈𝒇 corresponds to 𝑪=𝑩𝑨. Does 𝑪=𝑨𝑩?

Answer

1.2.8.

Linear mapping composition

Problem

Construct the rotation matrices 𝑨,𝑩,𝑪 for rotation by angles θ,φ,θ+φ. Verify 𝑪=𝑩𝑨, and the trigonometric identities for sine and cosine of sums of angles. Does 𝑪=𝑨𝑩? Compare your answer to previous case.

Answer

1.2.9.

Block matrix operations

Problem

Identify repeated blocks in the matrices 𝑨,𝑩 and carry out the mutiplication in Julia: (1) componentwise; (2) by blocks. Compare the two results.

𝑪=𝑨𝑩T=[ 2 1 0 3 3 2 3 0 0 3 2 1 3 0 3 2 ][ 2 3 1 1 1 2 2 1 1 2 2 3 1 1 1 2 ]T

Answer

1.2.10.

Block matrix operations

Problem

Carry out the following block matrix multiplication

𝑨=𝑼𝚺𝑽T=[ 𝒖1 𝒖2 𝒖m ][ σ1 0 0 0 σ2 0 0 0 σn 0 0 0 0 0 0 ][ 𝒗1 𝒗2 𝒗n ]T.

Answer

1.3.Linear functionals and mappings in analysis of EEG data

Electroencephalograms (EEGs) are recordings of the electric potential on cranium skin. Research on brain activity uses EEGs to determine specific activity patterns in the brain. For example, epileptic seizures have a distinctive EEG signature. EEG data can be loaded from the course data directory. As is typically the case in data analysis, an additional package is required to read in the particular data format; in this case the data is given in Matlab .mat format. This need only be done once.

import Pkg; Pkg.add("MAT");

Updating registry at ‘~/.julia/registries/General.toml‘

Resolving package versions…

No Changes to ‘~/.julia/environments/v1.10/Project.toml‘

No Changes to ‘~/.julia/environments/v1.10/Manifest.toml‘

Load EEG data using the Julia package to read Matlab files. There are n=32 electrode recordings at m=30504 moments of time. A common first step in working with data is centering and scaling values to a standard range.

using MAT
DataFileName = homedir()*"/courses/MATH347DS/data/eeg/eeg.mat";
DataFile = matopen(DataFileName,"r");
dict = read(DataFile,"EEG");
data = dict["data"]';
m,n=size(data)

[ 30504 32 ] (1)

mx=findmax(data[:,4:28])[1]; mn=findmin(data[:,4:28])[1];
d = 2*(data .- mn)/(mx-mn) .- 1;
clf();
for j=1:n
 plot(d[:,j].+(j-1)*2)
end
xlabel("time"); ylabel("voltage"); title("EEG data");
cd(homedir()*"/courses/MATH347DS/homework/hw01");
savefig("H01Fig01.eps");

Figure 1. Electrode voltage time history in EEG

clf();
for j=1:4
 plot(d[1000:1500,j].+(j-1)*2)
end
xlabel("time"); ylabel("voltage"); title("EEG data portion"); grid("on");
savefig("H01Fig02.eps");

Figure 2. Detail of recordings from first four electrodes.

1.3.1.Functional relationships in the data (functions)

Over some time subinterval, can the data from a sensor be expressed as a function of data from another sensor?

1.3.2.Data magnitude (norm)

Partition sensor data into time subintervals. Over each subinterval, evaluate the p-norm of centered data, for p=1,2,3, p. Plot the p-norms over the entire time history.

1.3.3.Orthogonality of sensor data (inner product)

Over some time interval, determine the angle between sensor data. Is sensor data orthogonal? Plot the angle between sensor data over the entire time history.

1.3.4.Linear relationships in the data (linear mapping)

Can data from a sensor be expressed as a linear combination of other sensors?