Effacer les filtres
Effacer les filtres

Create for loop in a matrix (power method)

2 vues (au cours des 30 derniers jours)
Roy dela Rama
Roy dela Rama le 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..

Réponses (1)

Roy dela Rama
Roy dela Rama le 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

Catégories

En savoir plus sur Logical dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by