手机版

MATLAB课后上机实验报告

发布时间:2024-11-10   来源:未知    
字号:

《MATLAB程序设计与应用》实验指导书

实验一 matlab集成环境使用与运算基础

1,先求下列表达式的值,然后显示matlab工作空间的使用情况并保存全部变量。 (1)z1 程序:

.>> z1=2*sin(85*pi/180)/(1+exp(2)) 结果: z1 =

0.2375

2其中x

0.45

1 2i

5

2sin851 e

2

(2

)z2 程序:

12

In(x

>> x=[2,1+2*i;-0.45,5]; >> z2=0.5*log(x+sqrt(1+x*x)) 结果: z2 =

0.7114 - 0.0253i 0.8968 + 0.3658i 0.2139 + 0.9343i 1.1541 - 0.0044i

(3)z3

e

0.3a

e2

0.3a

sin(a 0.3) In

0.3 a2

,a 3.0, 2.9, 2.8,...,2.8,2.9,3.0

提示:利用冒号表达式生成a向量,求各点函数值时用点乘运算。 程序:

>> a=-3.0:0.1:30;

>> z3=(exp(0.3*a)-exp(-0.3*a))/2.*sin((a+0.3)*pi/180)+log((0.3+a)/2) 结果: z3 =

1.0e+003 *

Columns 1 through 4

0.0003 + 0.0031i 0.0003 + 0.0031i 0.0003 + 0.0031i 0.0002 + 0.0031i

Columns 5 through 8

0.0002 + 0.0031i 0.0001 + 0.0031i 0.0001 + 0.0031i 0.0000 + 0.0031i

Columns 9 through 12

-0.0000 + 0.0031i -0.0001 + 0.0031i -0.0001 + 0.0031i -0.0002 + 0.0031i

Columns 13 through 16

-0.0003 + 0.0031i -0.0003 + 0.0031i

Columns 17 through 20

-0.0006 + 0.0031i -0.0007 + 0.0031i

Columns 21 through 24

-0.0010 + 0.0031i -0.0012 + 0.0031i

Columns 25 through 28

-0.0019 + 0.0031i -0.0023 + 0.0031i

Columns 29 through 32

-0.0030 -0.0023

Columns 33 through 36

-0.0014 -0.0012

Columns 37 through 40

-0.0008 -0.0007

Columns 41 through 44

-0.0004 -0.0003

Columns 45 through 48

-0.0001 -0.0001

Columns 49 through 52

-0.0004 + 0.0031i -0.0008 + 0.0031i -0.0014 + 0.0031i -0.0030 + 0.0031i -0.0019 -0.0010 -0.0006 -0.0003 -0.0000 -0.0005 + 0.0031i -0.0009 + 0.0031i -0.0016 + 0.0031i -0.0370 -0.0016 -0.0009 -0.0005 -0.0002 0.0000

0.0001 0.0001 0.0002 0.0002

Columns 53 through 56

0.0003 0.0003 0.0003 0.0004

Columns 57 through 60

0.0004 0.0005

Columns 61 through 64

0.0006 0.0006

Columns 65 through 68

0.0007 0.0007

Columns 69 through 72

0.0008 0.0008

Columns 73 through 76

0.0009 0.0010

Columns 77 through 80

0.0011 0.0011

Columns 81 through 84

0.0012 0.0012

Columns 85 through 88

0.0013 0.0013

Columns 89 through 92

0.0014 0.0014

Columns 93 through 96

0.0005 0.0005 0.0006 0.0007 0.0008 0.0008 0.0009 0.0009 0.0010 0.0010 0.0011 0.0011 0.0012 0.0013 0.0013 0.0014 0.0015 0.0015

0.0015 0.0016 0.0016 0.0016

Columns 97 through 100

0.0017 0.0017 0.0017 0.0018

Columns 101 through 104

0.0018 0.0018

Columns 105 through 108

0.0020 0.0020

Columns 109 through 112

0.0021 0.0022

Columns 113 through 116

0.0023 0.0024

Columns 117 through 120

0.0025 0.0026

Columns 121 through 124

0.0027 0.0028

Columns 125 through 128

0.0030 0.0031

Columns 129 through 132

0.0033 0.0034

Columns 133 through 136

0.0036 0.0037

Columns 137 through 140

0.0019 0.0020 0.0022 0.0024 0.0026 0.0029 0.0031 0.0034 0.0038 0.0019 0.0021 0.0023 0.0025 0.0027 0.0029 0.0032 0.0035 0.0039

0.0040 0.0041 0.0042 0.0043

Columns 141 through 144

0.0044 0.0045 0.0046 0.0047

Columns 145 through 148

0.0049 0.0050

Columns 149 through 152

0.0054 0.0056

Columns 153 through 156

0.0060 0.0062

Columns 157 through 160

0.0068 0.0069

Columns 161 through 164

0.0076 0.0078

Columns 165 through 168

0.0085 0.0088

Columns 169 through 172

0.0096 0.0099

Columns 173 through 176

0.0108 0.0112

Columns 177 through 180

0.0123 0.0127

Columns 181 through 184

0.0051 0.0057 0.0064 0.0071 0.0080 0.0090 0.0102 0.0115 0.0131 0.0053 0.0059 0.0066 0.0074 0.0083 0.0093 0.0105 0.0119 0.0135

0.0139 0.0144 0.0148 0.0153

Columns 185 through 188

0.0158 0.0163 0.0168 0.0174

Columns 189 through 192

0.0180 0.0185

Columns 193 through 196

0.0204 0.0211

Columns 197 through 200

0.0233 0.0241

Columns 201 through 204

0.0265 0.0274

Columns 205 through 208

0.0303 0.0313

Columns 209 through 212

0.0346 0.0358

Columns 213 through 216

0.0395 0.0409

Columns 217 through 220

0.0452 0.0467

Columns 221 through 224

0.0517 0.0534

Columns 225 through 228

0.0191 0.0218 0.0249 0.0284 0.0324 0.0370 0.0423 0.0483 0.0552 0.0198 0.0225 0.0257 0.0293 0.0335 0.0382 0.0437 0.0500 0.0571

0.0591 0.0611 0.0632 0.0654

Columns 229 through 232

0.0676 0.0699 0.0723 0.0748

Columns 233 through 236

0.0773 0.0800

Columns 237 through 240

0.0885 0.0915

Columns 241 through 244

0.1013 0.1047

Columns 245 through 248

0.1159 0.1199

Columns 249 through 252

0.1326 0.1372

Columns 253 through 256

0.1518 0.1570

Columns 257 through 260

0.1737 0.1796

Columns 261 through 264

0.1987 0.2055

Columns 265 through 268

0.2273 0.2351

Columns 269 through 272

0.0827 0.0947 0.1083 0.1240 0.1419 0.1624 0.1858 0.2125 0.2431 0.0856 0.0979 0.1121 0.1282 0.1467 0.1679 0.1921 0.2198 0.2514

0.2600 0.2689 0.2781 0.2876

Columns 273 through 276

0.2974 0.3076 0.3180 0.3289

Columns 277 through 280

0.3401 0.3517

Columns 281 through 284

0.3889 0.4021

Columns 285 through 288

0.4446 0.4597

Columns 289 through 292

0.5082 0.5254

Columns 293 through 296

0.5807 0.6004

Columns 297 through 300

0.6636 0.6861

Columns 301 through 304

0.7581 0.7838

Columns 305 through 308

0.8660 0.8952

Columns 309 through 312

0.9890 1.0223

Columns 313 through 316

0.3637 0.4158 0.4753 0.5433 0.6208 0.7093 0.8103 0.9254 1.0568 0.3761 0.4299 0.4915 0.5617 0.6418 0.7333 0.8377 0.9567 1.0924

1.1292 1.1673 1.2066 1.2472

Columns 317 through 320

1.2892 1.3326 1.3774 1.4237

Columns 321 through 324

1.4715 1.5210 1.5721

Columns 325 through 328

1.6794 1.7357 1.7940

Columns 329 through 331

1.9163 1.9805 2.0468

t2

,0 t 1(4)z

4 t2 11 t 2,其中t 0:0.5:2.5

t2 2t 1,2 t 3提示:用逻辑表达式求分段函数值。 程序:

>> t=0:0.5:2.5;

>> z1=(t>0&t<=1).*t.^2; >> z2=(t>=1&t<2).*(t.^2-1); >> z3=(t>=2&t<3).*(t.^2-2*t+1); >> z=z1+z2+z3 z =

0 0.2500 1.0000 1.2500 1.0000

1234 4 1

3 1

2,已知 A

34

787 ,B

203 3

65

7 3

2

7

求下列表达式的值:

(1) A+6*B和A-B+I(其中I为单位矩阵) (2) A*B和A.*B

1.6249 1.8541 2.2500

(3) A^3和A.^3 (4) A/B及B\A

(5) [A,B]和[A([1,3],:);B^2] 程序: (1)

>> A=[12,34,-4;34,7,87;3,65,7]; >> B=[1,3,-1;2,0,3;3,-2,7]; >> I=eye(3); >> D=A+6*B 结果: D =

18 52 46 7 21 53 程序: >>D =A-B+I 结果: D=

12 31 32 8 0 67

(2) 程序: >> D=A*B 结果: D =

68 44 309 -72 154 -5 程序: >> D=A.*B 结果: D =

12 102 68 0 9 -130

(3)

-10 105

49 -3 84 1 62 596 241 4 261 49

>> D=A^3

D =

37226 233824 48604 247370 149188 600766 78688 454142 118820

>> D=A.^3 D =

1728 39304 -64 39304 343 658503 27 274625 343

(4) >> D=A/B D =

16.4000 -13.6000 7.6000 35.8000 -76.2000 50.2000 67.0000 -134.0000 68.0000

>> D=B\A

D =

109.4000 -131.2000 322.8000 -53.0000 85.0000 -171.0000 -61.6000 89.8000 -186.2000

(4) >> D=[A,B] D =

12 34 -4 1 3 -1 34 7 87 2 0 3 3 65 7 3 -2 7

>> D=[A([1,3],:);B^2]

D =

12 34 -4 3 65 7 4 5 1 11 0 19 20 -5 40

3,设有矩阵A和B

1 6 A 11

16 21

27121722

38131823

49141924

5 3

1017 15 ,B 0 20 9

25 4

0 623713

16

9 4 0 11

(1) 求它们的乘积C;

(2) 将矩阵C的右下角3*2子矩阵赋给D; (3) 察看matlab工作空间的使用情况。 程序: (1)

>> A=[1,2,3,4,5;6,7,8,9,10;11,12,13,14,15;16,17,18,19,20;21,22,23,24,25];

>> B=[3,0,16;17,-6,9;0,23,-4;9,7,0;4,13,11]; >> C=A*B 结果:

C =

93 150 77 258 335 237 423 520 397 588 705 557 753 890 717 (2)

>> D=C(3:5,2:3) 结果: D =

520 397 705 557 890 717

4,完成下列操作:

(1)求[100,999]之间能被21整除的数的个数。 提示:先利用冒号表达式,再利用find和length函数。 (2)建立一个字符串向量,删除其中的大写字母。 提示:利用find函数和空矩阵 程序: (1)

>> A=100:1:999; >> B=rem(A,21)==0; >> C=find(B==1); >> D=length(C) 结果: D =

43 (2)

>> x=input('请输入字符串向量:','s'); 请输入字符串向量:cToOmPpuIter >> y=find(x>='A'&x<='Z'); >> x(y)=[]; >> x x = computer

实验二 matlab矩阵分析与处理

1, 设有分块矩阵A 3*3

O2*3

E

R3*2

,其中E、R、O、S分别为单位矩阵、随机S2*2

E

R RS

2

S

矩阵、零矩阵和对角阵,试通过数值计算验证A2

O

>> E=eye(3); >> R=rand(3,2); >> O=zeros(2,3); >> S=diag(1:2); >> A=[E,R;O,S] A =

1.0000 0 0 0.9501 0.4860 0 1.0000 0 0.2311 0.8913 0 0 1.0000 0.6068 0.7621 0 0 0 1.0000 0 0 0 0 0 2.0000

>> A^2

ans =

1.0000 0 0 1.9003 1.4579 0 1.0000 0 0.4623 2.6739 0 0 1.0000 1.2137 2.2863 0 0 0 1.0000 0 0 0 0 0 4.0000

2, 建立一个5×5矩阵,求它的行列式的值、迹、秩和范数。

>> A=[-29,6,18;20,5,12;-8,8,5]; >> b=eig(A) b =

-25.3169 -10.5182

16.8351

>> [v,b]=eig(A) v =

0.7130 0.2803 0.2733 -0.6084 -0.7867 0.8725 0.3487 0.5501 0.4050 b =

-25.3169 0 0 0 -10.5182 0 0 0 16.8351

3,下面是一个线性方程组:

1/2 1/3 1/4

1/31/41/5

1/4 x1 0.95

1/5x2 0.67 1/6 x3 0.52

(1)求方程的解;

(2)将方程右边向量元素b3改为0.53,再求解,并比较b3的变化和解的相对变化。

(1)

>> A=[1/2,1/3,1/4;1/3,1/4,1/5;1/4,1/5,1/6]; >> C=[0.95;0.67;0.52];

>> B=A\C B =

1.2000 0.6000 0.6000

>> A=[1/2,1/3,1/4;1/3,1/4,1/5;1/4,1/5,1/6];C=[0.95;0.67;0.52]

C =

0.9500 0.6700 0.5200

MATLAB课后上机实验报告.doc 将本文的Word文档下载到电脑,方便复制、编辑、收藏和打印
    ×
    二维码
    × 游客快捷下载通道(下载后可以自由复制和排版)
    VIP包月下载
    特价:29 元/月 原价:99元
    低至 0.3 元/份 每月下载150
    全站内容免费自由复制
    VIP包月下载
    特价:29 元/月 原价:99元
    低至 0.3 元/份 每月下载150
    全站内容免费自由复制
    注:下载文档有可能出现无法下载或内容有问题,请联系客服协助您处理。
    × 常见问题(客服时间:周一到周五 9:30-18:00)