第一章M A T L A B概况与基本操作1.选择题:(1)最初的MATLAB核心程序是采用A语言编写的。
A.FORTRANB.CC.BASICD.PASCAL(2)即将于2011年9月发布的MATLAB新版本的编号为D。
A.MATLAB 2011RaB.MATLAB 2011RbC.MATLAB R2011aD.MATLAB R2011b(3)在默认设置中,MATLAB中的注释语句显示的颜色是D。
A.黑色B.蓝色C.红色D.绿色(4)如果要以科学计数法显示15位有效数字,使用的命令是B。
A.format longB.format long eC.format long gD.format long d(5)在命令窗口新建变量a、b,如果只查看变量a的详细信息,使用的命令为B。
A.who aB.whos aC.whoD.whos(6)如果要清除工作空间的所有变量,使用的命令为 C 。
A.clearB.clear allC.两者都可D.两者都不可(7)在创建变量时,如果不想立即在命令窗口中输出结果,可以在命令后加上D。
A.冒号B.逗号C.空格D.分号(8)如果要重新执行以前输入的命令,可以使用B键。
A.下箭头↓B.上箭头↑C.左箭头←D.右箭头→(9)如果要查询函数inv的相关信息,并显示在命令窗口,应使用命令A。
A.helpB.lookforC.docD.三者均可(10)如果要启动Notebook文档,下列D操作是可行的。
A.在命令窗口输入notebook命令B.在命令窗口输入notebook filename命令C.在Word中启动M-book文档D.三者均可2.填空题:(1)MATLAB是MATrix和LABoratory两个单词前三个字母的组合,意为“矩阵实验室”,它的创始人是Cleve Moler和Jack Little。
(2)在MATLAB的默认设置中,关键字显示的字体为蓝色,命令、表达式、计算结果显示的字体为黑色,字符串显示的字体为紫色,注释显示的字体为绿色,错误信息显示的字体为红色。
(3)在命令窗口中,输出结果显示为各行之间添加空行的命令为format compact,各行之间不添加空行的命令为format compact。
备注:本题布置给大家时有一点小错误,现在予以更正。
(4)在MATLAB中,各种标点符号的作用是不同的。
例如,空格的作用是分隔数组中每一行的各个元素,逗号的作用是分隔数组中每一行的各个元素或不同的命令,分号的作用是分隔数组中的各行或控制命令执行结果是否在命令窗口显示,冒号的作用是生成一维数组或显示全部元素,百分号的作用是注释行的开头,…的作用是把相邻两行的语句连接为一个命令,感叹号的作用是执行操作系统命令。
3.先建立自己的工作目录,再将自己的工作目录设置到MATLAB搜索路径下。
请写出操作步骤或用Matlab命令实现。
用help命令能查询到自己的工作目录吗?解:操作步骤:(1)在Windows环境中建立一个工作目录,如:c:\mywork;(2)启动MATLAB,在File菜单中选择Set Path…命令,显示出如下图的对话框:(3)选择Add Folder…按钮,又显示出如下图的对话框:(4)在该对话框中找到c:\mywork文件夹,选择确定按钮。
(5)返回步骤(2)的对话框,选择Save按钮,然后选择Close按钮,关闭对话框。
(注意:选择Save和Close按钮的次序不能错,如果先选择Close按钮,就会直接关闭对话框,而不会将你的工作目录添加到搜索路径中。
采用这种方法设置的工作路径是永久性的,只要不在步骤(2)的对话框中选择Remove按钮移除该文件夹,那么你在该文件夹中保存的文件MATLAB总能找到。
4.利用MATLAB的帮助功能分别查询inv、plot、max、round等函数的功能及用法。
解:所使用的命令分别为help invINV Matrix inverse.INV(X) is the inverse of the square matrix X.A warning message is printed if X is badly scaled ornearly singular.See also SLASH, PINV, COND, CONDEST, LSQNONNEG, LSCOV.Overloaded functions or methods (ones with the same name in other directories) help gf/inv.mhelp lti/inv.mhelp idmodel/inv.mhelp atom/inv.mhelp ndlft/inv.mhelp ufrd/inv.mhelp umat/inv.mhelp uss/inv.mhelp sym/inv.mReference page in Help browserdoc invhelp plotPLOT Linear plot.PLOT(X,Y) plots vector Y versus vector X. If X or Y is a matrix,then the vector is plotted versus the rows or columns of the matrix,whichever line up. If X is a scalar and Y is a vector, disconnectedline objects are created and plotted as discrete points vertically atX.PLOT(Y) plots the columns of Y versus their index.If Y is complex, PLOT(Y) is equivalent to PLOT(real(Y),imag(Y)).In all other uses of PLOT, the imaginary part is ignored.Various line types, plot symbols and colors may be obtained withPLOT(X,Y,S) where S is a character string made from one elementfrom any or all the following 3 columns:b blue . point - solidg green o circle : dottedr red x x-mark -. dashdotc cyan + plus -- dashedm magenta * star (none) no liney yellow s squarek black d diamondw white v triangle (down)^ triangle (up)< triangle (left)> triangle (right)p pentagramh hexagramFor example, PLOT(X,Y,'c+:') plots a cyan dotted line with a plusat each data point; PLOT(X,Y,'bd') plots blue diamond at each datapoint but does not draw any line.PLOT(X1,Y1,S1,X2,Y2,S2,X3,Y3,S3,...) combines the plots defined bythe (X,Y,S) triples, where the X's and Y's are vectors or matricesand the S's are strings.For example, PLOT(X,Y,'y-',X,Y,'go') plots the data twice, with asolid yellow line interpolating green circles at the data points.The PLOT command, if no color is specified, makes automatic use ofthe colors specified by the axes ColorOrder property. The defaultColorOrder is listed in the table above for color systems where thedefault is blue for one line, and for multiple lines, to cyclethrough the first six colors in the table. For monochrome systems,PLOT cycles over the axes LineStyleOrder property.If you do not specify a marker type, PLOT uses no marker.If you do not specify a line style, PLOT uses a solid line.PLOT(AX,...) plots into the axes with handle AX.PLOT returns a column vector of handles to lineseries objects, onehandle per plotted line.The X,Y pairs, or X,Y,S triples, can be followed byparameter/value pairs to specify additional propertiesof the lines. For example, PLOT(X,Y,'LineWidth',2,'Color',[.6 0 0])will create a plot with a dark red line width of 2 points.Examplex = -pi:pi/10:pi;y = tan(sin(x)) - sin(tan(x));plot(x,y,'--rs','LineWidth',2,...'MarkerEdgeColor','k',...'MarkerFaceColor','g',...'MarkerSize',10)See also PLOTTOOLS, SEMILOGX, SEMILOGY, LOGLOG, PLOTYY, PLOT3, GRID,TITLE, XLABEL, YLABEL, AXIS, AXES, HOLD, LEGEND, SUBPLOT, SCATTER, PLOT3.Overloaded functions or methods (ones with the same name in other directories) help SimTimeseries/plot.mhelp timeseries/plot.mhelp phytree/plot.mhelp channel/plot.mhelp cfit/plot.mhelp darray/plot.mhelp fints/plot.mhelp iddata/plot.mhelp idfrd/plot.mhelp idmodel/plot.mhelp idnlarx/plot.mhelp idnlhw/plot.mhelp cgrules/plot.mhelp localavfit/plot.mhelp localmod/plot.mhelp localmulti/plot.mhelp xregarx/plot.mhelp xregmodel/plot.mhelp xregtransient/plot.mhelp xregtwostage/plot.mhelp mdevtestplan/plot.mhelp sweepset/plot.mhelp cgdatasetnode/plot.mhelp mpc/plot.mhelp rfckt/plot.mhelp frd/plot.mhelp dspdata/plot.mhelp dtree/plot.mhelp ntree/plot.mhelp wdectree/plot.mhelp edwttree/plot.mhelp rwvtree/plot.mhelp wvtree/plot.mReference page in Help browserdoc plothelp maxhelp round备注:后两个命令的执行结果这里就不再显示出来了,同学们可以自己执行一下。