matlab上机作业

合集下载
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

实验题目:matlab运行环境的熟悉及基本命令的练习
一、熟悉matlab的command window、workspace window、history window、current directry
window. 弄清楚各个窗口的基本作用与其中常用的设置。

二、在命令窗口直接输入Realmax、Realmin、eps 、pi 、inf、NaN 查看当前版本中,
这些变量代表什么值,并说明含意
>> realmax ans =
1.7977e+308 >> realmin ans =
2.2251e-308 >> eps ans =
2.2204e-016
>> pi
ans =
3.1416
>> inf
ans =
Inf
>> nan
ans =
NaN
>> NaN
ans =
NaN
三、练习对变量赋值、使用加、减、乘、左除、右除、矩阵元素右除“A./B”与左除“A.\B”、
矩阵元素幂“.^”:A.^B、矩阵元素相乘“.*”:A.*B命令进行计算,自己给具体的计算的例子,要求其中的变量分别采用标量和矩阵的形式,并验证结果。

>> a=[1,2,3;4,5,6,;7,8,9]
a =
1 2 3
4 5 6
7 8 9
>> b=[9,8,7;6,5,4;3,2,1]
b =
9 8 7
6 5 4
3 2 1
>> a+b
ans =
10 10 10
10 10 10
10 10 10
>> a-b
ans =
-8 -6 -4
-2 0 2
4 6 8
>> a*b
ans =
30 24 18
84 69 54
138 114 90
>> a/b
Warning: Matrix is singular to working precision.
ans =
NaN NaN NaN
NaN NaN NaN
NaN -Inf Inf >> a\b
Warning: Matrix is close to singular or badly scaled.
Results may be inaccurate. RCOND = 2.203039e-018.
ans =
0.1989 1.1989 -3.4005
-12.3978 -13.3978 -3.1989
11.1989 11.1989 5.5995
>> a./b
ans =
0.1111 0.2500 0.4286
0.6667 1.0000 1.5000
2.3333 4.0000 9.0000
>> a.\b
ans =
9.0000 4.0000 2.3333
1.5000 1.0000 0.6667
0.4286 0.2500 0.1111
>> a.^b
ans =
1 256 2187
4096 3125 1296
343 64 9 >> a.*b
ans =
9 16 21
24 25 24
21 16 9
四、练习使用who、whos、help、lookfor、demo命令。

>> who Your variables are: a ans b
>> whos
Name Size Bytes Class
a 3x3 72 double array
ans 3x3 72 double array
b 3x3 72 double array Grand total is 27 elements using 216 bytes
五、练习使用rand、zeros、eye、ones命令,给出具体的例子。

>> clear all
>> rand(1,7)
ans =
0.9501 0.2311 0.6068 0.4860 0.8913 0.7621 0.4565
>> zeros(2,3)
ans =
0 0 0
0 0 0
>> rand(3,2)
ans =
0.9218 0.4057
0.7382 0.9355
0.1763 0.9169
>> eye(6,5)
ans =
1 0 0 0 0
0 1 0 0 0
0 0 1 0 0
0 0 0 1 0
0 0 0 0 1
0 0 0 0 0
六、练习使用linspace、logspace命令,给出具体的例子
>> clear all
>> x1=1 x1 =1
>> x2=10 x2 =10
>> y=linspace(x1,x2)
y =Columns 1 through 9
1.0000 1.0909 1.1818 1.2727 1.3636 1.4545 1.5455 1.6364 1.7273 Columns 10 through 18
1.8182 1.9091
2.0000 2.0909 2.1818
2.2727 2.3636 2.4545 2.5455 Columns 19 through 27
2.6364 2.7273 2.8182 2.9091
3.0000
3.0909 3.1818 3.2727 3.3636 Columns 28 through 36
3.4545 3.5455 3.6364 3.7273 3.8182 3.9091
4.0000 4.0909 4.1818 Columns 37 through 45
4.2727 4.3636 4.4545 4.5455 4.6364 4.7273 4.8182 4.9091
5.0000 Columns 46 through 54
5.0909 5.1818 5.2727 5.3636 5.4545 5.5455 5.6364 5.7273 5.8182 Columns 55 through 63
5.9091
6.0000 6.0909 6.1818 6.2727
6.3636 6.4545 6.5455 6.6364 Columns 64 through 72
6.7273 6.8182 6.9091
7.0000 7.0909
7.1818 7.2727 7.3636 7.4545 Columns 73 through 81
7.5455 7.6364 7.7273 7.8182 7.9091
8.0000 8.0909 8.1818 8.2727 Columns 82 through 90
8.3636 8.4545 8.5455 8.6364 8.7273 8.8182 8.9091 9.0000 9.0909 Columns 91 through 99 9.1818 9.2727 9.3636 9.4545 9.5455 9.6364 9.7273 9.8182 9.9091 Column 100 10.0000
>> y=linspace(x1,x2,10)
y = 1 2 3 4 5
6 7 8 9 10
>> y=logspace(1,4,4)
y =10 100 1000 10000
七、1、练习使用正弦函数,给出当变量为实数、复数、矩阵时的计算例子,并给出结果。

