```Path: news.mathworks.com!newsfeed-00.mathworks.com!news.tele.dk!feed118.news.tele.dk!news.tele.dk!small.news.tele.dk!newsfeed.xs4all.nl!newsfeed4.news.xs4all.nl!xs4all!news.stack.nl!aioe.org!.POSTED!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Iterative Procedure Using Vectors
Date: Fri, 26 Apr 2013 02:26:57 -0500
Organization: Aioe.org NNTP Server
Lines: 67
Message-ID: <klda83\$g24\$1@speranza.aioe.org>
References: <klbqnr\$mdk\$1@newscl01ah.mathworks.com>
NNTP-Posting-Host: IcbzAjffnWaq9tw6UJPbag.user.speranza.aioe.org
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
X-Complaints-To: abuse@aioe.org
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:17.0) Gecko/20130328 Thunderbird/17.0.5
X-Notice: Filtered by postfilter v. 0.8.2
Xref: news.mathworks.com comp.soft-sys.matlab:794387

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

```