﻿ 130213025王颖洁作业8 - 计算数学达人 - 专，学者，数值代数，微分方程数值解

### 130213025王颖洁作业8

（1）

for n=5:20

for i=1:n

for j=1:n

a(i,j)=1/(i+j-1);

end

end

c=cond(a);

f=norm(c,inf);

fprintf('n=%3.0fnnorm(c,inf)%en',n,f)

end

n= 5

norm(c,inf)1.908432e+018

n= 6

norm(c,inf)1.908432e+018

n= 7

norm(c,inf)1.908432e+018

n= 8

norm(c,inf)1.908432e+018

n= 9

norm(c,inf)1.908432e+018

n=10

norm(c,inf)1.908432e+018

n=11

norm(c,inf)1.908432e+018

n= 12

norm(c,inf)1.908432e+018

n=13

norm(c,inf)1.908432e+018

n=14

norm(c,inf)1.908432e+018

n=15

norm(c,inf)1.908432e+018

n=16

norm(c,inf)1.908432e+018

n=17

norm(c,inf)1.908432e+018

n=18

norm(c,inf)1.908432e+018

n=19

norm(c,inf)1.908432e+018

n=20

norm(c,inf)1.908432e+018

（2）

function x=gauss(A,b)

[m,n]=size(A);

p=[];

tol=1e-14;

x=zeros(n,1);

if m==n

for k=1:n-1

[r,c]=find(A==max(max(abs(A(k:n,k:n)))));

p(k)=r(1);

A([k,p(k)],:)=A([p(k),k],:);

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

break;

end

end

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

U=triu(A,0)

for k=1:length(p)

b([k,p(k)])=b([p(k),k]);

end

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

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

for j=n-1:-1:1

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

end

else

'A is not a square!'

end

for n=5:20

A1=-1*ones(n,n);

A=tril(A1);

for i=1:n

A(i,i)=1;

end

A(:,n)=1;

x1=rand(n,1)

b=A*x1;

x=gauss(A,b)

r=b-A*x;

k=cond(A);

r1=k*norm(r,inf)/norm(b,inf)

end

x1 =

0.2077

0.3012

0.4709

0.2305

0.8443

x =

4.7939

4.4585

3.9576

2.7152

5.4304

x1 =

0.1948

0.2259

0.1707

0.2277

0.4357

0.3111

x =

-3.1560

-3.0464

-2.8825

-2.4976

-1.5198

-3.0397

x1 =

0.9234

0.4302

0.1848

0.9049

0.9797

0.4389

0.1111

x =

-79.9319

-78.6894

-76.4499

-71.2507

-60.7775

-40.3721

-80.7441

x1 =

0.2581

0.4087

0.5949

0.2622

0.6028

0.7112

0.2217

0.1174

x =

-75.3634

-74.8140

-73.5291

-71.2920

-66.4771

-56.7389

-37.7520

-75.5041

x1 =

0.2967

0.3188

0.4242

0.5079

0.0855

0.2625

0.8010

0.0292

0.9289

x =

70.2731

69.9597

69.4383

68.4791

66.1385

61.6343

53.1643

35.4526

70.9053

x1 =

0.7303

0.4886

0.5785

0.2373

0.4588

0.9631

0.5468

0.5211

0.2316

0.4889

x =

-374.7083

-373.9783

-372.4283

-369.6695

-363.9305

-351.9480

-328.3995

-281.3281

-187.4749

-374.9498

x1 =

0.6241

0.6791

0.3955

0.3674

0.9880

0.0377

0.8852

0.9133

0.7962

0.0987

0.2619

x =

-955.8101

-954.7687

-952.9697

-949.3997

-941.6392

-927.0685

-897.0795

-837.0735

-717.1785

-478.0861

-956.1723

x1 =

0.3354

0.6797

0.1366

0.7212

0.1068

0.6538

0.4942

0.7791

0.7150

0.9037

0.8909

0.3342

x =

1.0e+003 *

-1.0479

-1.0473

-1.0464

-1.0442

-1.0404

-1.0322

-1.0159

-0.9831

-0.9176

-0.7864

-0.5240

-1.0479

x1 =

0.6987

0.1978

0.0305

0.7441

0.5000

0.4799

0.9047

0.6099

0.6177

0.8594

0.8055

0.5767

0.1829

x =

1.0e+003 *

-3.2176

-3.2169

-3.2157

-3.2124

-3.2062

-3.1938

-3.1685

-3.1182

-3.0177

-2.8164

-2.4139

-1.6091

-3.2182

x1 =

0.2399

0.8865

0.0287

0.4899

0.1679

0.9787

0.7127

0.5005

0.4711

0.0596

