matlab - 无旋转的带状矩阵版本的高斯消元法
问题描述
我是 Matlab 的新手,每当我编写代码时我都会面临挑战。我有一个关于没有旋转的高斯消除的 Matlab 代码,我想实现它的带状矩阵版本,它接受一个参数 k 表示每个方向上非零的非对角线条目的数量(带宽)那是,如果 i > j + k 或 j > i + k,则 aij = 0。函数可以像这样开始: 函数 x = BandedGauss(A,b,k)。 下面是我没有旋转的高斯消除:
function [x] = GE_WithoutPivoting1(A,b)
% Solve linear system Ax=b using Gaussian elimination
n = length(b);
for k=1:n-1
% Check to see if the pivot is zero
if abs(A(k,k)) < 1e-15
error('A has diagonal entries of zero')
end
% Apply transformation to remaining submatrix and RHS vector
for i=k+1:n
m = -A(i,k)/A(k,k); % multiplier for current row i
for j=k+1:n
A(i,j) = A(i,j) + m*A(k,j);
end
b(i) = b(i) + m*b(k);
end
end
% A is now upper diagonal. Now, call the back substitution function to
% solve for the x solution vector i.e., the transformed problem:
x = GE_BackSubstitution(A,b);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function [x] = GE_BackSubstitution(A,b)
% Solve the upper triangular system Ax=b using backward substitution
n= length(b);
x = zeros(n,1);
for j=n:-1:1
% Check to see if the diagonal entry is zero
if abs(A(j,j)) < 1e-15
error('A is singular (zero diagonal entry)')
end
% Compute solution component
x(j) = b(j) / A(j,j);
% Update the RHS vector
for i=1:j-1
b(i) = b(i) - A(i,j)*x(j);
end
end
解决方案
推荐阅读
- google-analytics - 如果我只选择了一个国家/地区(哥伦比亚)加入我的 Google 行动,为什么我会有来自其他国家/地区的互动?
- windows - Windows UWP 应用程序找不到振动设备
- pm2 - pm2 在其列表中有多个可执行文件副本
- c++ - 如何在 Win32 中创建 POINT 对象?
- javascript - 如何将 for 循环中的项目组合成一个数组(Javascript)?
- arrays - 使用双精度数组在 C 中遇到问题
- graphql - 字典值 GraphQL Schema
- bash - Shell 脚本值对于基本问题来说太大了
- html - a:link 和 .nav-link 中的颜色冲突
- sql - 计数/组输出中空值的雪花/SQL 会计