1、Matlab 入门到精通 ch022. 基础准备及入门 2.1 MATLAB 5.x 版对外部系统的要求 2.2 MATLAB 的安装 2.3 MATLAB 环境的启动 2.4 MATLAB 指令窗简介 2.4.1 工具条 2.4.2 菜单选项 2.5 指令窗运行入门 2.5.1 最简单的计算器使用法 2【例 2.5.1-1】求的算术运算结果。 12,2,(7,4),3(1)用键盘在 MATLAB 指令窗中输入以下内容 (12+2*(7-4)/32 (2)在上述表达式输入完成后,按【Enter】键,该就指令被执行。 (3)在指令执行后,MATLAB 指令窗中将显示以下结果。 ans = 2 1
2、23,,A,456【例 2.5.1-2】简单矩阵的输入步骤。 ,789,(1)在键盘上输入下列内容 A = 1,2,3; 4,5,6; 7,8,9 (2)按【Enter】键,指令被执行。 (3)在指令执行后,MATLAB 指令窗中将显示以下结果: A = 1 2 3 4 5 6 7 8 9 and other bad habits. Implementation to grab at the front, the maximum possible for jobs initiative to achieve efficient service. To carry forward the met
3、iculous, detailed style. In the Office is no small matter. Business services a small mistake, it is possible to order at its meetings disrupted the entire, feedback on the content and timing a bit negligent, it could work in a passive position, slightly poor reception, may affect the image of a plac
4、e and unit. Therefore, the Office staff with a high degree of professionalism and responsibility, serious and responsible, meticulous, careful to do everything to ensure that globalSmoothly. To carry forward the hard work, honest style. Adhere to the “Ning public and poverty, is not private and rich
5、“ old adage, bearing in mind the purpose of serving, consciously resist the erosion of various corruption and self-discipline, integrity, do not take leadership on behalf of the Office for personal affairs, not banner of leading organs of self-serving, and always maintain and carry forward the fine
6、style of hard work, thrift and career, be honest and upright. Comrades, Government Office work task is glorious, a great responsibility. Hope the citys system of Government Office around the overall situation, pay attention to implementation of work in the purpose, give full play to staff aides, int
7、egrated and coordinated implementation, supervision, service functions, close contact, strengthen coordination, collaboration, efforts for grass-roots leadership services, service, quality and level of services for the masses to push to a new level. 2003 annual summary meeting of the Office of the m
8、unicipal government reports on innovation 【例 2.5.1-3】矩阵的分行输入 A=1,2,3 4,5,6 7,8,9 (以下是显示结果) A = 1 2 3 4 5 6 7 8 9 【例 2.5.1-4】指令的续行输入(以下格式在除 Notebook 外的 MATLAB 环境中可运行) S = 1 1/2 + 1/3 1/4 + 1/5 1/6 . + 1/7 1/8 S = 0.6345 2.5.2 数值、变量和表达式 2.5.2.1 数值的记述 2.5.2.2 变量命名规则 2.5.2.3 MATLAB 默认的预定义变量 2.5.2.4 表达式
9、2.5.2.5 复数和复数矩阵 ,izz126z,【例 2.5.2.5-1】复数表达,及计算。 z,3,4i,z,1,2i,z,2e123z3(1)经典教科书的直角坐标表示法 z1= 3 + 4i z1 = 3.0000 + 4.0000i (2)采用运算符构成的直角坐标表示法和极坐标表示法 z2 = 1 + 2 * i %运算符构成的直角坐标表示法 z3=2*exp(i*pi/6) %运算符构成的极坐标表示法 z=z1*z2/z3 z2 = 1.0000 + 2.0000i z3 = 1.7321 + 1.0000i z = 0.3349 + 5.5801i and other bad ha
10、bits. Implementation to grab at the front, the maximum possible for jobs initiative to achieve efficient service. To carry forward the meticulous, detailed style. In the Office is no small matter. Business services a small mistake, it is possible to order at its meetings disrupted the entire, feedba
11、ck onthe content and timing a bit negligent, it could work in a passive position, slightly poor reception, may affect the image of a pl ace and unit. Therefore, the Office staff with a high degree of professionalism and responsibility, serious and responsible, meticulous, careful to do everything to
12、 ensure that globalSmoothly. To carry forward the hard work, honest style. Adhere to the “Ning public and poverty, is not private and rich“ old adage, bearing in mind the purpose of serving, consciously resist the erosion of various corruption and selfdiscipline,- integrity, do not take leadership o
13、n behalf of the Office for personal affairs, not banner of leading organs of selfser-ving, and always maintain and carry forward the fine style of hard work, thrift and career, be honest and upright. Comrades, Government Office work task is glorious, a great responsibility. Hope the citys system of
14、Government Office around the overall situation, pay attention to implementation of work in the purpose, give full play to staff aides, integrated and coordinated implementation, supervision, service functions, close contact, strengthen coordination, collaboration, efforts for grassroots leadership s
15、ervices, service, quality and level of services for the -masses to push to a new level. 2003 annual summary meeting of the Office of the municipal government reports on innovation2 【例 2.5.2.5-2】复数矩阵的生成及运算 A=1,3;2,4-5,8;6,9*i B=1+5i,2+6i;3+8*i,4+9*i C=A*B A = 1.0000 - 5.0000i 3.0000 - 8.0000i 2.0000
16、- 6.0000i 4.0000 - 9.0000i B = 1.0000 + 5.0000i 2.0000 + 6.0000i 3.0000 + 8.0000i 4.0000 + 9.0000i C = 1.0e+002 * 0.9900 1.1600 - 0.0900i 1.1600 + 0.0900i 1.3700 【例 2.5.2.5-3】求上例复数矩阵 C 的实部、虚部、模和相角。 C_real=real(C) C_imag=imag(C) C_magnitude=abs(C) C_phase=angle(C)*180/pi %以度为单位计算相角 C_real = 99 116 11
17、6 137 C_imag = 0 -9 9 0 C_magnitude = 99.0000 116.3486 116.3486 137.0000 C_phase = 0 -4.4365 4.4365 0 2.5.3 计算结果的图形表示 tt,33【例 2.5.3-1】画出衰减振荡曲线及其它的包络线。的取值范围是y,ety,esin3t0。 0,4,t=0:pi/50:4*pi; %定义自变量取值数组 y0=exp(-t/3); %计算与自变量相应的 y0 数组 y=exp(-t/3).*sin(3*t); %计算与自变量相应的 y 数组 plot(t,y,-r,t,y0,:b,t,-y0,:b
18、) %用不同颜色、线型绘制曲线 grid %在“坐标纸”画小方格 and other bad habits. Implementation to grab at the front, the maximum possible for jobs initiative to achieve efficient service. To carry forward the meticulous, detailed style. In the Office is no small matter. Business services a small mistake, it is possible to o
19、rderat its meetings disrupted the entire, feedback on the content and timing a bit negligent, it could work in a passive position , slightly poor reception, may affect the image of a place and unit. Therefore, the Office staff with a high degree of professionalism and responsibility, serious and res
20、ponsible, meticulous, careful to do everything to ensure that globalSmoothly. To carry forward the hard work, honest style. Adhere to the “Ning public and poverty, is not private and rich“ old adage, bearing in mind the purpose of serving, consciously resist the erosion of various corruption and sel
21、fdiscipline,- integrity, do not take leadership on behalf of the Office for personal affairs, not banner of leading organs of selfser-ving, and always maintain and carryforward the fine style of hard work, thrift and career, be honest and upright. Comrades, Government Office work task is glori ous,
22、a great responsibility. Hope the citys system of Government Office around the overall situation, pay attention to implementation of work in the purpose, give full play to staff aides, integrated and coordinated implementation, supervision, service functions, close contact, strengthen coordination, c
23、ollaboration, efforts for grassroots leadership services, service, quality a-nd level of services for the masses to push to a new level. 2003 annual summary meeting of the Office of the municipal government reports on innovation3 10.80.60.40.20-0.2-0.4-0.6-0.8-102468101214图 2.5.3-1 衰减振荡曲线与包络 22sin(x
24、,y)【例 2.5.3-2】画出所表示的三维曲面。的取值范围是。 x,yz,8,822x,yclear;x=-8:0.5:8; %定义自变量 x 的一维刻度向量 y=x; %定义自变量 y 的一维刻度向量 X=ones(size(y)*x; %计算自变量平面上取值点坐标的二维数组 xY=y*ones(size(x); %计算自变量平面上取值点坐标的二维数组 y22R,x,yR=sqrt(X.2+Y.2)+eps; %计算中间变量 sinRz,Z=sin(R)./R; %计算与自变量二维数组相应的函数值 Rmesh(Z); %绘制三维网格图 colormap(hot) %指定网格图用 hot 色
25、图绘制 图 2.5.3-2 三维网线图 and other bad habits. Implementation to grab at the front, the maximum possible for jobs initiative to achieve efficient service. To carry forward the meticulous, detailed style. In the Office is no small matter. Business services a small mistake, it is possible to order at its m
26、eetings disrupted the entire, feedback onthe content and timing a bit negligent, it could work in a passive position, slightly poor reception, may affect the image of a pl ace and unit. Therefore, the Office staff with a high degree of professionalism and responsibility, serious and responsible, met
27、iculous, careful to do everything to ensure that globalSmoothly. To carry forward the hard work, honest style. Adhere to the “Ning public and poverty, is not private and rich“ old adage, bearing in mind the purpose of serving, consciously resist the erosion of various corruption and selfdiscipline,-
28、 integrity, do not take leadership on behalf of the Office for personal affairs, not banner of leading organs of selfser-ving, and always maintain and carry forward the fine style of hard work, thrift and career, be honest and upright. Comrades, Government Office work task is glorious, a great respo
29、nsibility. Hope the citys system of Government Office around the overall situation, pay attention to implementation of work in the purpose, give full play to staff aides, integrated and coordinated implementation, supervision, service functions, close contact, strengthen coordination, collaboration,
30、 efforts for grassroots leadership services, service, quality and level of services for the -masses to push to a new level. 2003 annual summary meeting of the Office of the municipal government reports on innovation4 2.6 控制指令窗的指令、操作和标点 2.6.1 常用控制指令 2.6.2 数值计算结果的显示格式 2.6.3 指令行的编辑 【例 2.6.3-1】指令行操作过程示例。 2sin(0.3),(1)若用户想计算的值,那末用户应依次键入以下字符 ,y11,5y1=2*sin(0.3*pi)/(1+sqrt(5) (2)按【Enter】键,该指令便被执行,并给出以下结果 y1 = 0.5000 在以上操作和计算结束后,操作指令和计算结果都记录在 MATLAB 工作内存中。因此,假如用户希望调回前面输入的指令重新运行,或希望对前面输入的指令加以修改后再运行,那末只要反复按动键盘上的箭头键,就可从内存中把以前输入的那指令调回到当前行,以供重新运行或修改后运行。新的计算结果,只可能被此后运行的指令所使用,而绝不会影响以前生成的(非同名)变量的“内容”。