北京理工数值分析作业_第1页
北京理工数值分析作业_第2页
北京理工数值分析作业_第3页
北京理工数值分析作业_第4页
北京理工数值分析作业_第5页
已阅读5页,还剩49页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

第一早

1.题

wc=lE-8;

i=l;

a(l,l)=5A(l/2);

a(l,2)=5A(l/4);

whileabs(a(l,i+l)-a(l,i))>wc

i=i+l;

a(1,i)=sqrt(a(1,i-1));

a(1,i+1)=sqrt(a(1,i));

fprintf('a(1,%d)=%12.10f\n',i,a(1,i));

end

fprintf。一共要计算%d次计算

结果

a(1,2)=1.4953487812

a(1,3)=1.2228445450

a(1,4)=1.1058230170

a(1,5)=1.0515811985

a(1,6)=1.0254663322

a(1,7)=1.0126531154

a(1,8)=1.0063066707

a(1,9)=1.0031483792

a(1,10)=1.0015729525

a(1,11)=1.0007861672

a(1,12)=1.0003930064

a(1,13)=1.0001964839

a(1,14)=1.0000982371

a(1,15)=1.0000491174

a(1,16)=1.0000245584

a(1,17)=1.0000122791

a(1,18)=1.0000061395

a(1,19)=1.0000030698

a(1,20)=1.0000015349

a(1,21)=1.0000007674

a(1,22)=1.0000003837

a(1,23)=1.0000001919

a(1,24)=1.0000000959

a(1,25)=1.0000000480

a(1,26)=1.0000000240

a(1,27)=1.0000000120

一共要进行27次计算

4题

Maltab代码:

当把区间[-10,10]分为100等份时

»x=-10:20/100:10;

»y=x;

»[x,y]=meshgrid(x,y);

»z=exp(-abs(x))+cos(x+y)+l./(xA2+yA2+l);

»mesh(z)

