数学软件实验报告实验二.docx

上传人:b****0 文档编号:17624923 上传时间:2023-07-27 格式:DOCX 页数:27 大小:75.33KB
下载 相关 举报
数学软件实验报告实验二.docx_第1页
第1页 / 共27页
数学软件实验报告实验二.docx_第2页
第2页 / 共27页
数学软件实验报告实验二.docx_第3页
第3页 / 共27页
数学软件实验报告实验二.docx_第4页
第4页 / 共27页
数学软件实验报告实验二.docx_第5页
第5页 / 共27页
数学软件实验报告实验二.docx_第6页
第6页 / 共27页
数学软件实验报告实验二.docx_第7页
第7页 / 共27页
数学软件实验报告实验二.docx_第8页
第8页 / 共27页
数学软件实验报告实验二.docx_第9页
第9页 / 共27页
数学软件实验报告实验二.docx_第10页
第10页 / 共27页
数学软件实验报告实验二.docx_第11页
第11页 / 共27页
数学软件实验报告实验二.docx_第12页
第12页 / 共27页
数学软件实验报告实验二.docx_第13页
第13页 / 共27页
数学软件实验报告实验二.docx_第14页
第14页 / 共27页
数学软件实验报告实验二.docx_第15页
第15页 / 共27页
数学软件实验报告实验二.docx_第16页
第16页 / 共27页
数学软件实验报告实验二.docx_第17页
第17页 / 共27页
数学软件实验报告实验二.docx_第18页
第18页 / 共27页
数学软件实验报告实验二.docx_第19页
第19页 / 共27页
数学软件实验报告实验二.docx_第20页
第20页 / 共27页
亲,该文档总共27页,到这儿已超出免费预览范围,如果喜欢就下载吧!
下载资源
资源描述

数学软件实验报告实验二.docx

《数学软件实验报告实验二.docx》由会员分享,可在线阅读,更多相关《数学软件实验报告实验二.docx(27页珍藏版)》请在冰点文库上搜索。

数学软件实验报告实验二.docx

数学软件实验报告实验二

数学软件实验报告

学院名称:

理学院专业年级:

姓名:

学号:

课程:

数学软件实验报告日期:

2014年10月25日

实验二MATLAB的基本数值运算

一.实验目的

MATLAB具有非常强大的数值计算能力,对各种常量(包括一般常量和固定常量)、各种变量(包括数值变量、字符变量、单元形变量和结构变量)熟悉其用法,向量及其运算,矩阵及其运算,数组及其运算,多项式及其各种运算,线性方程组的求解,数值统计的基本函数及其应用,简单插值函数,简单优化函数,微分方程数值解的基本函数等。

二.实验要求

理解常量、变量、向量、矩阵、多项式等概念,掌握向量在MATLAB中的表示,熟练掌握矩阵及其运算,数组及其运算,多项式运算,线性方程组求解,了解数值统计的基本函数,简单插值函数,简单优化函数,微分方程数值解的基本函数等。

三.实验内容

实验一:

第二节MATLAB基本数学运算

一:

简单矩阵的建立与矩阵元素

(1)直接输入矩阵

>>a=[123;456;789]

a=

123

456

789

(2)通过语句或者函数产生矩阵

>>b=sin(a)

b=

0.84150.90930.1411

-0.7568-0.9589-0.2794

0.65700.98940.4121

>>c=a+0.1*(1+b/2)

c=

1.14212.14553.1071

4.06225.05216.0860

7.13288.14959.1206

>>d=ones(3)+eye(3)

d=

211

121

112

(3)利用文件创建矩阵

loadfilel.txt

>>filel

filel=

123

456

789

(4)从外部数据文件中装入已有矩阵

loadfilel.txt

>>x=[-1.3sqrt(3)(1+2+3)*4/5]

x=

-1.30001.73214.8000

定义或修改某一元素

loadfilel.txt

>>x(5)=abs(x

(1))

x=

-1.30001.73214.800001.3000

小矩阵生成大矩阵

loadfilel.txt

>>e=[a,b]

e=

1.00002.00003.00000.84150.90930.1411

4.00005.00006.0000-0.7568-0.9589-0.2794

