英语翻译一、高斯消去法的程序:function [A,b]= Gauss(A,b);%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%use Gaussian elimination method to change 'A' into upper triangular matrix% Nov 26,2008%%%%%%%%%%%%%%%
来源:学生作业帮助网 编辑:六六作业网 时间:2024/11/09 02:10:16
英语翻译一、高斯消去法的程序:function [A,b]= Gauss(A,b);%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%use Gaussian elimination method to change 'A' into upper triangular matrix% Nov 26,2008%%%%%%%%%%%%%%%
英语翻译
一、高斯消去法的程序:
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
如题.翻译下注释就可以了
不要用在线翻译.稍微知道点的来回答下= =
英语翻译一、高斯消去法的程序:function [A,b]= Gauss(A,b);%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%use Gaussian elimination method to change 'A' into upper triangular matrix% Nov 26,2008%%%%%%%%%%%%%%%
一楼翻译是什么东西啊?直接复制到google在线里翻译出来,还累?我看别人要想看懂才真是累!给楼主翻译了下,如果楼主对高斯消去法比较了解的话就很容易懂.
%用高斯消去法把矩阵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中这些元素 A(k:n,1:k)
u=u+k-1;
%因为函数返回矩阵A(k:n,1:k)中最大元素,因此我们应该变换矩阵A的值,下面进行变换
p(k)=u; %用p(k)来记录u的值
%交换第k行和第u行的数据
t1 = A(k,k:n); %为了实现交换,定义一个中间变量t1
A(k,k:n) = A(u,k:n);
A(u,k:n) = t1;
t2 = b(k); %t2是一个临时变量
b(k) = b(u);
b(u) = t2;
%前面主要是对A进行变换,即在进行消去之前,第一次先比较A中第一列绝对值最大的元素,然后再将第一列中有最大元素的那行交换到第1行,
然后用下面方法进行消去,将除第一行外的元素的第一列都消去为0;第二次然后比较A中第二列元素(此时第一行不用参与比较),将最大元素那行
交换到第二行,将3,4,5…行的第二列也变为0;依此类推,直到把A变为上三角阵,这也是为什么下面的A(k,k) = 0不为0的原因(有0就可省去一步)
% 高斯消去法
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
% 计算矩阵 U
for k=2:n
A(k,1:k-1)=0;
end
二、求解三角方程组的程序:
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% 用转换为三角矩阵法来求解Ax=b
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
[m,n]=size(A); %获得A的行和列分别存入m和n中
%x(n)=b(n)/A(n,n); %计算x(n)
% 下面进行求解
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
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% 用高斯消去法求解线性方程 Ax=b
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
A = [ 1 3 6 8 9 2; %i输入矩阵 '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]; %i输入 'b'
b = b'; %转换 'b'
[A,b]= Gauss(A,b) %把[A b]变换为A为上三角阵的形式
%同时将变换后的'b'返还给b
b = b'
x= Eqn_Root(A,b) %通过三角阵方法求解
end