1 / 22

王国利

Matlab 计算与仿真技术 第六讲 : 交互式计算 -IV. 王国利. http://human-robot.sysu.edu.cn. 信息科学与技术学院. 中山大学. 第六讲提纲. 综合联系 交互式计算 -IV. 综合练习. 综合练习三 : 基于函数 eye 创建矩阵 - 提示 1: 借助矩阵翻转操作 回忆 : >> lookfor flip??? - 提示 2: 矩阵的算术运算 回忆 : >> A*c; %=[a ij* c ]. 综合练习 ( 续 ). - 提示 3: 矩阵左右翻转函数

kiril
Télécharger la présentation

王国利

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Matlab计算与仿真技术 第六讲: 交互式计算-IV 王国利 http://human-robot.sysu.edu.cn 信息科学与技术学院 中山大学

  2. 第六讲提纲 • 综合联系 • 交互式计算-IV

  3. 综合练习 • 综合练习三: 基于函数eye创建矩阵 - 提示1: 借助矩阵翻转操作 回忆: >> lookfor flip??? - 提示2: 矩阵的算术运算 回忆: >> A*c; %=[aij*c]

  4. 综合练习(续) - 提示3: 矩阵左右翻转函数 回忆: >> fliplr(A); % 列指标逆序矩阵 - 求解 >> Tem=fliplr(eye(3)); % 单位阵的左右翻转 >> (-2)*Tem % ans = 0 0 -2 0 -2 0 -2 0 0 >> flipud(A)

  5. 综合练习(续) • 综合练习四: 求解下述线性方程组 - 求解: >> A=[2 1 -5 1; 1 -3 0 -6;… 0 2 -1 2; 1 4 -7 6]; >> b=[8; 9; -5; 0] >> x=b’/A % x=A\b

  6. 交互式计算 (续) - 矩阵整形操作 拼接操作 >> cat(dim,A1,A2,…); >> blkdiag(A1,A2,…); 功能: 按行或列拼接矩阵, 或按对角块方式组织 特别地 >> cat(1,A,B); % == [A;B] >> cat(2,A,B); % == [A,B] 举例: >> cat(2,A’,B’) >> A=[1:4]; B=[5:8]; ans= >> cat(1,A,B) 1 5 ans = 2 6 1 2 3 4 3 7 5 6 7 8 4 8

  7. 交互式计算 (续) - 矩阵整形操作 块提取操作: diag(对角元素)/tril(下三角)/triu(上三角) 基本格式: >> diag(A); % 返回对角向量 >> tril(A); % 上三角元素清零 >> triu(A); % 下三角元素清零 功能:提取对角块/下三角/上三角块 举例: >> triu(A) >> A=[1:3; 4:6]; ans = >> diag(A) >> tril(A) 1 2 3 ans = ans = 0 5 6 1 1 0 0 5 4 5 0

  8. 交互式计算 (续) • 数据类型使用注解 - 更多的常用数据类型 复数 字符串 多项式 数组 结构 胞组 对象

  9. 交互式计算 (续) • 关于复数 - 虚数单位 内置变量: i/j(=sqrt(-1)) >> i^2 ans = -1 提示: 应尽量避免利用其自定义变量 - 内置函数 >> abs % 幅值 >> exp % 指数 >> angle % 复角 >> imag % 实部 >> conj % 共扼 >> real % 虚部

  10. 交互式计算 (续) - 使用实例 >> zeta=5; theta=pi/3; % 幅值和复角 >> z=zeta*exp(i*theta) z = 2.5000+4.3301i >> abs(z) >> real(z) ans = ans = 5.0000 2.5000 >> angle(z)*108/pi >> imag(z) ans = ans = 60.0000 4.3301

  11. 交互式计算 (续) • 关于字符串 - 基本概念 元素为字符的矩阵 单引号方式赋值 引用方式同矩阵 - 使用实例 >> first=‘john’; >> length(name) >> last=‘coltrane’; ans = >> name=[first,’ ’,last] 13 name = john coltrane

  12. 交互式计算 (续) - 常用操作函数 转换操作 >>char 操作 功能:将整数转换成对应的ASCII码字符 另:可将两个字符串拼接 >>num2str 操作 功能:将数值矩阵转换成字符串文本 >> str2num操作 功能:将字符串文本转换成数值矩阵

  13. 交互式计算 (续) 查询操作 >> findstr 功能:查找感兴趣的子字符串 对比操作 >> strcmp 功能:比较两个字符串,返回逻辑值 >> strncmp 功能:只比较字符串的前n个字符

  14. 交互式计算 (续) >> strmatch 功能:依行进行前端匹配查询 返回前端匹配的行下标 拼接操作 >> strcat 功能:行方式拼接字符串 >> strvcat 功能:列方式拼接字符串

  15. 交互式计算 (续) 使用实例 >> msg1=[‘there are’, num2str(100/2.45),… ‘inch in meter’] msg1 = there are 39.3701 inch in meter >> msg2=sprintf(‘there are %5.2f cubic … inches in a liter’, … 1000/2.54^3) msg2 = there are 61.02 inches in a liter

  16. 交互式计算 (续) >> both=strvcat(msg1,msg2) both = there are 39.3701 inch in meter there are 61.02 inches in a liter >> strcmp(msg1,msg2) ans = 0 >> strncmp(msg1,msg2,9) ans = 1

  17. 交互式计算 (续) >> findstr(‘in’,msg1) aus = 19 26 >> i=strmatch(‘max’,strvcat(‘max’,… 'minimax','maximum')) ans = 1 3 >> char([77, 65, 84, 76, 65, 66]) ans = MATLAB

  18. 交互式计算 (续) • 关于多项式 - 基本概念 数学表达式 求值计算 >> c=[c1,c2,c3,…,cn,cn+1]; >> polyval(c,x)

  19. 交互式计算 (续) 卷积计算 >> w=conv(u,v) % 返回多项式系数向量 重构操作 >> c=poly(v) % 返回多项式系数向量 微分操作 >> cdef=polyder(c) 拟合操作 >> c=polyfit(x,y,n)

  20. 交互式计算 (续) 使用实例 >> c = [3 2 1]; >> polyval(c,[5 7 9]) ans = 85 162 262 >> x = (0: 0.1: 2.5)'; y = erf(x); >> c = polyfit(x,y,6) c = 0.0084 -0.0983 0.4217 -0.7435 0.1471 1.1064 0.0004

  21. 交互式计算 (续) >> d=conv(c,[5 7 9]) ans = 15 31 46 25 9 >> dd=polyder(d) dd = 60 93 92 25 >> poly(roots(dd)) ans = 1.0000 1.5500 1.5333 0.4167

  22. 结束语 第七讲预告:Matlab编程 (2008年4月9日)

More Related