7.00008.00009.00000.65700.98940.4121

>>e=[a,d]

e=

123211

456121

789112

大矩阵抽取元素变为小矩阵f=e(:

[2,5])

f=

21

52

81

2:

常量,变量与表达式

t='howaboutthischaracterstring'

t=

howaboutthischaracterstring

>>v='Ican''tfindthelitter'

v=

Ican'tfindthelitter

>>A='Hello'

A=

Hello

>>B=2*A

B=

144202216216222

3:

命令窗口常用的命令与标点符号的使用

helpcd

CDChangecurrentworkingdirectory.

CDdirectory-specsetsthecurrentdirectorytotheonespecified.

CD..movestothedirectoryabovethecurrentone.

CD,byitself,printsoutthecurrentdirectory.

WD=CDreturnsthecurrentdirectoryasastring.

UsethefunctionalformofCD,suchasCD('directory-spec'),

whenthedirectoryspecificationisstoredinastring.

Seealsopwd.

Overloadedmethods:

ftp/cd

ReferencepageinHelpbrowser

doccd

二:

算数运算

1:

加减法运算a=[12;34];b=ones

(2);c=a+b

c=

23

45

>>d=[123];e=a+d

?

?

?

Errorusing==>plus

Matrixdimensionsmustagree.

>>c1=c-1

c1=

12

34

2:

乘除法运算

f=a*b

f=

33

77

>>g=b*a

g=

46

46

>>h=pi*a

h=

3.14166.2832

9.424812.5664

>>F=a.*c

F=

26

1220

>>G=c.*a

G=

26

1220

>>a=[123;426;749]b=[412]a*x=b

?

?

?

a=[123;426;749]b=[412]a*x=b

|

Error:

UnexpectedMATLABexpression.

四a=rand(3),b=rand(3),

a=

0.81470.91340.2785

0.90580.63240.5469

0.12700.09750.9575

b=

0.96490.95720.1419

0.15760.48540.4218

0.97060.80030.9157

>>A1=a/b

A1=

0.75710.33560.0323

0.2462-0.43410.7590

-0.94460.40931.0035

>>A2=a\b

A2=

-2.5775-1.3591-0.0618

3.03652.0130-0.0863

1.04620.81100.9734

>>A3=b\a

A3=

-1.8233-1.1435-0.2172

2.73672.19610.3685

-0.3205-0.60060.9537

>>A4=b/a

A4=

0.83060.3601-0.2991

1.0730-0.87950.6307

0.34420.69780.4577

>>A5=(a'/b')'

A5=

-1.8233-1.1435-0.2172

2.73672.19610.3685

-0.3205-0.60060.9537

>>A6=a.\b

A6=

1.18431.04790.5095

0.17400.76760.7712

7.64338.20460.9564

>>A7=a.\b

A7=

1.18431.04790.5095

0.17400.76760.7712

7.64338.20460.9564

>>A8=1./A7

A8=

0.84440.95421.9628

5.74691.30281.2967

0.13080.12191.0456

3.乘幂运算

g=[1234;5678;9101112]

g=

1234

5678

9101112

>>g=[1234;5678;9101112];

>>g.^2%对g中的元素求平方

ans=

14916

25364964

81100121144

>>h=[1111;2222;3333];

>>g.^(h-1)%求以g元素为底,以h中相应元素减一为幂指数产生的矩阵

ans=

1111

5678

81100121144

>>2.^g%以2为底,以中相应元素为幂指数产生的矩阵

ans=

24816

3264128256

512102420484096

4:

转置运算

x=[123;456;789]

x=

123

456

789

>>y=x'

y=

147

258

369

>>a=[1+2i2-3i;4+5i5-6i]

a=

1.0000+2.0000i2.0000-3.0000i

4.0000+5.0000i5.0000-6.0000i

>>b=a'

b=

1.0000-2.0000i4.0000-5.0000i

2.0000+3.0000i5.0000+6.0000i

>>b=a.'

b=

1.0000+2.0000i4.0000+5.0000i

2.0000-3.0000i5.0000-6.0000i

