'Enter The Matrix': For End For
'Enter The Matrix': For End For
'Enter The Matrix': For End For
DATE:
QR DECOMPOSITION OF A MATRIX
PROGRAMMING CODE
Clc;
a=input('enter the matrix');
[m n] =size(a);
u = zeros(m,n);
e = zeros(m,n);
v=zeros(m,1);
r=zeros(m,n);
u(:,1) =a(:,1)
s =0;
for j = 1:n
s = s+u(j,1)*u(j,1);
end
e(:,1)=u(:,1)/sqrt(s)
for i=2:n
s=0;
t=0;
v=zeros(m,1);
for j=1:m
for p =1:i-1
t=dot(a(:,i),e(:,p))
v(j,1)=v(j,1)+t*e(j,p);
end
u(j,i) = a(j,i)-v(j,1);
s=s+(u(j,i)*u(j,i))
end
e(:,i)=u(:,i)/sqrt(s)
end
fprintf('the Q Matrix:');
e
fprintf('the R matrix is:');
R = e'*a
fprintf('the given matrix');
L=e*R
0.9029
0.0343
0.1714 -0.9429
12.0000 -51.0000
4.0000