home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ARM Club 3
/
TheARMClub_PDCD3.iso
/
hensa
/
maths
/
matlab_1
/
Scripts
/
LinEqns
next >
Wrap
Text File
|
1994-03-24
|
1KB
|
36 lines
// function - call with matrices A and B for solution X of AX=B
disp(['solution of the linear equation AX=B'])
A
B
T1=['the system is determinate with solution:'];
T2=['the system is over-determined:'];
T3=['least-squares solution:'];
T4=['the system is under-determined:'];
T5=['the solution is not unique:'];
T6=['minimal length solution:'];
T7=['any multiple(s) of the following'];
T8=['ortho-normal vector(s) can be added:'];
[M,N]=size(A); [U,S,V]=svd(A); S=diag(S); R=0;
tol=size(S)*S(1)*eps;
for I=1:size(S), if S(I)>tol, R=R+1; end
if R=0, disp(['rank(A)=0: return']), return
if R>0, disp(['rank(A)']),R
S=diag(ones(R,1)./S(1:R));
P=V(:,1:R)*S*U(:,1:R)';
PCOND=S(1,1)\S(R,R);
PCOND
X=P*B;
if M=N, if R=M, disp(T1), X
if M=N, if R<M, disp(T2), disp(T3), X
if M>N, if R=N, disp(T2), X
if M>N, if R<N, disp(T2), disp(T3), X
if M>N, if R<N, disp(T7), disp(T8), ONV=V(:,(R+1):N); ONV
if M<N, if R=M, disp(T4), disp(T5), disp(T6), X
if M<N, if R<M, disp(T2), disp(T3), X
if M<N, disp(T7), disp(T8), ONV=V(:,(R+1):N); ONV
disp(['check C=AX-B'])
C=A*X-B; C
if M>N, if R<N, disp(['check C=A*ONV']), C=A*ONV; C
if M<N, disp(['check C=A*ONV']), C=A*ONV; C
return