>>conj(a')

ans=

1.0000+2.0000i4.0000+5.0000i

2.0000-3.0000i5.0000-6.0000i

三:

关系运算与逻辑运算

1:

关系运算

a=[-124;548];b=[015;512];

>>c=a>b

c=

010

011

2.逻辑运算

(1)逻辑运算与(&)a=[-124;548];b=[015;512];

>>c=a&b

c=

011

111

(2)逻辑运算与(|)

c=a|b

c=

111

111

(3)逻辑非

>c=~a

c=

000

000

四:

建立特殊数据组

1.用特殊函数建立数组

2.用小数组建大数组

a=[12;34]

a=

12

34

>>b=[a,eye(2,3);ones(3,2),rand(3)]

b=

1.00002.00001.000000

3.00004.000001.00000

1.00001.00000.79220.03570.6787

1.00001.00000.95950.84910.7577

1.00001.00000.65570.93400.7431

3.利用冒号建立数组

x=1:

5

x=

12345

>>y=0:

pi/4:

pi

y=

00.78541.57082.35623.1416

>>z=6:

-1:

1

z=

654321

>>a=0:

0.2:

1;b=exp(-a).*sin(a);[a',b']

ans=

00

0.20000.1627

0.40000.2610

0.60000.3099

0.80000.3223

1.00000.3096

4.空数组

x=[]

x=

[]

>>y=1:

-3

y=

Emptymatrix:

1-by-0

>>a=[123;456]

a=

123

456

>>a(:

3)=[]

a=

12

45

>>

实验四

第一节

1、由文件生成和保存矩阵

>>clear%清除当前工作空间中的变量

>>myfile%执行M文件

A=

34-11-910

65074-16

1-47-16-8

2-45-612-8

-36-78-11

8-49130

>>who%查看工作空间中的变量

Yourvariablesare:

A

>>loadtxefile.txt%装入txtfile.txt文件

>>who

Yourvariablesare:

A

>>savematfile%保存工作空间变量到matfile.mat文件中

>>clear

>>who

>>loadmatfile

>>who

Yourvariablesare:

A

>>txtfile%显示变量txtfile的内容

2、由函数生成矩阵

>>eye(5,6)

ans=

100000

010000

001000

000100

000010

>>eye(5)

ans=

10000

01000

00100

00010

00001

>>ones(8)

ans=

11111111

11111111

11111111

11111111

11111111

11111111

11111111

11111111

>>zeros(4)

ans=

0000

0000

0000

0000

>>rand(3)

ans=

0.81470.91340.2785

0.90580.63240.5469

0.12700.09750.9575

>>diag(4)

ans=

4

3、符号矩阵的创建

>>exam=sym('[1,x/a,sin(x);y/x,1+1/y,tan(x/y);1=0,3+3,4*r]')

?

?

?

Errorusing==>sym.symat198

Errorusing==>sym.symat165

Errorusing==>maplemex

`;`unexpected

>>symsxyzabc

f=a*x^2+b*x+c;

g=x*y*z;

h=(f+g)*b/a;

e1=sym('a*x^2+b*x+c=0');

>>e2=sym('x*y*z=0');

>>e3=sym('h=0');M=[123x

fghy

e1e2e3z]

M=

[1,2,3,x]

[]

[2]

[2b(ax+xyz+bx+c)]

[ax+bx+c,zyx,--------------------------,y]

[a]

[]

[2]

[ax+bx+c=0,zyx=0,h=0,z]

>>symsxycr

a=sin((c+(r-1)*3));

b=exp(r+(c-1)*4);

c=(c+(r-1)*3)*x+(r+(c-1)*4)*y;

A=symmat(3,3,a)

forC=

123

4、矩阵的修改

>>A=rand(5)

A=

0.81470.09750.15760.14190.6557

0.90580.27850.97060.42180.0357

0.12700.54690.95720.91570.8491

0.91340.95750.48540.79220.9340

0.63240.96490.80030.95950.6787

>>A([13],:

)=[]

A=

0.90580.27850.97060.42180.0357

0.91340.95750.48540.79220.9340

0.63240.96490.80030.95950.6787

>>A(2:

3,2:

3)=eye

(2)

A=

0.90580.27850.97060.42180.0357

0.91341.000000.79220.9340

0.632401.00000.95950.6787

二:

矩阵与向量的基本运算

(1)矩阵的运算

A+txtfile%矩阵加法

ans=

4637-1212

131416212-23

9727011-2

1211337111

9252933-824

10015-235

>>A-txtfile%矩阵减法

ans=

22-5-5-68

-1-4-1612-4-9

-7-15-13-21-14

-8-19-23-1913-17

-15-13-43-176-22

6-8343-5

>>A*txtfile%矩阵乘法

ans=

-55-85-180-24580-176

127174348250-1352

75110220194-41161

82129260283-91244

53761382121-36

98151284165-33176

>>3*A+7*txtfile%数乘矩阵

ans=

16262545-4844

6778112-1468-97

596516145318

7693211732939

75151231199-52164

381669-18935

>>A'%矩阵转置

ans=

3612-38

45-4-46-4

-1075-79

17-1-681

-94612-13

10-16-8-810

>>txtfile/m%矩阵右除

ans=

0.9337-0.16871.5921-0.23830.79380.0596

5.9273-0.01625.51383.03711.8754-2.0808

7.2759-0.76216.98453.31423.4372-1.5695

9.1056-1.047110.17982.79084.9550-1.4914

11.3503-1.909213.25372.78277.2407-0.9615

2.8057-0.32722.31541.34100.9586-0.8219

>>A\txtfile%矩阵左除

ans=

-2.1783-3.1414-6.0051-3.21050.1122-3.2168

5.09447.534814.29527.7724-0.75155.6699

3.68945.400010.14104.52990.01134.5038

0.23440.48580.80270.2483-0.27441.5049

2.12163.39506.38344.2520-1.24363.7915

0.97061.67543.16242.7091-1.12372.6093

det(A)

ans=

245295

det(txtfile)

ans=

0

inv(A)%求逆矩阵

ans=

-0.07370.0604-0.22970.0067-0.08040.1042

0.31420.00360.24080.16050.1259-0.1436

0.2099-0.03950.31550.03640.0834-0.0663

-0.0827-0.01230.0088-0.07770.07790.0878

0.0134-0.0335-0.01590.11290.10610.0337

0.0377-0.0525-0.01100.04690.06980.0411

>>pinv(txtfile)%求广义逆矩阵

ans=

-0.0187-0.00220.0340-0.00840.0040-0.0398

0.03630.0274-0.05640.0272-0.00920.0849

0.02140.0265-0.02750.0221-0.00370.0387

-0.0247-0.02170.0469-0.01100.0244-0.1694

-0.1294-0.05470.2146-0.08050.0231-0.2439

-0.0621-0.06590.0926-0.05160.0248-0.0000

矩阵的迹,翻书,条件数与秩:

trace(A)

ans=

8

>>trace(txtfile)

ans=

41

>>norm(A)

ans=

28.5398

>>norm(A,1)

ans=

43

cond(A)

ans=

18.6569

>>cond(A,1)

ans=

35.3343

>>rank(A)

ans=

6

>>rank(txtfile)

ans=

4

第二节;解线性方程组

(1)其次线性方程组的求解

A为奇次线性方程组对应的系数矩阵

A=[1-23-4;01-11;-10-12;1-34-5];

>>a=null(A)

a=

-0.14020.8044

0.4723-0.3321

0.80440.1402

0.33210.4723

若求方程中含有最多零元素个数的解:

a=null(A,'r')

a=

-12

1-1

10

01

(2)恰定方程组求解

A=rand(100)*1.e2;

x=ones(100,1);

b=A*x;

tic

y=inv(A)*b;

toc

Elapsedtimeis26.456033seconds.

err=norm(y-x)

err=

1.1380e-012

res=norm(A*y-b)

res=

4.6191e-010

tic

y=A\b;

toc

Elapsedtimeis54.438244seconds.

err=norm(y-x)

err=

展开阅读全文
相关资源
猜你喜欢
相关搜索
资源标签

当前位置:首页 > 表格模板 > 合同协议

copyright@ 2008-2023 冰点文库 网站版权所有

经营许可证编号:鄂ICP备19020893号-2