Create for loop in a matrix (power method)

2 次查看(过去 30 天)
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..

回答(1 个)

Roy dela Rama
Roy dela Rama 2016-3-9
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

类别

Help CenterFile Exchange 中查找有关 Logical 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by