Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function [ AnsVec, TracF ] = BroydenMethod ( A, x )
- # Matthew Graham
- # Mat 4010
- # Broyden's Method
- # A is the matrix in which we are trying to find the eigenvalues and eigenvectors
- # x is the initial guess for the eigenvector with the eigenvalue as the last entry
- # work in progress as far as comments are concerned
- # rest of the code is good to go
- if (size(A, 1) == size(A, 2))
- n = size(A,1);
- v = x(1:n);
- lambda = x(n+1);
- for i = 1: n
- F(i) = [A(i,:)*v];
- i = i+1;
- endfor
- F = F';
- F = [F; .5*(v'*v)] + [-lambda*v; -1];
- TracF = [F];
- J = [A-lambda*eye(n), -v; v', 0];
- d = -J\F;
- x = [x, x(:, columns(x))+d];
- delta = x(:, columns(x)-1) - x(:, columns(x));
- v = x(1:n, columns(x));
- lambda = x(n+1, columns(x));
- for i = 1: n
- F(i) = [A(i,:)*v];
- i = i+1;
- endfor
- F(n+1) = .5*(v'*v);
- F = F + [-lambda*v; -1];
- TracF = [TracF, F];
- y = TracF(:, columns(TracF)-1) - TracF(:, columns (TracF));
- J = J + ((y - J*delta)/(delta'*delta))*delta';
- while abs((sqrt(delta'*delta))/sqrt((x(:, columns(x))'*x(:, columns(x)))))>1e-6
- d = -J\F;
- x = [x, x(:, columns(x))+d];
- delta = x(:, columns(x)-1) - x(:, columns(x));
- v = x(1:n, columns(x));
- lambda = x(n+1, columns(x));
- for i = 1: n
- F(i) = [A(i,:)*v];
- i = i+1;
- endfor
- F(n+1) = .5*(v'*v);
- F = F + [-lambda*v; -1];
- TracF = [TracF, F];
- y = TracF(:, columns(TracF)-1) - TracF(:, columns (TracF));
- J = J + ((y - J*delta)/(delta'*delta))*delta';
- endwhile
- AnsVec = x(:, columns(x));
- else
- printf("Matrix A is not square \n")
- endif
- endfunction
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement