﻿ 130213003戴斌作业2 - 计算数学达人 - 专，学者，数值代数，微分方程数值解

### 130213003戴斌作业2

function [L,U]=gau(A,b)

n=size(A,1);

x=zeros(n,1);

tol=1e-16;

for k=1:n-1;

if A(k,k)>tol;

A(k+1:n,k)=A(k+1:n,k)/A(k,k);

A(k+1:n,k+1:n)=A(k+1:n,k+1:n)-A(k+1:n,k)*A(k,k+1:n);

else

stop

end

end

L=eye(n)+tril(A,-1);

U=triu(A,0);

b(1)=b(1)/L(1,1);

for j=2:n

b(j)=(b(j)-L(j,1:j-1)*b(1:j-1))/L(j,j);

end

b(n)=b(n)/U(n,n);

for j=n-1:-1:1

b(j)=(b(j)-U(j,j+1:n)*b(j+1:n))/U(j,j);

end

x=b

%%%%%%%%%test

A=diag(6*ones(1,84),0)+diag(ones(1,83),1)+diag(8*ones(1,83),-1)

b=15*ones(84,1);

b(1)=b(1)-8;

b(end)=b(end)-1

[L,U]=gau(A,b);

x =

1.0e+008 *

0.000000010000000

0.000000010000000

0.000000010000000

0.000000010000000

0.000000010000000

0.000000010000000

0.000000010000000

0.000000010000000

0.000000010000000

0.000000010000000

0.000000010000000

0.000000010000000

0.000000010000000

0.000000010000000

0.000000010000000

0.000000010000000

0.000000010000000

0.000000010000000

0.000000010000000

0.000000010000000

0.000000010000000

0.000000010000000

0.000000010000000

0.000000010000000

0.000000010000000

0.000000010000000

0.000000010000000

0.000000010000000

0.000000010000000

0.000000010000001

0.000000009999999

0.000000010000002

0.000000009999995

0.000000010000010

0.000000009999981

0.000000010000038

0.000000009999924

0.000000010000153

0.000000009999695

0.000000010000610

0.000000009998779

0.000000010002441

0.000000009995117

0.000000010009765

0.000000009980470

0.000000010039060

0.000000009921880

0.000000010156240

0.000000009687519

0.000000010624962

0.000000008750076

0.000000012499847

0.000000005000305

0.000000019999390

-0.000000009998779

0.000000049997559

-0.000000069995117

0.000000169990233

-0.000000309980464

0.000000649960918

-0.000001269921799

0.000002569843445

-0.000005109686279

0.000010249370117

-0.000020468730470

0.000040967421880

-0.000081904687519

0.000163838750076

-0.000327645000305

0.000655310001221

-0.001310550004883

0.002620970019531

-0.005241270078125

0.010480010312500

-0.020949751250000

0.041858575000000

-0.083553290000000

0.166451289999999

-0.330281269999999

0.650077449999998

-1.258214389999996

2.348666889999992

-4.026286069999986

5.368381449999981