MATLAB: For loop help for Linear Algebra Class

for looplinear algebraMATLAB

I cant seem to get this algorithm code correct.
%HW3 #2
% Given:
%

% y_k denotes k index
%
% y_k=A*x_k
% r_k=norm(y_k) / norm(x_k)
% x_(k+1) = y_k / norm(y)
%
% Create a vector with 0-50 indexes of k
clear all;
close all;
A = [-5,3,-1;0,4,1;0,0,-2];
x(1)=[1;1;1];
for k = 1:51
y{k} = A.*x;
r{k} = norm(y)/norm(x);
x{k+1} = y/norm(y);
end
I receive the error: "In an assignment A(I) = B, the number of elements in B and I must bethe same."
Im not sure how to go about fixing the problem, because I do not fully understand how mat lab operates yet.

Best Answer

Instead of
x(1)=[1;1;1];
you would need
x{1}=[1;1;1];
to avoid that error.
However, then when you go to the A.*x you would fail in trying to multiply A by a cell array. Try
y{k} = A.*x{k}
Related Question