Gram Shimidt QR Factorization Matlab version

function [Q,R] = gram_schmidt_qr(A)

% Formation: A = QR
% The implementation of QR Factorization(classical Gram-Schmidt method)
% Q is orthonormal basis for R(A)
% R is an upper-triangular matrix with positive diagonal entries.

% Author: Zhenlin Du(Johnsondu)
% Email:  [email protected]
% Time:   2014-11-27 22:00

A = double(A)
[m, n] = size(A);
Q = zeros(m, n);
R = zeros(n, n);

% for k = 1
u1 = A(:, 1);
Q(:, 1) = u1 / (sqrt(dot(u1, u1)));
R(1, 1) = (sqrt(dot(u1, u1)));

% for k > 1
for i = 2 : n
	% take column i
	u = A(:, i);  

    % compute R and u
	for j = 1: i - 1
		R(j, i) = dot(Q(:, j), u);
		u = u - R(j, i) * Q(:, j);
    end

    % get R(i, i)
	R(i, i) = (sqrt(dot(u, u)));
    % normalize
	u = u / R(i, i);
	Q(:, i) = u;
end

时间: 2025-01-02 14:22:26

Gram Shimidt QR Factorization Matlab version的相关文章

PLU decomposition Matlab version

function [P, L, U] = plu(A) % The implementation of PLU Factorization % L is lower triangular and U is upper triangular % P is permutation matrix % Author: Zhenlin Du(Johnsondu) % Email: [email protected] % Time: 2014-11-27 22:00 A = double(A); [m, n

Derive Modified Gram Schmidt QR Decomposition Algorithm from Gram Schmidt Orthogonalisation (part 2)

All rights reserved. Please don't share this article without notifying me. Email address: [email protected] From eq. 10 in part 1 we can find the Classical Gram Schmidt Algorithm, which is numerically unstable or sensitive to perturbation: Q=zeros((m

Householder Reduction Matlab Version

function [T, P] = householder(A) % Formations: RA = T, where A is original matrix % The implementation of Householder Reduction % R is constructed as a product of elementary reflector % T is upper triangular matrix % Author: Zhenlin Du(Johnsondu) % E

Matlab中所有自定义的函数

Functions By Category | Alphabetical List Language Fundamentals Entering Commands ans Most recent answer clc Clear Command Window diary Save Command Window text to file format Set display format for output home Send cursor home iskeyword Determine wh

lanczos算法及C++实现(二)实对称阵奇异值分解的QR算法

本文属作者原创,转载请注明出处: http://www.cnblogs.com/qxred/p/qralgorithm.html 首先推荐两个参考文献 https://www.math.kth.se/na/SF2524/matber15/qrmethod.pdf http://people.inf.ethz.ch/arbenz/ewp/Lnotes/chapter4.pdf 1. 基本的QR算法 我们先讨论一般对阵矩阵的QR算法,再讨论对称三对角阵的QR算法 给定一个实对称阵X,假设其特征值分解

Extending Justin’s Guide to MATLAB in MATH 240

Extending Justin’s Guide to MATLAB in MATH 240 - Part 41. MethodWe assume you are comfortable with (and remember or can review) commands used in the earlierprojects.2. New Commands(a) Eigenvalues can be found easily. If A is a matrix then:>> eig(A)w

matlab分布式平台

一.Matlab R2014b安装教程 1,下载Matlab R2014b ISO格式安装包 2,以winrar格式解压缩ISO文件,出现下图所示的文件列表 3,进入Matlab2014b crack.rar中jar文件,将其中的ValidatedFikImpl.class和InstallerBuilderImpl.class文件复制替换到 上述解压缩文件夹内的路径 \java\jar\install.jar压缩文件的\com\mathworks\install\目录下: 直接向Winrar所打

Linux版Matlab R2015b的bug——脚本运行的陷阱(未解决)

0 系统+软件版本 系统:CentOS 6.7 x64, 内核 2.6.32-573.el6.x86_64软件:Matlab R2015b(包括威锋网和东北大学ipv6下载的资源,都测试过) 1 bug描述 1.1 未知的“陷阱” 首先,这个程序在Matlab R2013a中可以完美运行,这个“陷阱“在是新安装的R2015b上才出现的. 说它是“陷阱“,是因为脚本文件涉及到大量的数据处理,比如一个几百次的循环,它可能在执行某一句的时候就失去响应了,可能是一个循环,也可能是单句,仿佛掉进了一个未知

浅谈压缩感知(七):常见测量矩阵的MATLAB实现

1.随机高斯测量矩阵 function [ Phi ] = GaussMtx( M,N ) %GaussMtx Summary of this function goes here % Generate Bernoulli matrix % M -- RowNumber % N -- ColumnNumber % Phi -- The Gauss matrix %% Generate Gauss matrix Phi = randn(M,N); %Phi = Phi/sqrt(M); end 2