You just need to store your x values inside the loop in an array. Anyway, firstly when you write
v(1)=2; v(2)=0; v(3)=1; v(4)=4; v(5)=2; v(6)=8; v(7)=0;
you are already creating a vector so you don't need the line that follows. Or you could simply write
Both mean the same thing.
Nextly, you could save the given values like,
x_init=[v(5)+1;v(6)];
MaxNorm=0.01;
and then define iter as 1 to calculate the first iteration outside the loop like,
iter=1;
x(:,iter) = A*x_init;
and then go inside the loop to calculate the remaining iterations until the condition is satisfied,
while norm(x(:,iter))>=MaxNorm
iter=iter+1;
x(:,iter)=A*x(:,iter-1);
end
finally, transpose the matrix using,
then plot or do whatever you want to do with it,
Best Answer