Topic: | Math@UNC environment |
Post date: | May 14, 2020 |
Due date: | May 15, 2020 |
This homework is meant as a tutorial on matrix computations, in particular:
vector addition and scaling;
vector norms;
inner products;
matrix-vector products;
matrix-matrix products.
Consider random walks on the real line with unit steps starting from the origin. What is the mean distance and mean squared distance from the origin?
Denote distance by , and the random walk steps as
Denote by the average distance over walks which is the sum of the average displacement in each step
Assuming that both left and right steps are equiprobable, and .
The squared distance is
The average is
Since the average is . The possible values of with equal probability . The average squared distance is
octave] |
m=100; n=500; U=2*(rand(m,n)<0.5)-1; mean(mean(U)) |
ans = -0.0063600
octave] |
function md=meand(m,n) U=2*(rand(m,n)<0.5)-1; md=mean(mean(U)); end |
octave] |
Nmax=1000; md=zeros(50,1); for k=1:50 md(k) = meand(m,100*k); end; |
octave] |
plot(100:100:5000,abs(md),'o') |
octave] |
pwd |
ans = /home/student/courses/MATH547ML
octave] |
mkdir homework |
ans = 1
octave] |
cd homework |
octave] |
pwd |
ans = /home/student/courses/MATH547ML/homework
octave] |
mkdir hw01; |
octave] |
cd hw01 |
octave] |
print -deps hw01fig01.eps |
octave] |
pwd |
ans = /home/student/courses/MATH547ML/homework/hw01
octave] |
ls |
hw01fig01.eps untitled.ofig
![]() |
Figure 1. Experiment on statsitc to evaluate
mean of random walk distance
|
Show that for , defined by
is a norm in .
Let , , or in vector form .
Since does not satisfy scaling property , neither if a norm. However would be.
Show that for , defined by
is not a norm in .
No for
Show that for , defined by
is a scalar product in .
Recall that
is a scalar product. From
and fact that is a scalar product, deduce is also a scalar product.
Show that for , defined by
is not a scalar product in .
From notice that can be negative, hence is not a scalar product.
Find examples of matrices for which , and .
octave] |
A=[2 1; 1 2]; B=[2 0; 0 2]; A*B-B*A |
ans =
0 0
0 0
octave] |
C=[2 1; -1 1]; D=[0 -2; 1 -1]; C*D-D*C |
ans =
-1 -3
-2 1
octave] |
Octave] |
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.
octave] |
load /home/student/courses/MATH547ML/data/eeg/eeg; |
octave] |
data=EEG.data'; [m n]=size(data); disp([m n]); |
30504 32
octave] |
There are sensor recordings with components each. A first common operation is scaling of the data.
octave] |
pdata=data./max(data)+meshgrid(0:n-1,0:m-1); |
octave] |
hold on; for j=1:n plot(pdata(:,j)); end; hold off; |
octave] |
cd /home/student/courses/MATH547ML/homework/hw01 |
octave] |
print -deps eeg.eps; |
GL2PS info: OpenGL feedback buffer
overflow
warning: gl2ps_renderer::draw: retrying with buffer
size: 8.4E+06 B
GL2PS info: OpenGL feedback buffer overflow
warning: gl2ps_renderer::draw: retrying
with buffer size: 1.7E+07 B
octave] |
![]() |
Over some time subinterval can the data from a sensor be expressed as a function of data from another sensor?
octave] |
cd /home/student/courses/MATH547ML/homework/hw01; |
octave] |
[m,n]=size(data); |
octave] |
mt=5000:5005; plot(data(mt,1),data(mt,2),'-o'); print -deps hw01Fig02a.eps |
octave] |
mt=6000:6005; plot(data(mt,1),data(mt,2),'-o'); print -deps hw01Fig02b.eps |
octave] |
mt=7000:7005; plot(data(mt,1),data(mt,2),'-o'); print -deps hw01Fig02c.eps |
octave] |
|
|||
Figure 3. From above figures, sensors 1,2 are
not in a functional relation.
|
Partition sensor data into time subintervals. Over each subinterval, evaluate the -norm of centered data, for , . Plot the -norms over the entire time history.
octave] |
mud=mean(data); |
octave] |
cdata=data-mud; |
octave] |
m1=1000; m2=1100; cdata(m1:m2,:) |
ans =
30504 32
octave] |
function nrmd=normd(m1,m2,d) [m,n]=size(d); nrmd=zeros(4,n); for k=1:n nrmd(1,k)=norm(d(m1:m2,k),1); nrmd(2,k)=norm(d(m1:m2,k),2); nrmd(3,k)=norm(d(m1:m2,k),3); nrmd(4,k)=norm(d(m1:m2,k),Inf); end; end; |
octave] |
tnrm=zeros(100,4,n); for j=1:100 tnrm(j,:,:) = normd(100*j,100*(j+1),cdata); end; |
octave] |
it=1:100; plot(it,tnrm(:,1,1),'r',it,tnrm(:,2,1),'k',it,tnrm(:,3,1),'g',it,tnrm(:,4,1),'b') |
octave] |
plot(it,tnrm(:,1,1),'r',it,tnrm(:,1,2),'k',it,tnrm(:,1,3),'g') |
octave] |
figure(); plot(it,tnrm(:,2,1),'r',it,tnrm(:,2,2),'k',it,tnrm(:,2,3),'g') |
octave] |
figure(); |
octave] |
jt=8900:9200; plot(jt,cdata(jt,1),'r',jt,cdata(jt,2),'k',jt,cdata(jt,3),'g') |
octave] |
figure(1); pwd |
ans = /home/student/courses/MATH547ML/homework/hw01
octave] |
print -deps hw01fig03.eps |
octave] |
![]() |
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.
octave] |
function angd=angld(m1,m2,n1,d) [m,n]=size(d); angd=zeros(n1,n); for k=1:n angd(k)=d(m1:m2,n1)'*d(m1:m2,k)/norm(d(m1:m2,n1))/norm(d(m1:m2,k)); end end; |
octave] |
tang=zeros(100,n); for j=1:100 tang(j,:) = angld(100*j,100*(j+1),1,cdata); end; |
octave] |
it=1:100; plot(it,tang(:,1),'r',it,tang(:,2),'k',it,tang(:,3),'g') |
octave] |
figure(4) |
octave] |
plot(tang) |
octave] |
Use template from Lesson01 to construct a representation of the data through periodic functions.
octave] |
ns=5; A=[]; it=100:400; dt=0.1; t=it*dt; t=t'; A = [A ones(size(t))]; |
octave] |
for k=1:ns A = [A sin(k*t) cos(k*t)]; end |
octave] |
bt=cdata(it,1); |
octave] |
x=A\bt; |
octave] |
b=A*x; |
octave] |
plot(t,bt,'ok',t,b,'r'); |
octave] |
print -deps hw01fig04.eps |
octave] |
![]() |
Figure 5. Data from sensor 1 is not accurately
captured by a trigonometric series.
|