关于matlab高斯消去法,翻译下注释就可以了,在线等
一、高斯消去法的程序:function[A,b]=Gauss(A,b);%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%...
一、高斯消去法的程序:
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
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
[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
如题。。。翻译下注释就可以了
不要用在线翻译。。。稍微知道点的来回答下= = 展开
2个回答
展开全部
一楼翻译是什么东西啊?直接复制到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
%用高斯消去法把矩阵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
展开全部
use Gaussian elimination method to change 'A' into upper triangular matrix
用高斯消去法改变'甲'到上三角矩阵
get the size of matrix 'A'
获取矩阵的大小'甲'
column pivotal elimination method
列关键消除法
select the maximum element into the kth %column of matrix A
选择到第k最大元素%列矩阵A
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
因为函数返回的最大最大值指数
对甲(金:无,1:十一),所以我们要变的价值是高斯消去法
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
P(下十一)= ü;%记录指数ü
%k的交流和U行
t1 =甲(金,钾:不适用);%的临时变量t1
甲(金,钾:不适用)=甲(ü,钾:n)的;
甲(ü,钾:不适用)= T1处理器
乃=乙(十一);%的临时变量t2
乙(十一)=的B(U);
的B(U)= t2;
%高斯消去法
如果A(金,十一)〜= 0
行= k +1的:无
甲(行,钾)=甲(行,钾)/阿(金,k)的;
甲(行,行)=甲(行,行)阿(行,k)的*甲(金,k)的;
蜇(行,行)=甲(行,行);
二
function x= Eqn_Root(A,b);函数x = Eqn_Root(甲,乙);
Nov 26,2008 26,2008年11月
[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);
use the Gauss method to solve the linear equations Ax=b
% Nov 26, 2008
使用高斯方法来求解线性方程组Ax = b的
%08年11月26日
end
x(i) = (b(i)-t)/A(i,i);
译:
[的m,n] =大小(A组);%获取矩阵的大小'甲'
%×(n)的二B(北)/阿(不适用,n)的;%计算×(n)的
%计算解决方案
对于i =信噪比:-1:1
t = 0时;
办理J = ñ:-1:我一
吨=吨+ A(一,十)* ×(j)条;
末端
×(一)=(b(一)-吨)/阿(一,一);
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
阿= [1 3 6 8 9 2%的投入的价值,'甲'
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];
乙= [2 -3 2 55 16 -6];%投入的'b值'
b = b的';%采取'转b'
[甲,乙] =高斯(甲,乙)%,改变矩阵'甲'到上三角矩阵
%的回报率的新数组的B
b = b的'
x = Eqn_Root(甲,乙)%计算上设置三角quations
结束
好累啊,很难翻译,但运用您强大的思维理解能力应该能知道大概意思 呼呼~~
用高斯消去法改变'甲'到上三角矩阵
get the size of matrix 'A'
获取矩阵的大小'甲'
column pivotal elimination method
列关键消除法
select the maximum element into the kth %column of matrix A
选择到第k最大元素%列矩阵A
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
因为函数返回的最大最大值指数
对甲(金:无,1:十一),所以我们要变的价值是高斯消去法
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
P(下十一)= ü;%记录指数ü
%k的交流和U行
t1 =甲(金,钾:不适用);%的临时变量t1
甲(金,钾:不适用)=甲(ü,钾:n)的;
甲(ü,钾:不适用)= T1处理器
乃=乙(十一);%的临时变量t2
乙(十一)=的B(U);
的B(U)= t2;
%高斯消去法
如果A(金,十一)〜= 0
行= k +1的:无
甲(行,钾)=甲(行,钾)/阿(金,k)的;
甲(行,行)=甲(行,行)阿(行,k)的*甲(金,k)的;
蜇(行,行)=甲(行,行);
二
function x= Eqn_Root(A,b);函数x = Eqn_Root(甲,乙);
Nov 26,2008 26,2008年11月
[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);
use the Gauss method to solve the linear equations Ax=b
% Nov 26, 2008
使用高斯方法来求解线性方程组Ax = b的
%08年11月26日
end
x(i) = (b(i)-t)/A(i,i);
译:
[的m,n] =大小(A组);%获取矩阵的大小'甲'
%×(n)的二B(北)/阿(不适用,n)的;%计算×(n)的
%计算解决方案
对于i =信噪比:-1:1
t = 0时;
办理J = ñ:-1:我一
吨=吨+ A(一,十)* ×(j)条;
末端
×(一)=(b(一)-吨)/阿(一,一);
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
阿= [1 3 6 8 9 2%的投入的价值,'甲'
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];
乙= [2 -3 2 55 16 -6];%投入的'b值'
b = b的';%采取'转b'
[甲,乙] =高斯(甲,乙)%,改变矩阵'甲'到上三角矩阵
%的回报率的新数组的B
b = b的'
x = Eqn_Root(甲,乙)%计算上设置三角quations
结束
好累啊,很难翻译,但运用您强大的思维理解能力应该能知道大概意思 呼呼~~
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询