필터 지우기
필터 지우기

Create for loop in a matrix (power method)

조회 수: 2 (최근 30일)
Roy dela Rama
Roy dela Rama 2016년 3월 9일
답변: Roy dela Rama 2016년 3월 9일
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