一、高斯消去法的程序:
function [A,b]= Gauss(A,b);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%use Gaussian elimination method to change 'A' into upper triangular matrix
% Nov 26,2008
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
[m,n]=size(A); %get the size of matrix 'A'
% column pivotal elimination method
for k=1:n-1
[v,u]=max(abs(A(k:n,k))); %select the maximum element into the kth
%column of matrix A(k:n,1:k)
u=u+k-1; %because function max return the index of maximum values
%of A(k:n,1:k) so we should change it into the value of
%matrix A
p(k)=u; %record the index u
%exchange the row of k and u
t1 = A(k,k:n); %temporary variable t1
A(k,k:n) = A(u,k:n);
A(u,k:n) = t1;
t2 = b(k); %temporary variable t2
b(k) = b(u);
b(u) = t2;
% Gauss elimination method
if A(k,k) ~= 0
rows=k+1:n
A(rows,k)=A(rows,k)/A(k,k);
A(rows,rows)=A(rows,rows)-A(rows,k)*A(k,k);
L(rows,rows)=A(rows,rows);
end
end
% calculate the matrix U
for k=2:n
A(k,1:k-1)=0;
end
二、求解三角方程组的程序:
function x= Eqn_Root(A,b);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% calculate the solution of upper triangular equations set Ax=b
% Nov 26,2008
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
[m,n]=size(A); %get the size of matrix 'A'
%x(n)=b(n)/A(n,n); %calculate x(n)
% calculate the solution
for i = n : -1 : 1
t = 0;
for j = n : -1 : i+1
t = t+A(i,j)*x(j);
end
x(i) = (b(i)-t)/A(i,i);
end
三、主程序:
function Examples_Eqn_Root
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% use the Gauss method to solve the linear equations Ax=b
% Nov 26, 2008
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
A = [ 1 3 6 8 9 2; %input the value of 'A'
2 5 3 1 6 3;
3 6 1 2 8 5;
2 6 8 9 3 8;
5 8 9 3 2 3;
3 5 8 1 7 2];
b= [2 -3 2 55 16 -6]; %input the value of 'b'
b = b'; %take the transpose of 'b'
[A,b]= Gauss(A,b) %change the matrix 'A' into upper triangular matrix
%return the new array 'b'
b = b'
x= Eqn_Root(A,b) %calculate the upper triangular quations set
end
如题。。。翻译下注释就可以了
不要用在线翻译。。。稍微知道点的来回答下= =
关于matlab高斯消去法,翻译下注释就可以了,在线等
用高斯消去法把矩阵A转换为上三角阵 [m,n]=size(A); %获得A的行和列分别存入m和n中 列主元素消去法 for k=1:n-1 [v,u]=max(abs(A(k:n,k))); %选出A的第k列中绝对值最大元素存入v, 而u是记录多少的行或列,并取最大值,比如有m行,n列,且n>m,则u=n 计算矩阵A...
MATLAB实现高斯列主元消去法的问题
按你的思路修改的,我试了一两个例子,还行。function x = gauss(A,b)[n,n]= size(A);x = zeros(n,1);Aug = [A,b];增广矩阵 for k = 1:n-1 [piv,r]= max(abs(Aug(k:n,k)));找列主元所在子矩阵的行r r = r + k - 1;列主元所在大矩阵的行 if r>k temp=Aug(k,...
matlab中用的高斯消元法怎么使用!
function x=gaussLinearEquation(A,b)高斯法解线性方程Ax=b disp('原方程为AX=b:')A b disp('---')n=length(b);eps=10^-2;for k=1:n-1 找列主元 [mainElement,index]=max(abs(A(k:n,k)));index=index+k-1;%index在A(k:n,k)中的行号转换为在A中的行号 if abs(mainElemen...
用MATLAB 实现列主元高斯消去法
function x=gauss_lie(A,b)采用高斯列主元法求解方程组Ax=b n=length(b);p=1:n;lu=A;y=[];for k=1:n [c,i]=max(abs(lu(k:n,k)));ik=i+k-1;if ik~=k m=p(k);p(k)=p(ik);p(ik)=m;ck=lu(k,:);lu(k,:)=lu(ik,:);lu(ik,:)=ck;end if k==n break;e...
用matlab 编写高斯顺序消元法求解下面方程组的程序及并计算结果_百度知 ...
function [x,XA]=GaussXQByOrder(A,b)高斯顺序消元法 N = size(A);n = N(1);for i=1:(n-1)for j=(i+1):n if(A(i,i)==0)disp('对角元素为0!'); %防止对角元素为0 return;end l = A(j,i);m = A(i,i);A(j,1:n)=A(j,1:n)-l*A(i,1:n)\/m; %...
MATLAB 如何使用高斯消去法解出方程式
高斯消去法解方程 Ax = B NA = size(A,2);[NB1,NB] = size(B);if NB1 ~= NA,error('A 和 b 维数不匹配');end N = NA + NB;AB = [A(1:NA,1:NA) B(1:NA,1:NB)]; % 增广矩阵 epss = eps*ones(NA,1);for k = 1:NA [akk,kx] = max(abs(AB(k:NA,k))....
用高斯消元法解线性方程组 的MATLAB程序
inv)求解线性方程组,输入如下代码:close all; clear all; clc,% MATLAB求逆法(inv)求解线性方程组,% A是线性方程组等号左边系数构成的矩阵。5、保存和运行上述代码,利用求逆法(inv)得到线性方程组的解如下。6、最后,可以看到左除法(\\)和求逆法(inv)求得的线性方程组解是一样的。
matlab 用列主元高斯消去法求逆矩阵
程序如下 function x=gauss(A,b) %高斯求解方程组 x=gauss(A,b)n=length(A);a=[A,b];for k=1:n-1 maxa=max(abs(a(k:n,k)));if maxa==0 return;end for i=k:n if abs(a(i,k))==maxa y=a(i,k:n+1);a(i,k:n+1)=a(k,k:n+1);a(k,k:n+1)=y;break;end...
如何用matlab语言实现用高斯消去法求矩阵的逆?
if Row ~= Col '线性方程组的系数矩阵非方阵,程序终止'return end if det(a)==0 '线性方程组的系数矩阵行列式为0'return end Gauss消元法 for k=1:n-1 if a (k,k) ==0 '对角线元素a(%1d,%1d)为零,程序终止'return end for i =k+1:n l(i,k) = a(i,k)\/a(k,k);for ...
如何编写用高斯约旦全主消元法求矩阵的逆矩阵的MATLAB程序
1\/x)+1]为初等函数,其定义域为x≠0,所以当x≠0时,函数皆连续.∵lim[x-->0-][2^(1\/x)-1]\/[2^(1\/x)+1]=-1 ∵lim[x-->0+][2^(1\/x)-1]\/[2^(1\/x)+1]=lim[x-->0+][1-2^(-1\/x)]\/[1+2^(-1\/x)]=1 ∴x=0是第一类间断点,是阶跃间断点,跳跃度是2.