Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Iterative Procedure Using Vectors

Subject: Iterative Procedure Using Vectors

From: Laura

Date: 25 Apr, 2013 17:56:11

Message: 1 of 3

I have been told to carry out the following iterative procedure:
a) Set a vector v to be the vector [1 ; 0]
b) Find a new vector u = Av (where A is a 2 x 2 real matrix)
c) Find the magnitude of this new vector u, and call this magnitude c
d) Divide u by c
e) Set v to be this unit vector, then repeat steps b) to e) a number of times.

So far I have tried:
v(1) = [1 ; 0]
for n = 1:100
    u(n) = A*v(n+1)
    c(n) = norm(u(n))
    v(n+1) = u(n)/c(n)
end

However, it doesn't seem to like the v(1) part and keeps saying sub-matrix error, probably because it thinks that I am referring to the first element in the vector instead of saying v = [1 ; 0] is the initial condition. Does anyone know how I can do this?
Also I'm not sure if the rest of it works ...

Subject: Iterative Procedure Using Vectors

From: Steven_Lord

Date: 25 Apr, 2013 18:30:57

Message: 2 of 3



"Laura " <laurafilgate17@gmail.com> wrote in message
news:klbqnr$mdk$1@newscl01ah.mathworks.com...
> I have been told to carry out the following iterative procedure:
> a) Set a vector v to be the vector [1 ; 0]
> b) Find a new vector u = Av (where A is a 2 x 2 real matrix)
> c) Find the magnitude of this new vector u, and call this magnitude c
> d) Divide u by c
> e) Set v to be this unit vector, then repeat steps b) to e) a number of
> times.
>
> So far I have tried:
> v(1) = [1 ; 0]

You can't fit the two elements of [1; 0] into the one element of v(1). It's
too big. If you wanted to store that in the first column of v, that would
work:

v(:, 1) = [1; 0]

> for n = 1:100
> u(n) = A*v(n+1)

See above plus you'll want to change all your indexing to refer to columns
of the matrix rather than individual elements.

Also pay close attention to whether you want elementwise or vector division.
See:

http://www.mathworks.com/help/matlab/ref/rdivide.html
http://www.mathworks.com/help/matlab/ref/mrdivide.html

--
Steve Lord
slord@mathworks.com
To contact Technical Support use the Contact Us link on
http://www.mathworks.com

Subject: Iterative Procedure Using Vectors

From: Nasser M. Abbasi

Date: 26 Apr, 2013 07:26:57

Message: 3 of 3

On 4/25/2013 12:56 PM, Laura wrote:
> I have been told to carry out the following iterative procedure:
> a) Set a vector v to be the vector [1 ; 0]
> b) Find a new vector u = Av (where A is a 2 x 2 real matrix)
> c) Find the magnitude of this new vector u, and call this magnitude c
> d) Divide u by c
> e) Set v to be this unit vector, then repeat steps b) to e) a number of times.
>
> So far I have tried:
> v(1) = [1 ; 0]
> for n = 1:100
> u(n) = A*v(n+1)
> c(n) = norm(u(n))
> v(n+1) = u(n)/c(n)
> end
>
> However, it doesn't seem to like the v(1) part and keeps saying sub-matrix error,
>probably because it thinks that I am referring to the first element in the vector
>instead of saying v = [1 ; 0] is the initial condition. Does anyone know how I can do this?
> Also I'm not sure if the rest of it works ...
>

There is nothing in the HW instructions that says you need to keep
track of all the v's. So why not just

---------------------
v = [1;0];
A = rand(2);
for n = 1:10
     u = A*v;
     v = u/norm(u)
end
------------------

If you need to save all the v's, then try

--------------------------
N = 10;
v = zeros(2,N);
v(:,1) = [1;0];
A = rand(2);

for n = 2:N
     u = A*v(:,n-1);
     v(:,n) = u/norm(u);
end
--------------------

EDU>> v'

ans =

    1.000000000000000 0
    0.942479907869958 0.334262805680553
    0.941008227921574 0.338383680138241
    0.940991359516029 0.338430585668871
    0.940991167526323 0.338431119487329
    0.940991165341345 0.338431125562555
    0.940991165316478 0.338431125631695
    0.940991165316195 0.338431125632482
    0.940991165316192 0.338431125632491
    0.940991165316192 0.338431125632491

that is a good convergence. You only need 3-4 iterations really.

--Nasser

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us