Matlab与数学建模综合练习

更新时间:2024-01-02 13:40:01 阅读量: 教育文库 文档下载

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

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

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

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

17 24 1 23 5 7 4 6 13 10 12 19 11 18 25

>> A'

ans =

17 23 4 24 5 6 1 7 13 8 14 20 15 16 22 >> inv(A)

ans =

-0.0049 0.0512 0.0431 -0.0373 -0.0303 0.0031 0.0047 -0.0065 0.0028 0.0050

(2)求A的特征值;>> P=poly(A) P =

1.0e+006 *

0.0000 -0.0001

>> roots(P)

8 15 14 16 20 22 21 3 2 9 10 11 12 18 19 25 21 2

3 9 -0.0354 0.0012 0.0034 -0.0046 0.0127 0.0015 0.0031 0.0031 0.0364 0.0108 0.0435 -0.0370 0.0415 -0.0450 0.0111 -0.0006 0.0406 0.0780 - 1 -

-5.0700

ans =

65.0000 -21.2768 -13.1263 21.2768 13.1263 >> V=eig(A) V =

65.0000 -21.2768 -13.1263 21.2768 13.1263

(3)计算A的各列的总和与平均值; >> sum(A(:,1))

ans =

65

>> mean(A(:,1))

ans =

13

>> sum(A)

ans =

65 65 65 65 65

>> mean(A)

ans =

13 13 13 13 13

(魔方矩阵的行、列、对角线上元素的和相等)

- 2 -

(4)计算A的各行的总和与平均值; >> sum(A(1,:))

ans =

65

>> mean(A(1,:))

ans =

13

>> sum(A,2)

ans =

65 65 65 65 65

>> mean(A,2)

ans =

13 13 13 13 13

(5)若b=[1 2 3 4 5] ',求方程组 Ax=b的解; >> b=[1 2 3 4 5]' b =

1 2 3 4 5

>> x=A\\b

- 3 -

x =

1/78 1/78 7/39 1/78 1/78

(6)验证你的结论的正确性. >> x=[1/78 1/78 7/39 1/78 1/78]' x =

1/78 1/78 7/39 1/78 1/78

>> A=magic(5) A =

17 24 23 5 4 6 10 12 11 18

>> A*x

ans =

1 2 3 4 5

2.产生行向量S =[1.0, 1.2, 1.4, …, >> S=1:0.2:20; >> S'; >> S*S'

1 8 15 7 14 16 13 20 22 19 21 3 25 2 9 20],并计算S * S' 与 S' * S,你有何“发现”?- 4 -

ans =

1.3533e+004

>> S'*S

ans =......

1行n列?n行1列=1行1列 n行1列?1行n列=n行n列

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

A =

1 2 3 4

>> B=[5 5;0 5] B =

5 5 0 5

>> C=A*B-B*A C =

-15 -15 0 15

4.若设矩阵A=??>> A=[1 2;3 4] A =

1 2 3 4

- 5 -

?12??50????;B=;求C=A * B – B * A,你又有何“发现”? ????34??05?

>> B=[5 0;0 5] B =

5 0 0 5

>> C=A*B-B*A C =

0 0 0 0

5.如何建立如下的矩阵(命令方式和程序方式)?

??20040?0?(1)?02004?0?????????;

??00?2004???10?10命令式:

>> D=diag(2004*ones(10,1)) D =

2004 0 0 0 0 0 0 0 2004 0 0 0 0 0 0 0 2004 0 0 0 0 0 0 0 2004 0 0 0 0 0 0 0 2004 0 0 0 0 0 0 0 2004 0 0 0 0 0 0 0 2004 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 程序方式: 建立M文件: A=zeros(10); for i=1:10

for j=1:10 if i==j

A(i,j)=2004;

- 6 -

0 0 0 0 0 0 0 0 0 0 0 0 0 0 2004 0 0 2004 0 0 0 0 0 0 0 0 0 0 0 2004

end end end A

运行结果: A =

2004 0 0 0 0 0 0 0 0 0 0 2004 0 0 0 0 0 0 0 0 0 0 2004 0 0 0 0 0 0 0 0 0 0 2004 0 0 0 0 0 0 0 0 0 0 2004 0 0 0 0 0 0 0 0 0 0 2004 0 0 0 0 0 0 0 0 0 0 2004 0 0 0 0 0 0 0 0 0 0 2004 0 0 0 0 0 0 0 0 0 0 2004 0 0 0 0 0 0 0 0 0 0 2004

??010?10???(2)100?10????????; ??1010?0???10?10命令式:

>> A=10*ones(10) A =

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 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

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

