matlab lu分解 l不是下三角,在MATLAB中执行LU分解而不进行旋转
默認(rèn)情況下,MATLAB的lu始終執(zhí)行旋轉(zhuǎn).如果您在嘗試執(zhí)行傳統(tǒng)的LU分解算法時(shí),例如對(duì)角線系數(shù)等于0,則在執(zhí)行高斯消元法創(chuàng)建上三角矩陣U時(shí)需要對(duì)角系數(shù),因此無(wú)法工作除以零誤差.需要旋轉(zhuǎn)以確保分解穩(wěn)定.
但是,如果您可以保證矩陣的對(duì)角線系數(shù)不為零,那么它非常簡(jiǎn)單,但您必須自己編寫(xiě).您所要做的就是在矩陣上執(zhí)行高斯消元法,并將矩陣縮減為梯形縮減形式.結(jié)果減少的梯形形式矩陣是U,而去除高斯消除中L的下三角形部分所需的系數(shù)將被放置在下三角形半部以制造U.
假設(shè)你的矩陣存儲(chǔ)在A中,這樣的東西可以工作.記住我在這里假設(shè)一個(gè)方陣.非旋轉(zhuǎn)LU分解算法的實(shí)現(xiàn)放在名為lu_nopivot的MATLAB函數(shù)文件中:
function [L, U] = lu_nopivot(A)
n = size(A, 1); % Obtain number of rows (should equal number of columns)
L = eye(n); % Start L off as identity and populate the lower triangular half slowly
for k = 1 : n
% For each row k, access columns from k+1 to the end and divide by
% the diagonal coefficient at A(k ,k)
L(k + 1 : n, k) = A(k + 1 : n, k) / A(k, k);
% For each row k+1 to the end, perform Gaussian elimination
% In the end, A will contain U
for l = k + 1 : n
A(l, :) = A(l, :) - L(l, k) * A(k, :);
end
end
U = A;
end
作為一個(gè)運(yùn)行的例子,假設(shè)我們有以下3 x 3矩陣:
>> rng(123)
>> A = randi(10, 3, 3)
A =
7 6 10
3 8 7
3 5 5
運(yùn)行算法給我們:
>> [L,U] = lu_nopivot(A)
L =
1.0000 0 0
0.4286 1.0000 0
0.4286 0.4474 1.0000
U =
7.0000 6.0000 10.0000
0 5.4286 2.7143
0 0 -0.5000
將L和U相乘得出:
>> L*U
ans =
7 6 10
3 8 7
3 5 5
…這是原始矩陣A.
總結(jié)
以上是生活随笔為你收集整理的matlab lu分解 l不是下三角,在MATLAB中执行LU分解而不进行旋转的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: php 注册树,php常用设计模式(单例
- 下一篇: homestead开发php,介绍Thi