0.6820

0.0424

0.0714

0.5216

x =

1.0e+003 *

-2.3656

-2.3650

-2.3646

-2.3634

-2.3614

-2.3566

-2.3472

-2.3287

-2.2916

-2.2178

-2.0697

-1.7740

-1.1826

-2.3653

x1 =

0.0967

0.8181

0.8175

0.7224

0.1499

0.6596

0.5186

0.9730

0.6490

0.8003

0.4538

0.4324

0.8253

0.0835

0.1332

x =

1.0e+004 *

-1.1763

-1.1763

-1.1761

-1.1758

-1.1752

-1.1741

-1.1718

-1.1672

-1.1580

-1.1396

-1.1028

-1.0293

-0.8822

-0.5882

-1.1763

x1 =

0.1734

0.3909

0.8314

0.8034

0.0605

0.3993

0.5269

0.4168

0.6569

0.6280

0.2920

0.4317

0.0155

0.9841

0.1672

0.1062

x =

1.0e+004 *

-1.9761

-1.9761

-1.9760

-1.9757

-1.9752

-1.9743

-1.9723

-1.9685

-1.9608

-1.9453

-1.9144

-1.8527

-1.7292

-1.4821

-0.9881

-1.9762

x1 =

0.3724

0.1981

0.4897

0.3395

0.9516

0.9203

0.0527

0.7379

0.2691

0.4228

0.5479

0.9427

0.4177

0.9831

0.3015

0.7011

0.6663

x =

1.0e+003 *

-4.4533

-4.4534

-4.4533

-4.4533

-4.4526

-4.4512

-4.4492

-4.4447

-4.4362

-4.4189

-4.3842

-4.3144

-4.1754

-3.8967

-3.3401

-2.2265

-4.4530

x1 =

0.5391

0.6981

0.6665

0.1781

0.1280

0.9991

0.1711

0.0326

0.5612

0.8819

0.6692

0.1904

0.3689

0.4607

0.9816

0.1564

0.8555

0.6448

x =

1.0e+004 *

-6.2829

-6.2829

-6.2828

-6.2826

-6.2822

-6.2814

-6.2799

-6.2768

-6.2707

-6.2584

-6.2339

-6.1848

-6.0866

-5.8903

-5.4976

-4.7122

-3.1415

-6.2829

x1 =

0.3763

0.1909

0.4283

0.4820

0.1206

0.5895

0.2262

0.3846

0.5830

0.2518

0.2904

0.6171

0.2653

0.8244

0.9827

0.7302

0.3439

0.5841

0.1078

x =

1.0e+005 *

-1.4874

-1.4874

-1.4874

-1.4873

-1.4873

-1.4872

-1.4870

-1.4867

-1.4859

-1.4845

-1.4816

-1.4758

-1.4642

-1.4409

-1.3944

-1.3015

-1.1155

-0.7437

-1.4874

x1 =

0.9063

0.8797

0.8178

0.2607

0.5944

0.0225

0.4253

0.3127

0.1615

0.1788

0.4229

0.0942

0.5985

0.4709

0.6959

0.6999

0.6385

0.0336

0.0688

0.3196

x =

1.0e+005 *

-6.8798

-6.8798

-6.8798

-6.8797

-6.8796

-6.8794

-6.8790

-6.8781

-6.8765

-6.8731

-6.8664

-6.8530

-6.8261

-6.7723

-6.6648

-6.4498

-6.0198

-5.1599

-3.4399

-6.8798

x1 =

0.5309

0.6544

0.4076

0.8200

0.7184

x =

0.5309

0.6544

0.4076

0.8200

0.7184

r1 =

2.9141e-016

x1 =

0.9686

0.5313

0.3251

0.1056

0.6110

0.7788

x =

0.9686

0.5313

0.3251

0.1056

0.6110

0.7788

r1 =

9.9997e-016

x1 =

0.4235

0.0908

0.2665

0.1537

0.2810

0.4401

0.5271

x =

0.4235

0.0908

0.2665

0.1537

0.2810

0.4401

0.5271

r1 =

5.4468e-015

x1 =

0.4574

0.8754

0.5181

0.9436

0.6377

0.9577

0.2407

0.6761

x =

0.4574

0.8754

0.5181

0.9436

0.6377

0.9577

0.2407

0.6761

r1 =

7.8812e-015

x1 =

0.2891

0.6718

0.6951

0.0680

0.2548

0.2240

0.6678

0.8444

0.3445

x =

0.2891

0.6718

0.6951

0.0680

0.2548

0.2240

0.6678

0.8444

0.3445

r1 =

4.1590e-015

x1 =

0.7805

0.6753

0.0067

0.6022