10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 - 7 -

0 0 0 0 0 0 0 0 0 0

10 0 0 0 0 0 0 0 0 0 10 10 0 0 0 0 0 0 0 0 10 10 10 0 0 0 0 0 0 0 10 10 10 10 0 0 0 0 0 0 10 10 10 10 10 0 0 0 0 0 10 10 10 10 10 10 0 0 0 0 10 10 10 10 10 10 10 0 0 0 10 10 10 10 10 10 10 10 0 0 10 10 10 10

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

0 10 10 10 0 0 10 10 0 0 0 10 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

>> L+U

ans =

0 10 10 10 10 0 10 10 10 10 0 10 10 10 10 0 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 程序式:

A=zeros(10); for i=1:10 for j=1:10

10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 0 10 10 0 0 10 0 0 0 0 0 0 0 0 0 0 0 0 10 10 10 10 10 10 10 10 10 10 10 10 0 10 10 10 0 10 10 10 0 10 10 10 10 10 10 10 10 10 10 10 0 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 0 10 10 0 0 10 0 0 0 10 10 10

10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 0 10 10 10 0 10 10 10 0

- 8 -

if i==j

A(i,j)=0; else

A(i,j)=10; end end end A

运行结果: A =

0 10 10 10 10 10 10 10 10 10 0 10 10 10 10 10 10 10 10 10 0 10 10 10 10 10 10 10 10 10 0 10 10 10 10 10 10 10 10 10 0 10 10 10 10 10 10 10 10 10 0 10 10 10 10 10 10 10 10 10 0 10 10 10 10 10 10 10 10 10 0 10 10 10 10 10 10 10 10 10 0 10 10 10 10 10 10 10 10 10

??20041?1?(3)?12004?1???; ??????

???11?2004??10?10命令式:

>> D=diag(2004*ones(10,1)); >> A=ones(10); >> L=tril(A,-1); >> U=triu(A,1); >> D+L+U

ans =

2004 1 1 1 1 1 1 1 2004 1 1 1 1 1 1 1 2004 1 1 1 1 1 1 1 2004 1 1 1 1 1 1 1 2004 1 1 1 1 1 1 1 2004 1 1 1 1 1 1 1 2004 1 1 1 1 1 1 1 - 9 -

10 10 10 10 10 10 10 10 10 0

1 1 1 1 1 1 1 1 1 1 1 1 1 1 2004 1 1

1 1 1 1 1

1

1

1 1 1 1 1 1 1 1 2004 1 1 1 1 1 1 1 1 1 1 2004

>> D=diag(2004*ones(10,1)) D =

2004 0 0 0 0 0 0 0 0 0 0 2004 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

>> A=ones(10) A =

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

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

0 0 0 0 1 0 0 0 1 1 0 0 1 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 0 0 2004 0 0 2004 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 1 1 1 1 1 1 1 1 1 1 1 1 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 0 0 1 0 0 0 1 1 0 0 0 0 0 0 0 0 0 0 0 2004 0 0 0 2004 0 0 0 2004 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 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0

- 10 -

0 0 0 0 0 0 0 0 0 0 0 0 2004 0 0 2004 0 0 0 0 0 0 0 0 0 0 2004

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

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

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

>> D+L+U

ans =

2004 1 1 1 1 1 2004 1 1 1 1 1 2004 1 1 1 1 1 2004 1 1 1 1 1 2004 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 程序式:

A=zeros(10); for i=1:10 for j=1:10 if i==j

A(i,j)=2004; else

A(i,j)=1; end end end

1 1 1 1 1 1 1 1 1 1 2004 1 1 2004 1 1 1 1 1 1 - 11 -

1 1 1 1 1 1 1 1 1 1 1 1 1 1 2004 1 1 2004 1 1 1 1 1 1 1 1 1 1 1 2004

A

运行结果: A =

2004 1 1 1 1 1 1 1 1 1 1 2004 1 1 1 1 1 1 1 1 1 1 2004 1 1 1 1 1 1 1 1 1 1 2004 1 1 1 1 1 1 1 1 1 1 2004 1 1 1 1 1 1 1 1 1 1 2004 1 1 1 1 1 1 1 2004 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1

??10?10??10?(4)??1010??10?????????

???10?10?10???10?10命令式:

>> D=diag(10*ones(10,1)) D =

10 0 0 0 0 0 0 0 0 0 0 10 0 0 0 0 0 0 0 0 0 0 10 0 0 0 0 0 0 0 0 0 0 10 0 0 0 0 0 0 0 0 0 0 10 0 0 0 0 0 0 0 0 0 0 10 0 0 0 0 0 0 0 0 0 0 10 0 0 0 0 0 0 0 0 0 0 10 0 0 0 0 0 0 0 0 0 0 10 0 0 0 0 0 0 0 0 0 0 10

