Matlab与数学建模综合练习(1)

更新时间:2024-05-04 03:32:02 阅读量: 综合文库 文档下载

说明:文章内容仅供预览,部分内容可能不全。下载后的文档,内容与下面显示的完全一致。下载之前请确认下面内容是否您想要的,是否完整无缺。

《Matlab与数学建模》综合练习

1.按顺序进行如下的操作:

(1)产生一个5阶魔术方阵A;并计算A'与A-1(即inv(A)); >> A=magic(5) A =

17 24 23 5 4 6 10 12 11 18

>> B=A' B =

17 23 24 5 1 7 8 14 15 16

>> inv(A)

ans =

-77/15600 133/2600 89/2063 -97/2600 -59/1950 1/325 73/15600 -17/2600 43/15600 1/200 (2)求A的特征值; >> eig(A)

ans =

65 -2383/112 -3846/293 2383/112 3846/293

1 7 13 19 25 4 6 13 20 22 -23/650 -3/650 1/325 7/650 27/650 - 1 -

8 14 20 21 2 10 12 19 21 3 3/2600 33/2600 1/325 113/2600 -9/200 15 16 22 3 9 11 18 25 2 9 53/15600 23/15600 71/1950 -577/15600 98/8837

(3)计算A的各列的总和与平均值; (4)计算A的各行的总和与平均值;

(5)若b=[1 2 3 4 5] ',求方程组 Ax=b的解; (6)验证你的结论的正确性.

2.产生行向量S =[1.0, 1.2, 1.4, …, 20],并计算S * S' 与 S' * S,你有何“发现”?

?12??55?3.设A=??34??;B=??05??;求C=A * B – B * A,你有何“发现”?

????4.若设矩阵A=???12??50????;B=;求C=A * B – B * A,你又有何“发现”? ????34??05?5.如何建立如下的矩阵(命令方式和程序方式)?

0?0??2004?010?10?????2004?0?100?10?0?(1)?; (2)?;>> ???????????????0??1010?0??0?2004??10?10??10?10a=ones(10,1)

a =

1 1 1 1 1 1 1 1 1 1

>> A=0*a A =

0 0 0 0 0 0 0

- 2 -

0 0 0

>> b=diag(A) b =

Columns 1 through 7

0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

Columns 8 through 10

0 0 0 0 0 0 0 0 0 0 >> c=ones(10)

0

0

0

0

0

0

0

0

0

0 0 0 0 0 0 0 0 0 0 0 - 3 -

0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

c =

Columns 1 through 7

1 1 1 1 1 1 1

1 1 1 1 1 1 1

1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1

Columns 8 through 10

1 1 1 1 1 1 1 1 1 1 >> C=10*c C =

Columns 1 through 7

1

1

1

1

1

1

1

1 1 1 1 1 1 1 1 1 1 1 - 4 -

1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1

10 10 10 10 10 10 10

10 10 10 10 10 10 10

10 10 10 10 10 10 10

10 10 10 10 10 10 10

10 10 10 10 10 10 10

10 10 10 10

10 10 10 10

10 10 10 10

10 10 10 10

10 10 10 10

Columns 8 through 10

10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10

>> m=triu(C,1) m =

Columns 1 through 7

0 10 10 10

0 0 10 10

10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 - 5 -

10 10 10 10 10 10 10 10 10 10 10 10 10 10

1 1 1 1 1 1 1 1 1 1 1 1

>> U=triu(a,1) U =

Columns 1 through 6

0 1

0 1

0 1

0 1

0 1

0 0

0 0

0 0

0 0

0 0

Columns 7 through 10

1 1 1 1 1 1 0 0 0 0

1 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 0 0 0 - 11 -

1 1 1 1 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1 0 0 1 1 1 1 0 0 0 0 0 0

>> D=tril(A,-1) D =

Columns 1 through 6

0 0 0 0 0 0

1 0 0 0 0 0

1 0

1 0

1 0

1 0

1 1

1 1

1 1

1 1

Columns 7 through 10

0 0 0 0 0 0 0 1 1 1

>> Q=D+U+F Q =

1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 1 1 - 12 -

0 0 1 0 1 1 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0

0 0 0 1 1 1 1 1

Columns 1 through 6

1024 1 1 1 1 1

1 1024 1 1 1 1

1 1 1024 1 1 1

1 1 1 1

1 1 1 1

1 1 1 1024

1 1 1 1

1 1 1 1

1 1 1 1

1 1 1 1

Columns 7 through 10

1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1024 1 1 1 1024 1 1 1 1024 1 1 1 ??10?10??10? (4)??1010??10?????????

???10?10?10???10?10- 13 -

1024 1 1 1024 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1024

?100?120(5) ???0??0? a=10:10:100 ?????????11?10???0

a =

Columns 1 through 7

10 20 60 70

Columns 8 through 10

80 90 >> A=diag(a) A =

Columns 1 through 7

10 0 0 0

0 20 0 0

0 0 0 0

