Drexel dragonThe Math ForumDonate to the Math Forum



Search All of the Math Forum:

Views expressed in these public forums are not endorsed by Drexel University or The Math Forum.


Math Forum » Discussions » Software » comp.soft-sys.matlab

Topic: Iterative Procedure Using Vectors
Replies: 2   Last Post: Apr 26, 2013 3:26 AM

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   Messages: [ Previous | Next ]
Nasser Abbasi

Posts: 5,688
Registered: 2/7/05
Re: Iterative Procedure Using Vectors
Posted: Apr 26, 2013 3:26 AM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

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




Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© Drexel University 1994-2014. All Rights Reserved.
The Math Forum is a research and educational enterprise of the Drexel University School of Education.