联系其他的三角函数。

>> x=[1,2,3;4,5,6;7,8,9]
x =
1 2 3
4 5 6
7 8 9
>> a=sin(x)
a =
0.8415 0.9093 0.1411
-0.7568 -0.9589 -0.2794
0.6570 0.9894 0.4121 >> y=[9,8,7;6,5,4;3,2,1]
y =
9 8 7
6 5 4
3 2 1 >> z=1+2i
z =1.0000 + 2.0000i
>> c=sin(z)
c =3.1658 + 1.9596i
>> w=5
w = 5
>> d=sin(w)
d = -0.9589
>> e=cos(x)
e =
0.5403 -0.4161 -0.9900
-0.6536 0.2837 0.9602
0.7539 -0.1455 -0.9111 >> f=atan(w)
f = 1.3734
2、练习使用log、log2、sqrt、pow2、real、imag、abs、angle、conj 、fix 、floor 、
ceil 、round、mod、rem、sign命令自己设计具体的例子,并给出结果。

>> clear all >> x=5;a=log(x) a =1.6094 >> b=log2(x)
b = 2.3219 >> c=sqrt(x)
c =2.2361 >> d=pow2(x)
d =32 >> e=real(x)
e =5
>> f=imag(x)
f =0
>> g=abs(x)
g =5
>> h=angle(x)
h = 0
>> j=conj(x)
j =5
>> k=fix(x) k =5
>> l=floor(x) l =5
>> m=ceil(x) m =5
>> n=round(x) n =5
>> y=mod(d,x) y =2
>> w=rem(d,x) w =2
>> s=sign(x) s =1
八、在命令窗口输入figure回车后再输入figure回车再输入figure回车,观察生成的三个窗
口有什么区别。

然后令figure; a=1:0.2:10; b=sin(a); plot(a,b)
观察在哪个figure图形窗口画出的图figure 4 出现正弦波形
然后figure(2);a=1:0.2:10;b=sin(a);plot(a,b)
观察在哪个figure图形窗口画出的图figure 2 出现正弦波形
close all;a=1:0.2:10;b=sin(a);plot(a,b)
观察会出现什么现象。

figure 1 出现正弦波形,其他figure关闭。

九、练习编写.m文件。

在file 菜单下选择new在选择M-File程序会自动为其添加后缀。

编写程序的要求及注意事项:
1 该程序中要求用到至少一个关系或者逻辑操作符。

2 程序中至少要用到for、while、switch、if、等流程控制语句。

3 注意每个语句结尾处加;号,不加分号的区别,自己试一下看看运行时命令窗口的
显示会有什么不同。

4 在程序最前端加上clear all;命令,说明加上这条命令的原因。

程序的运行:如下图,进入文本编辑界面进行编写,写完程序后保存,即编写好.m文件,保存时不用加后缀.m,系统会自动为其加上后缀.m,就像编写word文档保存时,不用自己添加后缀,
1 在命令窗口直接输入不带后缀的文件名然后回车,则程序运行。

2 运行完程序后,在workspace 窗口观察,程序中的变量值。

>> clear all
>>a=5;c=1;h=5;if a>6 c=7 h=9;end g=8;
>>ketang
h= 5。

相关文档
最新文档