>> A=10*ones(10) A =

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

- 12 -

1 1 1 1 2004 1 1 2004 1 1 1 1 1 1 2004

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 10 10 10 10 10

>> L=-1*tril(A,-1) L =

0 0 0 0 0 0 0 0 0 0 -10 0 0 0 0 0 0 0 0 0 -10 -10 0 0 0 0 0 0 0 0 -10 -10 -10 0 0 0 0 0 0 0 -10 -10 -10 -10 0 0 0 0 0 0 -10 -10 -10 -10 -10 0 0 0 0 0 -10 -10 -10 -10 - 10 -10 0 0 0 0 -10 -10 -10 -10 -10 -10 -10 0 0 0 -10 -10 -10 -10 -10 -10 -10 -10 0 0 -10 -10 -10 -10 -10 -10 -10 -10 -10 0

>> U=-1*triu(A,1) U =

0 -10 -10 -10 -10 -10 -10 -10 -10 -10 0 0 -10 -10 -10 -10 -10 -10 -10 -10 0 0 0 -10 -10 -10 -10 -10 -10 -10 0 0 0 0 -10 -10 -10 -10 -10 -10 0 0 0 0 0 -10 -10 -10 -10 -10 0 0 0 0 0 0 -10 -10 -10 -10 0 0 0 0 0 0 0 -10 -10 -10 0 0 0 0 0 0 0 0 -10 -10 0 0 0 0 0 0 0 0 0 -10 0 0 0 0 0 0 0 0 0 0

>> D+L+U

ans =

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

- 13 -

-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 -10 -10 -10 10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 10

程序式:

A=zeros(10); for i=1:10 for j=1:10 if i==j

A(i,j)=10; else

A(i,j)=-10; end end end A

运行结果: A =

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 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10

??100?0?(5) ?120?0????????? ??11?10???0命令式:

>> D=[10:10:100]' D =

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

- 14 -

20 30 40 50 60 70 80 90 100

>> D=diag(D,0) D =

10 0 0 0 20 0 0 0 30 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

>> A=ones(10) A =

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

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

0 0 0 0 0 0 0 0 0 40 0 0 0 50 0 0 0 60 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 1 1 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 0 0 0 0 0 0 70 0 0 0 0 80 0 0 0 0 90 0 0 0 0 100

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

- 15 -

0 0 0 0 0 0 0 0 0 0

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

>> D+L

ans =

10 0 0 0 0 0 0 0 1 20 0 0 0 0 0 0 1 1 30 0 0 0 0 0 1 1 1 40 0 0 0 0 1 1 1 1 50 0 0 0 1 1 1 1 1 60 0 0 1 1 1 1 1 1 70 0 1 1 1 1 1 1 1 80 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 程序式:

A=zeros(10); for i=1:10 for j=1:10 if i==j

A(i,j)=10*i; elseif i

A(i,j)=1; end end end A

运行结果: A =

10 0 0 0 0 0 0 0 0 0 1 20 0 0 0 0 0 0 0 0 1 1 30 0 0 0 0 0 0 0

1 0

0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 90 0 1 100

- 16 -

1 1 1 40 0 0 0 0 0 0 1 1 1 1 50 0 0 0 0 0 1 1 1 1 1 60 0 0 0 0 1 1 1 1 1 1 70 0 0 0 1 1 1 1 1 1 1 80 0 0 1 1 1 1 1 1 1 1 90 0 1 1 1 1 1 1 1 1 1 100

??11?23?11(6) ??34?????11?1112命令式: >> format rat >> H=hilb(11) H =

1 1/2 1/2 1/3 1/3 1/4 1/4 1/5 1/5 1/6 1/6 1/7 1/7 1/8 1/8 1/9 1/9 1/10 1/10 1/11 1/11 1/12

>> H(:,11)=[] H =

1 1/2 1/2 1/3 1/3 1/4 1/4 1/5 1/5 1/6 1/6 1/7 1/7 1/8 1?11?1??12??? ?1?20?? 1/3 1/4 1/4 1/5 1/5 1/6 1/6 1/7 1/7 1/8 1/8 1/9 1/9 1/10 1/10 1/11 1/11 1/12 1/12 1/13 1/13 1/14 1/3 1/4 1/4 1/5 1/5 1/6 1/6 1/7 1/7 1/8 1/8 1/9 1/9 1/10 1/5 1/6 1/7 1/6 1/7 1/8 1/7 1/8 1/9 1/8 1/9 1/10 1/9 1/10 1/11 1/10 1/11 1/12 1/11 1/12 1/13 1/12 1/13 1/14 1/13 1/14 1/15 1/14 1/15 1/16 1/15 1/16 1/17 1/5 1/6 1/6 1/7 1/7 1/8 1/8 1/9 1/9 1/10 1/10 1/11 1/11 1/12 - 17 -

