由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Programming版 - a MatLab question
相关主题
python 小问题error of opening a file located in a remote server from pyt (转载)
一个矩阵分解的问题(对称实矩阵)perl 匹配问题
c++ private 问题正则表达式里括号的转义好乱
perl 的问题store "" in c string
return Triangular_iterator( _beg_pos );意思How does matlab optimization deal with singular matrix?
请问C++返回值和返回引用区别Source code for graph algorithms?
Python没有for loop问个简单的matrix变换的问题,包子答谢
入门问题,perl里s@\_@@g 是什么意思?我不太理解unit testable,有人能解释一下什么是unit testable吗?
相关话题的讨论汇总
话题: na话题: ab话题: gauss话题: eq话题: nb
进入Programming版参与讨论
1 (共1页)
t********n
发帖数: 611
1
Can't run this Gauss elimination program. Got error message : not enough
input arguments.
function x = gauss(A,B)
%The sizes of matrices A,B are supposed to be NA x NA and NA x NB.
%This function solves Ax = B by Gauss elimination algorithm.
NA = size(A,2); [NB1,NB] = size(B);
if NB1 ~= NA, error(’A and B must have compatible dimensions’); end
N = NA + NB; AB = [A(1:NA,1:NA) B(1:NA,1:NB)]; % Augmented matrix
epss = eps*ones(NA,1);
for k = 1:NA
%Scaled Partial Pivoting at AB(k,k) by Eq.(2.2.20)
[akx,kx] = max(abs(AB(k:NA,k))./ ...
max(abs([AB(k:NA,k + 1:NA) epss(1:NA - k + 1)]’))’);
if akx < eps, error(’Singular matrix and No unique solution’); end
mx = k + kx - 1;
if kx > 1 % Row change if necessary
tmp_row = AB(k,k:N);
AB(k,k:N) = AB(mx,k:N);
AB(mx,k:N) = tmp_row;
end
% Gauss forward elimination
AB(k,k + 1:N) = AB(k,k+1:N)/AB(k,k);
AB(k,k) = 1; %make each diagonal element one
for m = k + 1: NA
AB(m,k+1:N) = AB(m,k+1:N) - AB(m,k)*AB(k,k+1:N); %Eq.(2.2.5)
AB(m,k) = 0;
end
end
%backward substitution for a upper-triangular matrix eqation
% having all the diagonal elements equal to one
x(NA,:) = AB(NA,NA+1:N);
for m = NA-1: -1:1
x(m,:) = AB(m,NA + 1:N)-AB(m,m + 1:NA)*x(m + 1:NA,:); %Eq.(2.2.7)
end
%do_gauss
A = [0 1 1;2 -1 -1;1 1 -1]; b = [2 0 1]’; %Eq.(2.2.8)
x = gauss(A,b)
x1 = A\b %for comparison with the result of backslash operation
Can anyone help me?? THanks!!!
1 (共1页)
进入Programming版参与讨论
相关主题
我不太理解unit testable,有人能解释一下什么是unit testable吗?return Triangular_iterator( _beg_pos );意思
下一个big thing,来了却不见你们讨论请问C++返回值和返回引用区别
Business Analyst (greater Los Angeles)Python没有for loop
为什么超快棋入门问题,perl里s@\_@@g 是什么意思?
python 小问题error of opening a file located in a remote server from pyt (转载)
一个矩阵分解的问题(对称实矩阵)perl 匹配问题
c++ private 问题正则表达式里括号的转义好乱
perl 的问题store "" in c string
相关话题的讨论汇总
话题: na话题: ab话题: gauss话题: eq话题: nb