How to get my script to work?

I want to make a script to follow an iterative procedure but every time I run my current script the following error message: ??? In an assignment A(I) = B, the number of elements in B and I must be the same.
A = [1 2;3 4]
%Investigate the iterative procedure v(n+1) = u/C
for n = 1:10
v(1) = [1 0];
u = A*transpose(v(n));
C = norm(u);
v(n+1) = u/C;
end
How do I fix this? Thank you for your help in advance.

1 comentario

Jan
Jan el 29 de Abr. de 2013
When you post an error message in the forum, show the failing line also. Although we could guess it here, relying on out crystal balls is usually not efficient. ;-)

Respuestas (2)

Azzi Abdelmalek
Azzi Abdelmalek el 29 de Abr. de 2013

0 votos

A = [1 2;3 4]
%Investigate the iterative procedure v(n+1) = u/C
for n = 1:10
v(1,:) = [1 0];
u = A*transpose(v(n,:));
C = norm(u);
v(n+1,:) = u/C;
end

2 comentarios

Arati
Arati el 29 de Abr. de 2013
Thank you, I can see where I was going wrong now.
Jan
Jan el 29 de Abr. de 2013
I recommend to use a pre-allocation. This is fundamental for efficient programs.
Jan
Jan el 29 de Abr. de 2013

0 votos

A = [1 2;3 4]
v = zeros(11, 2); % Pre-allocate
v(1, :) = [1 0]; % Outside the loop
for n = 1:10
u = A * transpose(v(n, :));
C = norm(u);
v(n+1, :) = u/C;
end

La pregunta está cerrada.

Preguntada:

el 29 de Abr. de 2013

Cerrada:

el 20 de Ag. de 2021

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by