高斯列主元消元法的matlab程序 求原创
1个回答
展开全部
两年前写的代码 comment 是给的,里面代码是我自己按照comment写的,希望能有帮助。
clc;
clear all;
A=[X X X X X ; X X X X X ;...];
b=[X X X X X]';
[m, n] = size(A);
% Non-square A, exit with error()
if m ~= n
error('A needs to be square!');
end
% b is not a column vectorQ, exit
[bm, bn] = size(b);
if bn ~= 1
error('b must be a column vector!');
end
% A and b sizes must agree
if m ~= bm
error('A and b size mismatch!');
end
Aug = [A b]; % Argumented Matrix
nb = n+1; % Column index of b values in Aug
% Forward Elimination
% Aug(1,1), Aug(2,2) ... etc
% So, Aug(p,p) is the current pivot element
for p = 1:n-1
for r = p+1:n
factor = Aug(r,p) / Aug(p,p);
Aug(r,p:nb) = Aug(r,p:nb) - factor*Aug(p,p:nb);
end
end
%Backward Substitution
x = zeros(size(b));
% Calculating last x value
x(n) = Aug(n,nb) / Aug(n, n);
% Again, Aug(p,p) is the pivot
% Moving through x values backwards
for p = n-1:-1:1
x(p) = (Aug(p, nb) - Aug(p, p+1:n)*x(p+1:n) ) / Aug(p,p);
end
x; % x is yr result
clc;
clear all;
A=[X X X X X ; X X X X X ;...];
b=[X X X X X]';
[m, n] = size(A);
% Non-square A, exit with error()
if m ~= n
error('A needs to be square!');
end
% b is not a column vectorQ, exit
[bm, bn] = size(b);
if bn ~= 1
error('b must be a column vector!');
end
% A and b sizes must agree
if m ~= bm
error('A and b size mismatch!');
end
Aug = [A b]; % Argumented Matrix
nb = n+1; % Column index of b values in Aug
% Forward Elimination
% Aug(1,1), Aug(2,2) ... etc
% So, Aug(p,p) is the current pivot element
for p = 1:n-1
for r = p+1:n
factor = Aug(r,p) / Aug(p,p);
Aug(r,p:nb) = Aug(r,p:nb) - factor*Aug(p,p:nb);
end
end
%Backward Substitution
x = zeros(size(b));
% Calculating last x value
x(n) = Aug(n,nb) / Aug(n, n);
% Again, Aug(p,p) is the pivot
% Moving through x values backwards
for p = n-1:-1:1
x(p) = (Aug(p, nb) - Aug(p, p+1:n)*x(p+1:n) ) / Aug(p,p);
end
x; % x is yr result
绿知洲
2024-11-13 广告
2024-11-13 广告
交通噪声预测计算主要依据车辆类型、平均辐射声级、交通量、行驶速度、距离衰减量、公路纵坡和路面等因素。预测时,需先确定各参数,如车型分类、平均行驶速度、噪声源强等。通过公式计算,可得出预测点接收到的交通噪声值。预测过程还需考虑几何发散、大气吸...
点击进入详情页
本回答由绿知洲提供
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询