>>title('区间分成100等分的三维图像,);

»xlabel('x');

»ylabel('y');

»zlabel('z');

当把区间[-10,10]分为200等份时,

»x=-10:20/200:10;

»y=x;

»[x,y]=meshgrid(x,y);

»z=exp(-abs(x))+cos(x+y)+l./(xA2+yA2+l);

»mesh(z)

>>title('区间分成200等分的三维图像,);

»xlabel('x');

»ylabel('y');

»zlabel('z');

当把区间[-10,10]分为400等份时,编程如下,

»x=-10:20/400:10;

»y=x;

»[x,y]=meshgrid(x,y);

»z=exp(-abs(x))+cos(x+y)+l./(xA2+yA2+l);

»mesh(z)

>>title('区间分成400等分的三维图像,);

»xlabel('x');

»ylabel('y');

»zlabel('z')

第一早

1.题

a=-2*ones(1,8);

a(l,D=O;

b=5*ones(1,8);

b(l,1)=2;

c=-2*ones(1,7);

disp。请输入电压值V,)

V=input('V=')

disp。请输入电阻值R')

R=input('R=')

d=zeros(1,8);

d(l,1)=(V/R);

fori=2:8

a(l,i)=a(l,i)/b(l,i-l);

b(l,i)=b(l,i)-c(l,i-l)*a(l,i);

d(l,i)=d(l,i)-a(l,i)*d(l,i-l);

end

d(l,8)=d(l,8)/b(l,8);

fori=7:-1:1

d(l,i)=(d(l,i)-c(l,i)*d(l,i+l))/b(l,i);

end

disp(1电流值如下:1);

fori=l:8

disp([111int2str(i)1=1num2str(d(i))]);

㊀nd

fprintf(1\n1);

结果:

请输入电压值V

V=10

V=

10

请输入电阻值R

R=10

R

10

电流值如下:

II=0.99995

12=0.49995

13=0.24993

工4=0.12487

15=0.062254

16=0.030761

17=0.014648

18=0.0058592

3.题

改进的平方根法

formatrational

%A=[335;359;5917]

A=[4-2-4;-21710;-410

n=length(A);

L=zeros(n,n);

U=zeros(n,n);

sum=0;

forj=l:n

U(l,j)=A(l,j);

end

fori=2:n

end

forr=2:n

forj=r:n

fork=l:r-1

sum=sum+L(r,k)*U(k,j);

end

U(r,j)=A(r,j)-sum;

sum=0;

㊀nd

sum=0;

fori=r+l:n

fork=l:r-1

sum=sum+L(irk)*U(k,r);

end

L(i,r)=(A(i,r)-sum)/U(r,r);

sum=O;

end

sum=O;

end

L=L+eye(n);

U;

D=eye(n,n);

D=D.*U;

L*D*L'

结果:

A=

4-2-4

-21710

-4109

ans=

4-2-4

-21710

-4109

第二早

1题

%Jacobi迭代算法

function[x]=jacobi_zhao(A,b,x_0,e,N)

n=size(A,l);

M=eye(n)-eye(n)/diag(diag(A))*A;

g=eye(n)/diag(diag(A))*b;

out=[];

fork=l:N

x_l=M*x_0+g;

out=[out;kx_l'];

ifnorm(x_l-x_0)<e

break;

end

x_0=x_l;

end

x=x_l;

disp('kx

disp(out)

end

%G-S迭代算法

function[x]=G_S_zhao(A,b,x_0,e,N)

n=size(A,l);

L=-tril(A,-l);

U=-tril(A',-l)';

D=diag(diag(A));

out=[];

M=eye(n)/(D-L)*U;

g=eye(n)/(D-L)*b;

fork=l:N

x_l=M*x_0+g;

out=[out;kx_l'];

ifnorm(x_l-x_0)<e

break;

end

x_0=x_l;

end

x=x_l;

disp('kx,)

disp(out)

end

求解题目过程:

»A=[101234;19-12-3;2-173-5;32312-1;4-3-5-115]

A=

101234

19-12-3

2-173-5

32312-1

4-3-5-115

»b=[12;-27;14;-17;12]

b=

12

-27

14

-17

12

»xO=[O;O;O;O;O]

xO=

0

0

0

0

0

x=jacobi_zhao(A,b,xO,O.OOOO1,60);

kX

1.00001.2000-3.00002.0000-1.41670.8000

2.00001.2050-2.32962.4071-1.65000.4522

3.00001.2656-2.34902.3531-1.89370.7051

4.00001.2504-2.22332.6181-1.87110.6508

5.00001.1997-2.21532.5919-1.95900.7699

6.00001.1829-2.15342.7302-1.93120.7704

7.00001.1405-2.14212.7323-1.97190.8352

8.00001.1252-2.10652.8098-1.95830.8468

9.00001.0975-2.09542.8217-1.97880.8847

10.00001.0850-2.07382.8671-1.97350.8969

11.00001.0673-2.06452.8802-1.98430.9200

12.00001.0577-2.05092.9077-1.98280.9303

13.00001.0463-2.04372.9191-1.98870.9448

14.00001.0392-2.03502.9363-1.98860.9527

15.00001.0318-2.02972.9451-1.99200.9620

16.00001.0267-2.02412.9561-1.99240.9678

17.00001.0218-2.02032.9627-1.99440.9739

18.00001.0182-2.01652.9699-1.99490.9781

19.00001.0149-2.01382.9746-1.99610.9821

20.00001.0124-2.01132.9793-1.99660.9851

21.00001.0102-2.00942.9827-1.99730.9878

22.00001.0085-2.00772.9858-1.99770.9898

23.00001.0070-2.00642.9882-1.99810.9916

24.00001.0058-2.00532.9903-1.99840.9930

25.00001.0048-2.00442.9919-1.99870.9943

26.00001.0040-2.00362.9934-1.99890.9952

27.00001.0033-2.00302.9945-1.99910.9961

28.00001.0027-2.00252.9955-1.99930.9967

29.00001.0022-2.00212.9962-1.99940.9973

30.00001.0019-2.00172.9969-1.99950.9978

31.00001.0015-2.00142.9974-1.99960.9982

32.00001.0013-2.00122.9979-1.99970.9985

33.00001.0010-2.00102.9982-1.99970.9987

34.00001.0009-2.00082.9985-1.99980.9990

35.00001.0007-2.00072.9988-1.99980.9991

36.00001.0006-2.00052.9990-1.99980.9993

37.00001.0005-2.00042.9992-1.99990.9994

38.00001.0004-2.00042.9993-1.99990.9995

39.00001.0003-2.00032.9994-1.99990.9996

40.00001.0003-2.00032.9995-1.99990.9997

41.00001.0002-2.00022.9996-1.99990.9997

42.00001.0002-2.00022.9997-1.99990.9998

43.00001.0002-2.00012.9997-2.00000.9998

44.00001.0001-2.00012.9998-2.00000.9998

45.00001.0001-2.00012.9998-2.00000.9999

46.00001.0001-2.00012.9999-2.00000.9999

47.00001.0001-2.00012.9999-2.00000.9999

48.00001.0001-2.00012.9999-2.00000.9999

49.00001.0000-2.00002.9999-2.00000.9999

50.00001.0000-2.00002.9999-2.00001.0000

51.00001.0000-2.00002.9999-2.00001.0000

52.00001.0000-2.00003.0000-2.00001.0000

53.00001.0000-2.00003.0000-2.00001.0000

54.00001.0000-2.00003.0000-2.00001.0000

55.00001.0000-2.00003.0000-2.00001.0000

»x=G_S_zhao(A,b,xO,0.00001,60);

k

1.00001.2000-3.13331.2095-1.49680.1567

2.00001.6578-2.66491.8991-1.84870.3347

3.00001.5074-2.43412.2530-1.92320.5340

4.00001.3562-2.29502.4903-1.95130.6794

5.00001.2451-2.20162.6513-1.96720.7803

6.00001.1680-2.13792.7613-1.97760.8496

7.00001.1150-2.09442.8366-1.98470.8970

8.00001.0787-2.06462.8882-1.98950.9295

9.00001.0539-2.04422.9234-1.99280.9517

10.00001.0369-2.03032.9476-1.99510.9670

11.00001.0253-2.02072.9641-1.99660.9774

12.00001.0173-2.01422.9754-1.99770.9845

13.00001.0118-2.00972.9832-1.99840.9894

14.00001.0081-2.00672.9885-1.99890.9927

15.00001.0055-2.00462.9921-1.99930.9950

16.00001.0038-2.00312.9946-1.99950.9966

17.00001.0026-2.00212.9963-1.99970.9977

18.00001.0018-2.00152.9975-1.99980.9984

19.00001.0012-2.00102.9983-1.99980.9989

20.00001.0008-2.00072.9988-1.99990.9993

21.00001.0006-2.00052.9992-1.99990.9995

22.00001.0004-2.00032.9994-1.99990.9997

23.00001.0003-2.00022.9996-2.00000.9998

24.00001.0002-2.00022.9997-2.00000.9998

25.00001.0001-2.00012.9998-2.00000.9999

26.00001.0001-2.00012.9999-2.00000.9999

27.00001.0001-2.00002.9999-2.00000.9999

28.00001.0000-2.00002.9999-2.00001.0000

29.00001.0000-2.00003.0000-2.00001.0000

30.00001.0000-2.00003.0000-2.00001.0000

31.00001.0000-2.00003.0000-2.00001.0000

32.00001.0000-2.00003.0000-2.00001.0000

2.题

formatlong

A=[10,l,2,3,4;l,9,-l,2,-3;2,-l,7,3,-5;3,2,3,12,-l

;4,-3,-5,-l,15];

b=[12,-27,14,-17,12]';

N=200;

%A=[2,-l,0;-l,2,-l;0,-l,2];

%b=[1,0,1.8]';

w=l.4;

n=length(A);

x0=ones(n,1);

x=ones(n,0);

flag=l;

sum=0;

k=0;

whileflag==l

fori=l:n

forj=l:i

ifi-=j

sum=sum+A(i,j)*x(j,1);

else

continue;

end

㊀nd

form=j+1:n

sum=sum+A(i,m)*x0(m,1);

end

x(i,1)=(1-w)*x0(i,l)+w*(b(i,1)-sum)/A(i,i

sum=0;

㊀nd

k=k+l

x

ifk~=N

ifnorm(x-xO,inf)>wc

flag=l;

㊀Is㊀

flag=0;

end

else

fprintf(1ON'ip^xiz6piizu'IEy1);

flag=O;

end

xO=x;

㊀nd

结果:

k=

1

x=

-0.120000000000000

-4.270222222222222

1.993955555555556

-1.926165925925926

0.319874883950618

k=

2

X=

2.397383309432098

-1.806139972249109

2.157810899061290

-2.348433539283285

0.379099041230848

k=

3

x=

1.143765844014580

-2.412267015519451

2.785075064466581

-1.811963710490288

0.996504787835416

k=

4

x=

0.983372103734337

-1.926070677869254

2.991090011275371

-2.083934205973658

1.016314189039255

k=

5

X=

1.024912270897810

-2.001106816938999

3.060052436366378

-1.994002385812657

1.012448082134657

k=

6

x=

0.963885439875658

-1.980654782076844

3.003143406710068

-1.993920749912968

1.015954517083863

k=

x=

0.999369525058159

-2.001596919855795

3.010982410353194

-2.003820902469318

0.998174940186140

k=

8

x=

1.000027496390528

-1.997320103697281

2.996599498230785

-1.998129319911984

1.000057825553756

k=

9

x=

0.999747888509718

-2.002116712222330

2.999973120360280

-2.000149979306557

0.999451770078803

k=

10

x=

1.000774710670985

-1.999487187338363

2.999345187782558

-2.000165589181306

0.999752620171508

k=

11

x=

1.000009749539964

-2.000372428623808

3.000035513026520

-1.999891567193516

1.000017725229458

k=

12

x=

0.999982828636702

-1.999868296078108

2.999971669664657

-2.000056110499740

1.000017739845509

k=

13

X=

1.000009994586556

-2.000032908028784

3.000052158839111

-1.999989561310395

1.000005273570704

k=

14

x=

0.999978667365228

-1.999976191374097

2.999991441600386

-1.999998653709936

1.000008652904539

k=

15

x=

1.000002185129806

-2.000007575489729

3.000008879340478

-2.000001633960826

0.999997593108479

k=

16

X=

0.999999734424105

-1.999996162134237

2.999995895552294

-1.999998993213431

1.000000315065173

k=

17

x=

1.000000118887653

-2.000002358301658

3.000000833556922

-2.000000149042239

0.999999544347364

k=

18

x=

1.000000366974449

-1.999999150369042

2.999999323486351

-2.000000083451083

0.999999959658791

k=

19

x=

0.999999981326240

-2.000000435046371

3.000000200795130

-1.999999933557701

1.000000001200712

k=

20

x=

0.999999983575195

-1.999999812302289

2.999999925126745

-2.000000038278648

1.000000019693475

k=

21

x=

1.000000006305440

-2.000000066607681

3.000000056766253

-1.999999988924269

0.999999998643082

k=

22

x=

0.999999987016416

-1.999999966585965

2.999999981167382

-2.000000001249537

1.000000005840724

k=

23

x=

1.000000003042602

-2.000000013654010

3.000000010175650

-2.000000000259220

0.999999997429126

k=

24

X=

0.999999999393900

-1.999999993980330

2.999999994960771

-1.999999999624972

1.000000000623497

k=

25

x=

1.000000000304000

-2.000000003064747

3.000000001679621

-2.000000000056430

0.999999999557535

k=

26

x=

1.000000000108651

-1.999999998718656

2.999999999132353

-2.000000000062381

1.000000000084475

k=

27

X=

0.999999999998986

-2.000000000588518

3.000000000351665

-1.999999999950599

0.999999999970524

k=

28

x=

0.999999999980090

-1.999999999735918

2.999999999860998

-2.000000000029200

1.000000000025574

k=

29

x=

1.000000000007856

-2.000000000107458

3.000000000074061

-1.999999999988933

0.999999999992344

k=

30

x=

0.999999999990804

-1.999999999951082

2.999999999969541

-2.000000000002855

1.000000000005712

k=

31

x=

1.000000000003359

-2.000000000021274

3.000000000014010

-1.999999999999307

0.999999999997107

第四章

1.塞法

cl㊀ar;

A=[19066-8430;6630342-36;336-168147-112;30

-3628291];

x0=[0001]1;

tol=10A(-6);

nmax=100;

k=l;u=0;lm=0;

whil㊀k<=nmax

xr=norm(xO,inf);

a=xr;

y=x0/a;

x=A*y;

lm=xr;

ifabs(Im-u)<tol;

break;

㊀nd

k=k+l;

u=lm;

x0=x;

end

Im,ul=xO

运行结果:

Im=

343.0000

ul=

-114.3333

-343.0000

0.0000

171.5002

结果分析:

按模最大特征向量为

-114.3333-343.00000.0000171.5002

按模最大特征值为

343.0000

2.题反塞法

formatlong

%A=[19066-8430;

%6630342-36;

%336-168147-112;

%30-3628291];

A=[2-10;02-1;0-12];

ep=lE-8;

N=200;

k=0;

lamda0=0;

x0=[001]';

flag=l;

a=max(abs(xO(:,1)));

whileflag==l

k=k+l

y=xO./a;

x=A*y

a=max(abs(x(:,1)));

lamda=a;

ifk<N

ifabs(lamda-lamdaO)>ep

flag=l;

else

flag=O;

end

else

flag=O;

fprintf('ON'fx6pii"uzIEy');

end

lamdaO=lamda;

xO=x;

end

结果:

k=

1

x=

0

-1

2

k=

2

x=

0.500000000000000

-2.000000000000000

2.500000000000000

k=

3

x=

1.200000000000000

-2.600000000000000

2.800000000000000

k=

4

x=

1.785714285714286

-2.857142857142858

2.928571428571429

k=

5

x=

2.195121951219512

-2.951219512195122

2.975609756097561

k=

6

x=

2.467213114754098

-2.983606557377049

2.991803278688525

k=

7

x=

2.646575342465753

-2.994520547945205

2.997260273972603

k=

8

x=

2.765082266910421

-2.998171846435100

2.999085923217550

k=

9

x=

2.843645230112770

-2.999390429747028

2.999695214873514

k=

10

x=

2.895854501117659

-2.99979678927

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论