Monday, June 30, 2014

Fundamentals of Digital Image and Video Processing - Week 12 Solutions

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.

5 comments:

  1. Hi! your code does not work Thanks

    ReplyDelete
    Replies
    1. I think it should work! where did you get errors?

      Delete
  2. The code does not work! It gives an error on line 19:

    while nnz(x)<3 nbsp="" p="">i = 0;
    |
    Error: The input character is not valid in MATLAB statements or expressions.

    ReplyDelete
  3. Hi Vijay,

    The code showed does not work, please can you check it or check it with the user who submitted, cause it is not a valid solution.

    The following sentences does not work or do not have any sense:

    while nnz(x)<3 nbsp="" p="">i = 0;

    I does not make sense, cause it does not follow the logical structure for a While loop. MATLAB returns:

    Error: The input character is not valid in MATLAB statements or expressions.

    Moreover, what is the meaning of nnz(x), nbsp and p variables?

    On the other hand, this expression is not valid:

    if (maxnormmaxnorm = x_j;

    What that means? Again it has not a logical structure for an if condition in MATLAB.

    Making the proper corrections to the code, at the end MATLAB returns the following error message:

    Attempted to access A(:,0); index must be a positive integer or logical.

    ReplyDelete
  4. Really amazing information you shared. For getting services of Digital Marketing Company click on the link.

    ReplyDelete