1/8 1/9 1/9 1/10 1/10 1/11 1/11 1/12 1/12 1/13 1/13 1/14 1/14 1/15 1/15 1/16 1/16 1/17 1/17 1/18 1/18 1/19 1/7 1/8 1/8 1/9 1/9 1/10 1/10 1/11 1/11 1/12 1/12 1/13 1/13 1/14 1/10 1/11 1/11 1/12 1/12 1/13 1/13 1/14 1/14 1/15 1/15 1/16 1/16 1/17 1/17 1/18 1/18 1/19 1/19 1/20 1/20 1/21 1/9 1/10 1/10 1/11 1/11 1/12 1/12 1/13 1/13 1/14 1/14 1/15 1/15 1/16 ????

1/8 1/9 1/10 1/11 1/12 1/13 1/14 1/15 1/16 1/17 1/9 1/10 1/11 1/12 1/13 1/14 1/15 1/16 1/17 1/18 1/10 1/11 1/12 1/13 1/14 1/15 1/16 1/17 1/18 1/19 1/11 1/12 1/13 1/14 1/15 1/16 1/17 1/18 1/19 1/20

>> H(1,:)=[] H =

1/2 1/3 1/4 1/5 1/3 1/4 1/5 1/6 1/4 1/5 1/6 1/7 1/5 1/6 1/7 1/8 1/6 1/7 1/8 1/9 1/7 1/8 1/9 1/10 1/8 1/9 1/10 1/11 1/9 1/10 1/11 1/12 1/10 1/11 1/12 1/13 1/11 1/12 1/13 1/14 程序式:

format rat A=zeros(10); for i=1:10 for j=1:10

A(i,j)=1/(i+j); end end A

运行结果: A =

1/2 1/3 1/4 1/5 1/3 1/4 1/5 1/6 1/4 1/5 1/6 1/7 1/5 1/6 1/7 1/8 1/6 1/7 1/8 1/9 1/7 1/8 1/9 1/10 1/8 1/9 1/10 1/11 1/9 1/10 1/11 1/12 1/10 1/11 1/12 1/13 1/11 1/12 1/13 1/14

1/6 1/7 1/7 1/8 1/8 1/9 1/9 1/10 1/10 1/11 1/11 1/12 1/12 1/13 1/13 1/14 1/14 1/15 1/15 1/16 1/6 1/7 1/7 1/8 1/8 1/9 1/9 1/10 1/10 1/11 1/11 1/12 1/12 1/13 1/13 1/14 1/14 1/15 1/15 1/16 - 18 -

1/8 1/9 1/9 1/10 1/10 1/11 1/11 1/12 1/12 1/13 1/13 1/14 1/14 1/15 1/15 1/16 1/16 1/17 1/17 1/18 1/8 1/9 1/9 1/10 1/10 1/11 1/11 1/12 1/12 1/13 1/13 1/14 1/14 1/15 1/15 1/16 1/16 1/17 1/17 1/18 1/10 1/11 1/11 1/12 1/12 1/13 1/13 1/14 1/14 1/15 1/15 1/16 1/16 1/17 1/17 1/18 1/18 1/19 1/19 1/20

1/10 1/11 1/11 1/12 1/12 1/13 1/13 1/14 1/14 1/15 1/15 1/16 1/16 1/17 1/17 1/18 1/18 1/19 1/19 1/20

??2004200?0200430(7)??002004?000??000>> D=[20:10:50]'

D =

20 30 40 50

>> D=diag(D,1) D =

0 20 0 0 0 0 0 30 0 0 0 0 0 40 0 0 0 0 0 50 0 0 0 0 0

>> V=diag(2004*ones(5,1)) V =

2004 0 0 0 2004 0 0 0 2004 0 0 0 0 0 0

>> D+V

ans =

2004 20 0 0 2004 30 0 0 2004 0 0 0 0 0 0 00?00?400??200450? ?02004?? 0 0 0 0 0 0 2004 0 0 2004

0 0 0 0 40 0 2004 50 0 2004

- 19 -

程序式:

A=zeros(5); for i=1:5 for j=1:5 if i==j

