Create for loop in a matrix (power method)

3 views (last 30 days)
Roy dela Rama
Roy dela Rama on 9 Mar 2016
Answered: Roy dela Rama on 9 Mar 2016
Estimate the most dominant eigenvalue of [A] and its corresponding eigenvector,using the power method.
A = [4 3 1;
3 -6 0;
1 0 2];
B = [1;
1;
1];
n = 50; % number of iterations
C = A*B % iterative equation
[maxC, index] = max (abs(C(:)));
maxC = maxC * sign(C(index))
% largest magnitude in matrix C (courtesy of IMAGE ANALYST)
D = C/maxC % factor out the largest magnitude in matrix C
B = D % this is the new value of B
I want to use the new value of B in C = A*B until it reaches 50 iterations. Expected answers are
maxC = -6.83909
D = -0.279693
1
0.0316436
I get an error message whenever I try the for loop..

Answers (1)

Roy dela Rama
Roy dela Rama on 9 Mar 2016
I already figured it out. I don't need to use C(i+1) for my iteration equation for this particular matrix.
All I have to do is proceed with for loop:
for i = 1:n;
C = A*B
[maxC, index] = max (abs(C(:)));
maxC = maxC * sign(C(index))
D = C/maxC % factor out the largest magnitude in matrix C
B = D % this is the new value of B
end
This will result with my expected answers

Categories

Find more on Numeric Types in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!