0.3868

0.9160

0.0012

0.4624

0.4243

0.4609

x =

0.7805

0.6753

0.0067

0.6022

0.3868

0.9160

0.0012

0.4624

0.4243

0.4609

r1 =

1.2317e-014

x1 =

0.7702

0.3225

0.7847

0.4714

0.0358

0.1759

0.7218

0.4735

0.1527

0.3411

0.6074

x =

0.7702

0.3225

0.7847

0.4714

0.0358

0.1759

0.7218

0.4735

0.1527

0.3411

0.6074

r1 =

7.6498e-014

x1 =

0.1917

0.7384

0.2428

0.9174

0.2691

0.7655

0.1887

0.2875

0.0911

0.5762

0.6834

0.5466

x =

0.1917

0.7384

0.2428

0.9174

0.2691

0.7655

0.1887

0.2875

0.0911

0.5762

0.6834

0.5466

r1 =

1.4340e-013

x1 =

0.4257

0.6444

0.6476

0.6790

0.6358

0.9452

0.2089

0.7093

0.2362

0.1194

0.6073

0.4501

0.4587

x =

0.4257

0.6444

0.6476

0.6790

0.6358

0.9452

0.2089

0.7093

0.2362

0.1194

0.6073

0.4501

0.4587

r1 =

1.5609e-013

x1 =

0.6619

0.7703

0.3502

0.6620

0.4162

0.8419

0.8329

0.2564

0.6135

0.5822

0.5407

0.8699

0.2648

0.3181

x =

0.6619

0.7703

0.3502

0.6620

0.4162

0.8419

0.8329

0.2564

0.6135

0.5822

0.5407

0.8699

0.2648

0.3181

r1 =

1.2507e-013

x1 =

0.1192

0.9398

0.6456

0.4795

0.6393

0.5447

0.6473

0.5439

0.7210

0.5225

0.9937

0.2187

0.1058

0.1097

0.0636

x =

0.1192

0.9398

0.6456

0.4795

0.6393

0.5447

0.6473

0.5439

0.7210

0.5225

0.9937

0.2187

0.1058

0.1097

0.0636

r1 =

8.6716e-014

x1 =

0.4046

0.4484

0.3658

0.7635

0.6279

0.7720

0.9329

0.9727

0.1920

0.1389

0.6963

0.0938

0.5254

0.5303

0.8611

0.4849

x =

0.4046

0.4484

0.3658

0.7635

0.6279

0.7720

0.9329

0.9727

0.1920

0.1389

0.6963

0.0938

0.5254

0.5303

0.8611

0.4849

r1 =

1.0697e-012

x1 =

0.3935

0.6714

0.7413

0.5201

0.3477

0.1500

0.5861

0.2621

0.0445

0.7549

0.2428

0.4424

0.6878

0.3592

0.7363

0.3947

0.6834

x =

0.3935

0.6714

0.7413

0.5201

0.3477

0.1500

0.5861

0.2621

0.0445

0.7549

0.2428

0.4424

0.6878

0.3592

0.7363

0.3947

0.6834

r1 =

5.8306e-012

x1 =

0.7040

0.4423

0.0196

0.3309

0.4243

0.2703

0.1971

0.8217

0.4299

0.8878

0.3912

0.7691

0.3968

0.8085

0.7551

0.3774

0.2160

0.7904

x =

0.7040

0.4423

0.0196

0.3309

0.4243

0.2703

0.1971

0.8217

0.4299

0.8878

0.3912

0.7691

0.3968

0.8085

0.7551

0.3774

0.2160

0.7904

r1 =

5.9397e-012

x1 =

0.9493

0.3276

0.6713

0.4386

0.8335

0.7689

0.1673

0.8620

0.9899

0.5144

0.8843

0.5880

0.1548

0.1999

0.4070

0.7487

0.8256

0.7900

0.3185

x =

0.9493

0.3276

0.6713

0.4386

0.8335

0.7689

0.1673

0.8620

0.9899

0.5144

0.8843

0.5880

0.1548

0.1999

0.4070

0.7487

0.8256

0.7900

0.3185

r1 =

4.7913e-012

x1 =

0.5341

0.0900

0.1117

0.1363

0.6787

0.4952

0.1897

0.4950

0.1476

0.0550

0.8507

0.5606

0.9296

0.6967

0.5828

0.8154

0.8790

0.9889

0.0005

0.8654

x =

0.5341

0.0900

0.1117

0.1363

0.6787

0.4952

0.1897

0.4950

0.1476

0.0550

0.8507

0.5606

0.9296

0.6967

0.5828

0.8154

0.8790

0.9889

0.0005

0.8654

r1 =

5.5612e-011