A(i,j)=2004; elseif i+1==j A(i,j)=10*j; else

A(i,j)=0; end end end A 运行结果: A =

2004 20 0 0 0 0 2004 30 0 0 0 0 2004 40 0 0 0 0 2004 50 0 0 0 0 2004

6.绘制下列曲线的图形(散点图与折线图):y?>> x=[-1:0.1:2];

>> y=(x.^3-x.^2-x+1).^(1/3); >> plot(x,y,'.')

3x3?x2?x?1,x?[?1,2]

- 20 -

>> x=[-1:0.5:2];

>> y=(x.^3-x.^2-x+1).^(1/3); >> plot(x,y)

- 21 -

7.绘制下列曲面的图形:z?x?2y>> x=-4:0.2:4;y=x; >> [X,Y]=meshgrid(x,y); >> Z=(X.^2+2.*Y.^2).^(1/2); >> surf(X,Y,Z) >> hold on

>> Z=-(X.^2+2.*Y.^2).^(1/2); >> surf(X,Y,Z)

222(提示:曲面由两部分构成)

- 22 -

8.在同一个图形上作下列两个函数的图象:

(1)y?sin(x),x?[0,2?]; (2)y?cos(x),x?[0,2?]

>> x=0:0.2:2*pi; >> y=sin(x).^2; >> plot(x,y,'--m') >> hold on >> y=cos(x).^2; >> plot(x,y,'-b')

22 - 23 -

- 24 -

>> x=0:0.1:2*pi; >> subplot(2,1,1) >> plot(x,sin(x).^2) >> title('y=sin(x)^2') >> subplot(2,1,2) >> plot(x,cos(x).^2) >> title('y=cos(x)^2')

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

x=[53 56 60 67.5 75 90 110]; y=[109 120.5 130 141.1 157.5 180 185]; 求其回归直线,画回归直线图形并计算最小误差平方和.

>> x=[53 56 60 67.5 75 90 110];

>> y=[109 120.5 130 141.1 157.5 180 185]; >> plot(x,y)

- 25 -

>> [p,s]=polyfit(x,y,1) p =

1.3538 47.2362 s =

R: [2x2 double] df: 5 normr: 20.8486

所以回归方程为:y=1.3538x+47.2362; 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]; 求其回归直线,画回归直线图形并计算最小误差平方和.

>> 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];

- 26 -

>> plot(x,y)

>> [p,s]=polyfit(x,y,1) p =

0.5805 -41.2700 s =

R: [2x2 double] df: 13 normr: 16.2044

所以回归方程为: y=0.5805x+-41.2700;

12.求下列各结果:

(1)用Matlab因式分解:x>> syms x

- 27 -

100?1.

>> f=x^100-1; >> factor(f) ans =

(x-1)*(x^4+x^3+x^2+x+1)*(x^20+x^15+x^10+x^5+1)*(x+1)*(1-x+x^2-x^3+x^4)*(1-x^5+x^10-x^15+x^20)*(1+x^2)*(x^8-x^6+x^4-x^2+1)*(x^40-x^30+x^20-x^10+1)

(2)用Matlab求极限:L?lim>> syms x

>> f=((1+x)^(1/x)-exp(1))/x; >> L=limit(f,x,0) L = NaN

(3)用Matlab求积分:>> syms x >> f=sin(x^2); >> int(f,x,0,inf) ans =

1/4*2^(1/2)*pi^(1/2)

(4)用Matlab求幂级数:

x?0(1?x)?e.

x1x?0??sinx2dx.

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

>> syms x n

>> Fn=(-1)^(n-1)*x^(2*n+1)/(4*n^2-1); >> S=symsum(Fn,n,1,inf) S =

1/3*x^3*(3/2*LerchPhi(-x^2,1,3/2)*(-1/2-1/2*x^2)+1/(x^2+1)*(3/2*x^2+3/2))

14. (三维)符号作图尝试 命令

作用 - 28 -

解释 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])

>> ezplot3('sin(t)', ' cos(t)', 't', [0,6*pi])

ezcontour('x*exp(-x^2 - y^2)')

>> ezcontour('x*exp(-x^2 - y^2)')

- 29 -

ezcontourf('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])

>> ezmesh('(s-sin(s))*cos(t)','(1-cos(s))*sin(t)','s',[-2*pi,2*pi])

- 30 -

ezmeshc('(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)')

>> ezsurf('x*exp(-x^2 - y^2)')

- 31 -

ezsurfc('x*exp(-x^2 - y^2)')

>> ezsurfc('x*exp(-x^2 - y^2)')

- 32 -

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

Top