Hi Coursera people,
This is a follower submitted code. Thanks to Mokam for this code.
Solution to question 8 of Week 12.
b = [-2,-6,-9,1,8,10,1,-9,-4,-3]';
S = 3;
for i = 1:10
for j = 1:10
A(i,j) = sin(i+j);
if (i==j)
A(i,j) = A(i,j) +1;
end
end
end
for i = 1: 10
Anorm(:,i) = A(:,i)/norm(A(:,i));
end
A = Anorm;
x = zeros(10,1);
r = b;
omg = [];
A_omg = [];
while nnz(x)<3 nbsp="" p="">i = 0;
maxnorm = 0;
for j=1:10
if(any(j==omg))
else
x_j = norm(transpose(A(:,j)) * r);
if(maxnormmaxnorm = x_j;
i = j;
end
end
end
omg = [omg, i];
A_omg = [A_omg, A(:,i)];
z_omega_star = pinv(A_omg' * A_omg) * A_omg' * b;
r = b - A_omg * z_omega_star;
x = zeros(10,1);
for j=1:length(omg)
index = omg(1,j);
x(index,1) = z_omega_star(j,1);
end
end
Answer is the matrix omg, in ascending order.
-Cheers,
Vijay. 3>
This is a follower submitted code. Thanks to Mokam for this code.
Solution to question 8 of Week 12.
b = [-2,-6,-9,1,8,10,1,-9,-4,-3]';
S = 3;
for i = 1:10
for j = 1:10
A(i,j) = sin(i+j);
if (i==j)
A(i,j) = A(i,j) +1;
end
end
end
for i = 1: 10
Anorm(:,i) = A(:,i)/norm(A(:,i));
end
A = Anorm;
x = zeros(10,1);
r = b;
omg = [];
A_omg = [];
while nnz(x)<3 nbsp="" p="">i = 0;
maxnorm = 0;
for j=1:10
if(any(j==omg))
else
x_j = norm(transpose(A(:,j)) * r);
if(maxnorm
i = j;
end
end
end
omg = [omg, i];
A_omg = [A_omg, A(:,i)];
z_omega_star = pinv(A_omg' * A_omg) * A_omg' * b;
r = b - A_omg * z_omega_star;
x = zeros(10,1);
for j=1:length(omg)
index = omg(1,j);
x(index,1) = z_omega_star(j,1);
end
end
Answer is the matrix omg, in ascending order.
-Cheers,
Vijay.