MATLAB原理及应用2

上传人:简****9 文档编号:112806000 上传时间:2019-11-07 格式:PPT 页数:68 大小:1.59MB
返回 下载 相关 举报
MATLAB原理及应用2_第1页
第1页 / 共68页
MATLAB原理及应用2_第2页
第2页 / 共68页
MATLAB原理及应用2_第3页
第3页 / 共68页
MATLAB原理及应用2_第4页
第4页 / 共68页
MATLAB原理及应用2_第5页
第5页 / 共68页
点击查看更多>>
资源描述

《MATLAB原理及应用2》由会员分享,可在线阅读,更多相关《MATLAB原理及应用2(68页珍藏版)》请在金锄头文库上搜索。

1、MATLAB原理及应用,矩阵的操作,MATLAB的help,MATLAB的help,Help 的详细使用见MATLAB/Getting Started/Desktop Tools and Development Environment/Getting Help,MATLAB的help,MATLAB帮助函数,help funcname: Displays in the Command window a description of the specified function funcname. lookfor topic: Looks for the string topic in the f

2、irst comment line (the H1 line) of the HELP text of all M-files found on MATLABPATH (including private directories), and displays the H1 line for all files in which a match occurs. doc funcname: Opens the Help Browser to the reference page for the specified function funcname, providing a description

3、, additional remarks, and examples.,Entering Commands and Expressions, MATLAB retains your previous keystrokes. Use the up-arrow key to scroll back back through the commands.Press the key once to see the previous entry, and so on. Use the down-arrow key to scroll forward. Edit a line using the left-

4、 and right-arrow keys the Backspace key, and the Delete key. Press the Enter key to execute the command.,管理工作进程的命令,分号; 抑制输出 省略号三个点 如果输入语句太长,一行放不下,就用省略号, 然后按回车表明下行接着写,如 s = 1 -1/2 + 1/3 -1/4 + 1/5 - 1/6 + 1/7 . - 1/8 + 1/9 - 1/10 + 1/11 - 1/12;,控制命令窗口输入输出显示,格式函数format (见help说明) format 控制MATLAB显示的数值的格

5、式,它只影响数的显示,不影响MATLAB如何计算它或保存它。,输入/输出命令,系统、目录、文件命令,向量的产生 矩阵的产生 矩阵的基本操作 矩阵中元素的获取 改变矩阵形状 矩阵信息的获取,变量(variable),不必事先声明 变量名可包含最多63个字符 变量名必须以字母开头,后面可跟字母,数字和下划线 变量区分大小写,MATLAB如何识别变量,When you type problem1, 1. MATLAB first checks to see if problem1 is a variable and if so, displays its value. 2. If not, MATL

6、AB then checks to see if problem1 is one of its own commands, and executes it if it is. 3. If not, MATLAB then looks in the current directory for a file named problem1.m and executes problem1 if it finds it. 4. If not, MATLAB then searches the directories in its search path, in order, for problem1.m

7、 and then executes it if found.,MATLAB特殊变量(常数),ans 缺省变量名 pi 3.1415926. eps 最小增量数 2(-52) Inf 无穷 NaN 非数 如0/0 realmin 最小浮点数 2.2251e-308 realmax 最大浮点数 1.7977e+308 i,j 虚数单位,标量(scalar),7, 583.62, -3.51, 5.46097e-14, 83+4i,向量(vector ),矩阵(matrix,array),53.2 87 .39 4-12i 43.9,1 2 3 8 4 5 6 0 4 7 8 7,产生向量,向量:

8、向量元素用逗号或空格隔开,再用方括号括起来产生行向量 p = 3,7,9 p = 3 7 9 用()将行向量转置产生列向量. p = 3,7,9 p = 3 7 9 g = 3;7;9,数值序列也可产生向量,中括号不要 x = m:q:n 如果m-n是q的整数倍,产生的向量的最后一个值是n 如果x = 0:2:8 ,则产生的向量 x = 0,2,4,6,8 如果m-n不是q的整数倍,产生的向量的最后一个值小于n 如果x = 0:2:7 ,则产生的向量x = 0,2,4,6,数值序列(也可产生向量),缺省步长为整数1 A = 10:15 A = -2.5:2.5 A = 1:6.3(即使结尾的值

9、是小数,产生的序列都是整数) A = 1 2 3 4 5 6 设置任意步长值 (步长分别为整数、小数、负数) A = 10:5:50 A = 3:0.2:3.8 A = 9:-1:1,可作下标 A(1:100) 可作循环变量取值 i=1: 2:15 可生成向量或数组 a=100:-1:50,linspace命令,命令linspace产生线性间隔行向量,只能定义元素个数不能定义增量(步长) linspace(x1,x2,n) where x1 and x2 are the lower and upper limits and n is the number of points. If n is

