Given an nxn matrix and eigenvector, performs deflation creating an nxn matrix which is similar to A. That is it has the same eigenvalues as A. Uses an alternative algorithm. Input arguments: A, square matrix v, eigenvector of A Output arguments: D, deflated matrix
0001 function [ D ] = deflation_alt_1( A,v ) 0002 % Given an nxn matrix and eigenvector, performs deflation 0003 % creating an nxn matrix which is similar to A. That is it has the 0004 % same eigenvalues as A. Uses an alternative algorithm. 0005 % Input arguments: 0006 % A, square matrix 0007 % v, eigenvector of A 0008 % Output arguments: 0009 % D, deflated matrix 0010 0011 [n,m]=size(A); % finding the size of A 0012 [p,q]=size(v); % finding the size of v 0013 if n~= m; 0014 error('input is not a square matrix'); 0015 elseif q~=1 || p~=n; 0016 error('input dimensions do not agree'); 0017 end 0018 0019 % find index of first nonzero entry in v 0020 k=1; 0021 while v(k)==0 0022 k=k+1; 0023 end 0024 if k>n 0025 error('zero vector is invalid input'); 0026 end 0027 0028 if k>1 0029 P=eye(n); % generate permutation matrix such that 0030 P(1,1)=0; % first entry in P*v is non-zero 0031 P(1,k)=1; 0032 P(k,1)=1; 0033 P(k,k)=0; 0034 v = P*v; 0035 A = P*A*P'; % adjust A 0036 end 0037 S=eye(n); % initializing S to the identity 0038 for i=2:n; % adjusting S so that the bottom n-1 entries of S*v are zero 0039 S(i,1)=-v(i)/v(1); 0040 end 0041 0042 S_inv=2*eye(n)-S; % calculating inverse of S 0043 0044 D=S*A*S_inv; % generating deflated matrix 0045 0046 end 0047