资源预览内容
第1页 / 共11页
第2页 / 共11页
第3页 / 共11页
第4页 / 共11页
第5页 / 共11页
第6页 / 共11页
第7页 / 共11页
第8页 / 共11页
第9页 / 共11页
第10页 / 共11页
亲,该文档总共11页,到这儿已超出免费预览范围,如果喜欢就下载吧!
资源描述
MMa at tl la ab b课课内内实实验验报报告告姓姓名名 :袁清晨袁清晨学学号号 :10093001311009300131学学院院 :理理 学学 院院班班级级 :数学数学 101101课课程程名名称称:MatlabMatlab 语言程序设计语言程序设计实实验验题题目目:MatlabMatlab 的矩阵生成和运算的矩阵生成和运算指指导导教教师师:王冠王冠2012 年 03 月 09 日- 1 -一、实验目的1. 熟悉 Matlab 的工作环境;2. 掌握 Matlab 中创建矩阵和向量的方法;3. 掌握 Matlab 中的逻辑运算和关系运算;4. 掌握 Matlab 中的矩阵的代数运算。二、实验内容和结果1.计算;保存 ;清除工作空间中的变量 ;将保存的44)6cos(4 . 0)25sin(2 sss读取到工作空间;清空命令窗口。s format short s=(2*sin(pi/5+2)-0.4)/(cos(6)+4)+4s =4.1173 2.将 format 设为 rat;输入 H=hilb(4);查找函数 hilb 的帮助文件 format rat H=hilb(4)H =1 1/2 1/3 1/4 1/2 1/3 1/4 1/5 1/3 1/4 1/5 1/6 1/4 1/5 1/6 1/7 help hilbHILB Hilbert matrix.HILB(N) is the N by N matrix with elements 1/(i+j-1),which is a famous example of a badly conditioned matrix.See INVHILB for the exact inverse.HILB(N,CLASSNAME) produces a matrix of class CLASSNAME.CLASSNAME must be either single or double (the default).- 2 -This is also a good example of efficient MATLAB programmingstyle where conventional FOR or DO loops are replaced byvectorized statements. This approach is faster, but usesmore storage.See also invhilb.Reference page in Help browserdoc hilb3.直接输入生成矩阵;取矩阵的第 1、3 行元素生成矩阵; 429653978AAB将矩阵按列合成一个列向量。B A=8 7 9;3 5 6; 9 2 4A =8 7 93 5 69 2 4 B=A(1 3,:)B =8 7 99 2 4 C=B(:)C =897294- 3 -4.以为首项,为步长,为末项生成向量;计算向量的正弦值,赋2 . 0xx 值到变量;以向量为对角线生成对角矩阵。yyA x=-pi:0.2*pi:pix =Columns 1 through 8 -3.1416 -2.5133 -1.8850 -1.2566 -0.6283 0 0.6283 1.2566Columns 9 through 11 1.8850 2.5133 3.1416 y=sin(x)y =Columns 1 through 8 -0.0000 -0.5878 -0.9511 -0.9511 -0.5878 0 0.5878 0.9511Columns 9 through 11 0.9511 0.5878 0.0000 A=diag(y)A =Columns 1 through 8 -0.0000 0 0 0 0 0 0 00 -0.5878 0 0 0 0 0 00 0 -0.9511 0 0 0 0 00 0 0 -0.9511 0 0 0 00 0 0 0 -0.5878 0 0 0- 4 -0 0 0 0 0 0 0 00 0 0 0 0 0 0.5878 00 0 0 0 0 0 0 0.95110 0 0 0 0 0 0 00 0 0 0 0 0 0 00 0 0 0 0 0 0 0Columns 9 through 11 0 0 00 0 00 0 00 0 00 0 00 0 00 0 00 0 00.9511 0 00 0.5878 00 0 0.0000 5.生成一个 5 阶希尔伯特矩阵;取矩阵的第 1、3、5 行,第 2 到 4 列元素HH 生成矩阵;左右翻转矩阵得矩阵;对矩阵逆时针旋转 90 度得矩阵MMFF ;取矩阵的主对角线向量 ;以向量 为第-3 对角线生成对角矩阵RRvv (矩阵得阶数是多少?) 。DD H=hilb(5)H =1.0000 0.5000 0.3333 0.2500 0.20000.5000 0.3333 0.2500 0.2000 0.16670.3333 0.2500 0.2000 0.1667 0.14290.2500 0.2000 0.1667 0.1429 0.12500.2000 0.1667 0.1429 0.1250 0.1111 M=H(1 3 5,2 3 4)M =- 5 -0.5000 0.3333 0.25000.2500 0.2000 0.16670.1667 0.1429 0.1250 F=fliplr ? F=fliplr| Error: Incomplete or misformed expression or statement. F=fliplr(M)F =0.2500 0.3333 0.50000.1667 0.2000 0.25000.1250 0.1429 0.1667 R=rot90(F)R =0.5000 0.2500 0.16670.3333 0.2000 0.14290.2500 0.1667 0.1250 v=diag(R)v =0.50000.20000.1250 S=diag(v,-3)S =0 0 0 0 0 00 0 0 0 0 00 0 0 0 0 00.5000 0 0 0 0 00 0.2000 0 0 0 00 0 0.1250 0 0 0- 6 - size(S)ans =6 6 6.生成随机逻辑矩阵和;对矩阵和作与、或、非以及异或运算,并将ABAB 结果分别赋给四个变量名;选择其中两个测试逻辑函数 any 和 all。 A=round(rand(6)A =1 0 1 0 0 00 0 1 1 0 11 1 0 0 0 00 0 0 0 1 11 1 1 1 0 01 1 1 0 0 0 B=round(rand(6)B =1 1 0 0 0 01 0 0 1 1 00 1 0 0 1 01 1 1 1 1 11 1 0 1 1 10 0 1 1 1 0 C=A&BC =1 0 0 0 0 00 0 0 1 0 00 1 0 0 0 00 0 0 0 1 11 1 0 1 0 00 0 1 0 0 0 D=A|BD =- 7 -1 1 1 0 0 01 0 1 1 1 11 1 0 0 1 01 1 1 1 1 11 1 1 1 1 11 1 1
收藏 下载该资源
网站客服QQ:2055934822
金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号