Why?
Ax=b是数值分析的基础,没有几个算法里面不需要解线性方程组的。
Linear, algebraic equations occur in almost all branches of numerical analysis. But their most visible application in engineering is in the analysis of linear systems (any
system whose response is proportional to the input is deemed to be linear). Linear systems include structures, elastic solids, heat flow, seepage of fluids, electromagnetic fields and electric circuits; i.e.,most topics taught in an engineering curriculum.
If the system is discrete, such as a truss(
桁架(truss)是以剛性直桿為材料,在桿件之兩端以平滑之銷釘結合(pin joint)而成之剛性構架。在工程上運用甚廣,且具實用性及經濟性。桁架之桿件稱為構件(member),接合點亦稱為節點。實際上桁架之節點是用焊接而成,但為簡化設計,各直桿端部均假設以光滑銷釘連接,故各直桿均以二力桿件處理。) or an electric circuit, then its analysis leads directly to linear algebraic equations. In the case of a statically determinate truss, for example, the equations arise when the equilibrium conditions of the joints are written down. The unknowns x1, x2, . . . , xn represent the forces in the members and the support reactions, and the constants b1, b2, . . . , bn are the prescribed external
loads.
The behavior of continuous systems is described by differential equations, rather than algebraic equations. However, because numerical analysis can deal only with discrete variables, it is first necessary to approximate a differential equation with a
system of algebraic equations. The well-known
finite difference, finite element and boundary element methods of analysis work in this manner. They use different approximations to achieve the “discretization,”but in each case the final task is the same:
solve a system(often a very large system) of linear, algebraic equations.
In summary, the modeling of linear systems invariably gives rise to equations of the form Ax = b, where b is the input and x represents the response of the system.
The coefficient matrix A, which reflects the characteristics of the system, is independent of the input. In other words, if the input is changed, the equations have to be solved again with a different b, but the same A. Therefore, it is desirable to have
an equation-solving algorithm that can handle any number of constant vectors with minimal computational effort.
解Ax=b的法子大概可分为两类,
1 直接法
2 迭代法
Overview of Direct Methods
Table 2.1 lists three popular direct methods, each of which uses elementary operations to produce its own final form of easy-to-solve equations.
Method Initial form Final formGauss elimination Ax = b Ux = cLU decomposition Ax = b LUx = bGauss–Jordan elimination Ax = b Ix = c
LU法的优点是,对于某一个特定的A,当b变动时,仅需要forward substitution 和 back substitution就可以得到解。
function A = LUdec(A)
%Dolittle's decomposition
%returns A=[L\U]
%USAGE: A = LUdec(A)
n = size(A,1);
for i =1:n-1
for j =i+1:n
if(A(j,i))
l = A(j,i)/A(i,i);
A(j,i+1:n)= A(j,i+1:n)- l*A(i,i+1:n);
A(j,i)= l;
end
end
end
function x = LUsol(A,b)
% first call LUdec to decompose A=L*U
% then, Solves L*U*b = x by first forward substitution
% and finally back substitution
% USAGE: x = LUsol(A,b)
A = LUdec(A);
n=size(A,1);
for i = 2:n
b(i,:)= b(i,:) - A(i,1:i-1)*b(1:i-1,:);
end
for k = n:-1:1
b(k,:) = (b(k,:) - A(k,k+1:n)*b(k+1:n,:))/A(k,k);
end
x=b;
上面两个函数实现了LU分解和用LU的结果解方程。注意这里的代码可以解决Ax=b,当b不止一列的情形。