0 0 0 0

0 0 0 0

0 0 60 0

0 0 0 70

0 0 0 0

0 0 0 0

0 0 0 0

Columns 8 through 10

30 100 0 0 30 0 0 0 0 0 0 0 - 14 -

40 0 0 0 40 0 0 0 0 0 0 50 0 0 0 0 50 0 0 0 0 0

0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 80 0 0 0 90 0 0

>> a=ones(10) a =

Columns 1 through 7

1 1 1 1

1 1 1 1

1 1 1 1

1 1 1 1

1 1 1 1

1 1 1 1

1 1 1 1

1 1 1 1

1 1 1 1

1 1 1 1

Columns 8 through 10

1 1 1 1 1 1 0 100 1 1 1 1 1 1 1 1 1 1 1 1 1

- 15 -

1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1

1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 >> D=tril(a,-1) D =

Columns 1 through 7

0 0 0

1 0 0

1 0 0

1 0 0

1 0 0

1 0 0

1 1 0

1 1 1

1 1 1

1 1 1

Columns 8 through 10

0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 - 16 -

0 0 0 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0

0 0 0 0 1 1 1 1 1 1 0 0 0 0 0 1 1 1 1 1

1 0 0 1 1 0

>> W=A+D W =

Columns 1 through 7

10 0 0 0

1 20 0 0

1 1 0 0

1 1 0 0

1 1 0 0

1 1 60 0

1 1 1 70

1 1 1 1

1 1 1 1

1 1 1 1

Columns 8 through 10

0 0 0 0 0 0 0 0 0 0 0 0 0 0 80 0 1 90 1 1 - 17 -

0 0 30 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0

100 0 0 0 0 0 0 40 0 1 50 1 1 1 1 1 1 1 1 1 1 (6)

?11?23??11?34?????11??11121?11??1??12? ????1???20??000??200420??020043000??02004400? (7)?0??000200450???00002004???6.绘制下列曲线的图形(散点图与折线图):y?3x3?x2?x?1,x?[?1,2]

7.绘制下列曲面的图形:z2?x2?2y2(提示:曲面由两部分构成) 8.在同一个图形上作下列两个函数的图象:

(1)y?sin2(x),x?[0,2?]; (2)y?cos2(x),x?[0,2?]

9.假如你有一组实测数据,例如:

x=[53 56 60 67.5 75 90 110]; y=[109 120.5 130 141.1 157.5 180 185]; 求其回归直线,画回归直线图形并计算最小误差平方和. 10.假如你有一组实测数据,例如:

x=[75 86 95 108 112 116 135 151 155 160 163 167 171 178 185]; y=[10 12 15 17 20 22 35 41 48 50 51 54 59 66 75]; 求其回归直线,画回归直线图形并计算最小误差平方和.

11.随机产生500个0到100的整数FS作为学生的考试分数.

(1) 画出FS的简单直方图;

(2) 画出每个分数段(0~10、10~20、…,90~100)的统计频数直方图; 12.求下列各结果:

(1)用Matlab因式分解:x100?1.

(2)用Matlab求极限:L?limx?0(1?x)?e.

x1x(3)用Matlab求积分:

?0??sinx2dx.

(4)用Matlab求幂级数:

?(?1)n?1?n?1x2n?14n?12的和函数(化简结果).

- 18 -

13.非线性回归尝试

下表是到1994年的游泳世界纪录,试估计时间y与距离x的关系. 距离x(米) 时间y(秒) 50 21.81 100 48.42 200 106.69 400 225 800 466.60 1500 863.48 x,但当x?18时,y??0.2794,说明:用线性回归方法将得到:y??11.0089?0.5961这是非常荒唐的结果!显然,一个基本要求是当x?0时y?0.试尝试使用非线性回归模型: y?axb.

14. (三维)符号作图尝试 命令 ezplot3 ezcontour ezcontourf ezmesh ezmeshc ezsurf ezsurfc 作用 3-D parametric curve plotter use contour plotter filled contour plotter 3-D mesh plotter combination mesh/contour plotter 3-D colored surface plotter combination surf/contour plotter 解释 3D参数曲线图形 等高线图 填充等高线图 3D mesh曲面图形 mesh曲面/等高线图 3D surf曲面图形 surf曲面/等高线图

请尝试以下的命令:

ezplot3('sin(t)', ' cos(t)', 't', [0,6*pi]) ezcontour('x*exp(-x^2 - y^2)') ezcontourf('x*exp(-x^2 - y^2)')

ezmesh('(s-sin(s))*cos(t)','(1-cos(s))*sin(t)','s',[-2*pi,2*pi]) ezmeshc('(s-sin(s))*cos(t)','(1-cos(s))*sin(t)','s',[-2*pi,2*pi]) ezsurf('x*exp(-x^2 - y^2)') ezsurfc('x*exp(-x^2 - y^2)')

- 19 -

本文来源:https://www.bwwdw.com/article/b8ig.html

Top