How can I update a matrix at the end of each 'for loop' and use that updated matrix in the second loop?
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
I want find Schur Decomposition using QR decomposition of Matrix A.
The algorithm for finding Schur Decomposition using QR factorization method is:
- Set A(1)=A (in my case, R=A)
- Find QR-decompostion Q(1)R(1) of A
- Define A(2)=R(1)*Q(1)
- Find a QR Decomposition Q(2)R(2) of A(2)
- Repeat this process! that is, if A(k) has the QR decomposition Q(k)R(k), use this to define A(k+1)=R(k)*Q(k)
I also want to compare the result with matlab result using schur(A).
clc;
clear all;
close all;
A=[2 -3 1;-1 5 -2;3 -8 4];
b=[2 4 5];
N=size(A,1);
Q=eye(N);
R=A;
for i=1:5
R=A;
% For Finding QR decomposition of A
for k=1:N-1
H=Householder1(R(:,k),k);
R=H*R;
Q=Q*H;
end
%After QR decomposition of A, the value of Q and R is
Q
R
% I want to multiply R and Q and define A1 as A1=R*Q
% Then reassign "A1" in "R" at the beginning of the 'for loop' to start the 2nd loop.
A1=R*Q
end
% Function for creating Householder's Matrix
function H=Householder1(x,k)
N=length(x);
tmp=sum(x(k+1:N).^2);
g=sqrt(x(k)^2+tmp);
c=sqrt((x(k)+g)^2+tmp);
w=zeros(N,1);
w(k)=(x(k)+g)/c;
w(k+1:N)=x(k+1:N)/c;
H=eye(N)-2*w*w';
end
0 comentarios
Respuestas (1)
Koundinya
el 18 de Dic. de 2018
Editada: Koundinya
el 18 de Dic. de 2018
It isn't quite clear as to what the exact problem is , but if you want to update the value of R after each iteration :
R=A;
for i=1:5
% R=A;
% For Finding QR decomposition of A
for k=1:N-1
H=Householder1(R(:,k),k);
R=H*R;
Q=Q*H;
end
%After QR decomposition of A, the value of Q and R is
Q
R
% I want to multiply R and Q and define A1 as A1=R*Q
% Then reassign "A1" in "R" at the beginning of the 'for loop' to start the 2nd loop.
A1=R*Q;
R=A1;
end
0 comentarios
Ver también
Categorías
Más información sobre Linear Algebra en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!