10、omitted, the spacing is 1. linspace(5,8,31) is equivalent to 5:0.1:8.,Logspace对数间隔命令,Its syntax is logspace(a,b,n), where n is the number of points between 10a and 10b. For example, x = logspace(-1,1,4) produces the vector x = 0.1000, 0.4642, 2.1544, 10.000. If n is omitted, the number of points def

11、aults to 50.,Magnitude, Length, and Absolute Value 的区别,注意help文档中Magnitude length absolute value的区别 Length指的是向量中元素个数 Magnitude指的是 向量中元素的开平方(x12 + x22 + + xn2)与向量的几何长度一样 absolute value指的是向量中每一个元素的绝对值 For example if x = 2,-4,5, its length is 3; (computed from length(x) its magnitude is 22 + (4)2 + 52 =

12、 6.7082; (computed from sqrt(x*x) its absolute value is 2,4,5 (computed from abs(x).,矩阵(matrix)的输入,输入明确的元素清单 元素间用空格或逗号隔开 行与行用分号或回车(enter)隔开 用方括号括起所有元素 -1 2 3 4 5; 4 5 6 -7 8; 1 2 3 -9 3 -1,2, 3, 4, 5; 4, 5, 6, -7, 8; 1, 2, 3, -9, 3 用MATLAB内部函数产生矩阵 B=magic(4) D = 1,3,5;7,9,11;,矩阵元素的获取,获取单个元素 双下标表示A(i

13、,j) 代表矩阵A的第i行第j列的元素 单下标表示A(i) 代表矩阵A的存储的第i个元素 A = 2 6 9; 4 2 8; 3 5 1 A = 2 6 9 4 2 8 3 5 1 矩阵中元素在内存中按列存储: 2, 4, 3, 6, 2, 5, 9, 8, 1,矩阵元素的获取,获取多个元素 获取连续元素 A(1:m, n) 获取A矩阵第n列1到m个元素 A(:) 获取A矩阵中所有的元素 A = magic(4); A(1,4) + A(2,4) + A(3,4) + A(4,4) 等同 sum(A(1:4, 4) 获取不连续元素 A(a:s:m, n) A(行向量, n),矩阵中不连续元素的

14、获取,A = magic(4) B = A; B(1:3:16) = -10 B = -10 2 3 -10 5 11 -10 8 9 -10 6 12 -10 14 15 -10,A = 5:5:50 B = 1 3 6 7 10; A(B) ans = 5 15 30 35 50,关键字end,end代表数组或矩阵中最后一个元素。 编程时,不知道矩阵的维数时,在获取最后一个元素时很有用。 B(1:3:16) = -10 等同 B(1:3:end) = -10,冒号的使用,表示元素间隔单位 0:pi/4:pi 表示引用矩阵的元素 A(1:k,j) 矩阵A第j列前k个元素 A(:,j) 矩阵A

15、第j列所有元素 A(:,end)矩阵A最后一列所有元素 A(:) 矩阵A所有元素,输出以列向量显示 A = B(:,1 3 2 4) 交换矩阵B的中间两列变成A A(1,:)= 删除A矩阵的第一行,矩阵基本信息函数,矩阵基本信息函数,min 求数组里面元素的最小值 x = min(A) 若A是向量,就求所有元素最小值,x是一标量; 若A是矩阵,就按列求每列元素最小值, x是一行向量 x,k=min(A) x包含A矩阵的最小值,k包含最小值的位置编号 max 求数组里面元素的最大值 x=max(A) x,k=max(A),矩阵的调整,减少矩阵元素 A = magic(4) A = 16 2 3 13 5 11 10 8 9 7 6 12 4 14 15 1 A(:, 2) = 删除A矩阵第2列 A(2:2:10) = 删除A矩阵第2到10个元素,矩阵的调整,矩阵的调整,调整矩阵形状 reshape 修改矩阵形状 A = 1 4 7 10; 2 5 8 11; 3 6 9 12 A = 1 4 7 10 2 5 8 11 3 6 9 12 B = reshape(A, 2, 6) B = 1 3 5 7 9 11 2 4 6 8 10 12,矩阵的调整,调整矩阵形状 fliplr 水平翻转矩阵 A = 1 4 7 10; 2 5 8 11; 3 6 9 12 A = 1 4 7

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 商业/管理/HR > 管理学资料

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号