基础实验部分 实验一、 MATLAB基本操作 1、实验目的 (1)掌握在 MATLAB环境中矩阵的几种创建途径 (2)熟练掌握常见矩阵与数组的算术运算和关系运算 (3)学习并练习 MATLAB各种数学函数和矩阵函数 2、实验内容 (1)在 MATLAB中试用各种方法创建矩阵(至少3种) Problem 1: Create the matrix a by using the matrix constructor operator, 0 834 672 Problem 2: Create followed matrix by using specialized matrix functions v To create a 5-by-5 magic square matrix, 6 6 Problem 3: Concatenating matrices 6600 6600 600 600 6600 Problem 4: Use the colon operator -2.5000-1.5000-0.50000.50001.50002.5000
基础实验部分 实验一、MATLAB 基本操作 1、 实验目的 (1)掌握在 MATLAB 环境中矩阵的几种创建途径 (2)熟练掌握常见矩阵与数组的算术运算和关系运算 (3)学习并练习 MATLAB 各种数学函数和矩阵函数 2、实验内容 (1)在 MATLAB 中试用各种方法创建矩阵(至少 3 种) Problem 1:Create the matrix A by using the matrix constructor operator, []. A = 8 1 6 3 5 7 4 9 2 Problem 2: Create followed matrix by using specialized matrix functions To create a 5-by-5 magic square matrix, B = 6 6 6 6 6 6 6 6 6 6 Problem 3: Concatenating matrices C = 6 6 6 6 6 6 6 6 6 6 0 0 0 0 0 0 0 0 0 0 Problem 4: Use the colon operator D = -2.5000 -1.5000 -0.5000 0.5000 1.5000 2.5000
(2) Use subscripting and indexing to access and assign values to the elements of a matlaB matrIx A=matrix(5) Problem 1: Accessing the element at row 4, column 2 by specifying its row and column ar inae Problem 2: Compute the sum of all elements in the second column of magic square A (3)练习数组、矩阵的加、减、乘、除等各种运算(注意规则) 3、实验报告及要求 (1)简述实验目的。 (2)写出操作命令及计算结果 (3)总结矩阵建立、操作的常用方法。 实验二、M文件及 MATLAB程序设计与调试 l、实验目的 1.熟悉M命令文件和M函数文件的编写。 2.初步掌握 MATLAB语言编程和调试能力。 2、实验内容 (1)编写函数文件求半径为r的圆的面积s和周长1,其中半径r为输入参数,面积s和周 长1为输出参数 (2)利用函数文件,实现直角坐标(xy)与极坐标(p0)之间的转换,其中直角坐标为输入参 数,对应的极坐标为输出参数。 (3)设计一段程序,求1+2++n的和s,n为输入参数,和为输出参数ss (4)设计一段程序计算1~100的奇数和。 (5)一个三位整数各位数字的立方和等于该数本身则称该数为水仙花数。输出全部水仙花 (6)编制程序:取人以整数,若是偶数,则处以2,否则乘3加1,重复此过程,直到整 数变为1。 3、分析思考题
(2)Use subscripting and indexing to access and assign values to the elements of a MATLAB matrix A=matrix(5) Problem 1: Accessing the element at row 4, column 2 by specifying its row and column number and specifying the linear indexing. Problem 2: Compute the sum of all elements in the second column of magic square A. (3)练习数组、矩阵的加、减、乘、除等各种运算(注意规则) 3、实验报告及要求 (1)简述实验目的。 (2)写出操作命令及计算结果 (3)总结矩阵建立、操作的常用方法。 实验二、M 文件及 MATLAB 程序设计与调试 1、实验目的 1. 熟悉 M 命令文件和 M 函数文件的编写。 2. 初步掌握 MATLAB 语言编程和调试能力。 2、实验内容 (1)编写函数文件求半径为 r 的圆的面积 s 和周长 l,其中半径 r 为输入参数,面积 s 和周 长 l 为输出参数。 (2)利用函数文件,实现直角坐标(x,y)与极坐标(ρ,θ)之间的转换,其中直角坐标为输入参 数,对应的极坐标为输出参数。 (3)设计一段程序,求1+2+……+n 的和 s,n 为输入参数,和为输出参数 s。 (4)设计一段程序计算 1~100 的奇数和。 (5)一个三位整数各位数字的立方和等于该数本身则称该数为水仙花数。输出全部水仙花 数。 (6)编制程序:取人以整数,若是偶数,则处以2,否则乘3加1,重复此过程,直到整 数变为1。 3、分析思考题
(1) MATLAB的命令文件和函数文件的主要区别是什么? (2)For循环与 while循环的区别是什么? 4、实验报告及要求 (1)简述实验目的。 (2)写出每个问题的程序源代码,并附计算结果 (3)简要回答分析思考题 实验三、 MATLAB图形功能 1、实验目的 (1)学习和掌握 MATLAB图形功能。 (2)学习并掌握通过命令和 Plotting tools两种方式进行基本的图形操作方法。 2、实验内容 (1)基本知识 MATLAB provides a collection of plotting tools that form an interactive plotting environment This environment enables you to Create various type of graph o Select variables to plot directly from a workspace browser Easily create and manipulate subplots in the figure o Add annotations such as arrows. lines and text To create a figure with the plotting tools attached, use the plottools command. You can also start the plotting tools from the figure toolbar by clicking the Show Plot Tools (2)实验内容 Create a variable in the workspace >>X=-2 pipi/25: 2 pi Use the plottools command to create a figure with the plotting tools attached Click 2D Axes in the New Subplot panel of the Figure Paletto Once the axes appears, the Add data button on the plot browser is activated. Click this button to
(1)MATLAB 的命令文件和函数文件的主要区别是什么? (2)For 循环与 while 循环的区别是什么? 4、实验报告及要求 (1)简述实验目的。 (2)写出每个问题的程序源代码,并附计算结果。 (3)简要回答分析思考题。 实验三、MATLAB 图形功能 1、 实验目的 (1) 学习和掌握 MATLAB 图形功能。 (2) 学习并掌握通过命令和 Plotting Tools 两种方式进行基本的图形操作方法。 2、 实验内容 (1)基本知识 MATLAB provides a collection of plotting tools that form an interactive plotting environment. This environment enables you to Create various type of graphs Select variables to plot directly from a workspace browser Easily create and manipulate subplots in the figure Add annotations such as arrows, lines, and text Set properties on graphics objects To create a figure with the plotting tools attached, use the plottools command. You can also start the plotting tools from the figure toolbar by clicking the Show Plot Tools (2)实验内容 Create a variable in the workspace, >>x = -2*pi:pi/25:2*pi; Use the plottools command to create a figure with the plotting tools attached. >>plottools Click 2D Axes in the New Subplot panel of the Figure Palette. Once the axes appears, the Add Data button on the Plot Browser is activated. Click this button to
display the Add data to Axes dialog When the Add Data to Axes dialog is displayed, enter the following values Select plot as the Plot Type ● Set X data source to x. o Set Y Data Source to sin(x). 2 Click OK to plot this data. MATLAB draws a plot of sin(x). 2 VS.X. Now add another plot to the same axes. Click Add Data again and specify the data to plot Set X Data Source to x Set Y Data Source set to sin(x). 8. Click OK to plot this data Select the last plot(the green line)and set the Plot Type in the Property Editor to Stem t=0:2:20 alpha=.055 stem(t, exp(-alpha"t). * sin(5*t)) You then use the Property Editor to modify the graph to loo 实验四、数字信号源的设计 1、实验目的 (3)学习和掌握 MATLAB程序设计基本方法。 (4)学习并掌握数字信号处理中常用时域离散序列信号的设计。 (5)了解 MATLAB信号处理工具箱提供的常用信号使用方法。 2、实验内容及步骤 (1)通过编程实现以下信号序列 单位采样序列 参考代码 function y=srcdelta(n1, n2, n0) n=nl: n2 y=[(n-n0)==0 单位阶跃序列
display the Add Data to Axes dialog. When the Add Data to Axes dialog is displayed, enter the following values: Select plot as the Plot Type. Set X Data Source to x. Set Y Data Source to sin(x).^2. Click OK to plot this data. MATLAB draws a plot of sin(x).^2 vs. x. Now add another plot to the same axes. Click Add Data again and specify the data to plot: Set X Data Source to x. Set Y Data Source set to sin(x).^8. Click OK to plot this data. Select the last plot (the green line) and set the Plot Type in the Property Editor to Stem. t = 0:.2:20; alpha =.055; stem(t,exp(-alpha*t).*sin(5*t)) You then use the Property Editor to modify the graph to loo 实验四、数字信号源的设计 1、 实验目的 (3) 学习和掌握 MATLAB 程序设计基本方法。 (4) 学习并掌握数字信号处理中常用时域离散序列信号的设计。 (5) 了解 MATLAB 信号处理工具箱提供的常用信号使用方法。 2、 实验内容及步骤 (1)通过编程实现以下信号序列: 单位采样序列; 参考代码: function y=srcdelta(n1,n2,n0) n=n1:n2; y=[(n-n0)==0]; 单位阶跃序列;
参考代码: function y=src jy(nl, n2, nO) n=nl: n2 y=[(n-n0)>=0 矩形序列 参考代码 function y=srcjy(nl, n2, n3, n4) n=nl: n2 y=[(n-n3)>=0&(n-n4)<=0] 实指数序列 参考代码 function y=srcexp(a, n) y-a (2)通过 MATLAB帮助系统学习以下函数的用法 ·方波— square 语法格式 x=square(t) x=square(, duty) 参考代码 00.1*p6*p y=square(t) axis(07*pi-1.51.5]) plot(t, y); 正弦波 -sin 锯齿波— sawtooth 语法格式: X= sawtooth(t) X= sawtooth(t, width) 参考代码 t=0:0001:1.5;%抽取长度1.5s,抽样频率1000Hz
参考代码: function y=srcjy(n1,n2,n0) n=n1:n2; y=[(n-n0)>=0]; 矩形序列; 参考代码 function y=srcjy(n1,n2,n3,n4) n=n1:n2; y=[(n-n3)>=0 &(n-n4)<=0]; 实指数序列; 参考代码: function y=srcexp(a, n) y=a.^n (2)通过 MATLAB 帮助系统学习以下函数的用法: 方波——square 语法格式: x = square(t) x = square(t,duty) 参考代码: t=0:0.1*pi:6*pi; y=square(t); axis([0 7*pi -1.5 1.5]) plot(t,y); 正弦波——sin 锯齿波——sawtooth 语法格式: x = sawtooth(t) x = sawtooth(t,width) 参考代码: t=0:0.001:1.5; % 抽取长度 1.5s,抽样频率 1000Hz