?? mychol.m
字號(hào):
function [A,iflag] = mychol( A )%% Usage:% [A,iflag] = mychol( A )%% Given a symmetric N by N matrix A, CHOL attempts% to compute the Cholesky decomposition of A.% (Inner product form.)% %% input:% A: The N by N matrix A.% Only the lower triangular part of A% is used.%% output:% A: The upper triangular part of A% contains the Cholesky factor R.% The strict lower triangular part of A is unchanged.%% iflag: error flag% iflag = 0 Cholesky decomposition could be computed% and is stored in the upper triangular% part of A.% iflag = 1 A is not squared% iflag > 1 Negative entry observed in step iflag-1.% Matrix A is not positive definite.%%% Matthias Heinkenschloss% Jan 30, 2007iflag = 0;% get size of A and check dimensions[m,n] = size(A);if ( m ~= n ) iflag = 1; returnend% Start Cholesky decomposition% first stepif( A(1,1) <= 0 ) iflag = 2; returnend% Step 1A(1,1) = sqrt(A(1,1));A(1,2:n) = A(1,2:n) / A(1,1);% Steps 2 to nfor i = 2:n t = A(i,i) - A(1:i-1,i)'*A(1:i-1,i); if( t <= 0 ) iflag = i; return end A(i,i) = sqrt(t); for j = i+1:n A(i,j) = ( A(i,j) - A(1:i-1,i)'*A(1:i-1,j) ) / A(i,i); endend %end of mychol
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -