Assignment 3 Test Scripts

P1

% P1
% Examines maxElement
clc
n = 10000;
rand('seed',0)
v = 1000*rand(n-1,1);
a = 2*ones(n,1);
c = -ones(n-1,1)+v;
f = -ones(n-1,1)-v;
disp('    m              maxElement')
disp('-----------------------------------')
for m=1000:1000:10000
    mu = MaxElement(a(1:m),c(1:m-1),f(1:m-1));
    disp(sprintf('%6d  %30.15f',m,mu))
end

% NOTE: Make sure you comment your maxElement implementation so that it
% is clear how many flops are require. In particular, include
% a comment of the form
%                   Total flops = ( ____ ) * n^{___}   (Fill in the blanks)

 

P2

% P2 Tests BlockToeplitz

p = 100;
m = 5;
R = cell(p,1);
randn('seed',0);
for i=1:p
    R{i} = randn(m,m);
    R{i} = R{i}/(p*max(max(abs(R{i})))); %Scaling ensures T_{p} diag dom
end
b = randn(p*m,1);

% Explicit Solution
A = zeros(p*m,p*m);
for i=1:p
    for j=1:p
        rows = 1+(i-1)*m:i*m;
        cols = 1+(j-1)*m:j*m;
        if i==j
            A(rows,cols) = eye(m,m);
        elseif i < j
            A(rows,cols) = R{j-i};
        else
            A(rows,cols) = R{i-j};
        end
    end
end
x0 = A\b;

x = BlockToeplitz(R,b);
errx = norm(x0-x)/norm(x0);
clc
disp(sprintf('Cond(Tp)       = %10.3e\nrelative error = %10.3e',cond(A),errx))

% NOTE: Make sure you comment your BlockToeplitz implementation so that it
% is clear how many flops are require. In particular, include
% a comment of the form
%                   Total flops = ( ____ ) * p^{___} * m^{___}
% Fill in the blanks.
% Likewise, include a comment of the form
%                   Required storage = ( ____ ) * p^{ ___ } * m^{___}