MATLAB实验报告

合集下载

matlab矩阵实验报告

matlab矩阵实验报告

matlab矩阵实验报告《MATLAB矩阵实验报告》摘要:本实验报告利用MATLAB软件进行了矩阵实验,通过对矩阵的运算、转置、逆矩阵、特征值等操作进行了分析和讨论。

实验结果表明,MATLAB在矩阵运算方面具有高效、准确的特点,能够满足工程和科学计算的需求。

引言:矩阵是线性代数中的重要概念,广泛应用于工程、物理、经济等领域。

MATLAB是一种强大的数学软件,能够对矩阵进行各种运算和分析。

本实验旨在利用MATLAB软件对矩阵进行实验,探讨其在矩阵运算中的应用和优势。

实验方法:1. 创建矩阵:利用MATLAB软件创建不同大小的矩阵,包括方阵和非方阵。

2. 矩阵运算:进行矩阵的加法、减法、乘法等运算,比较不同大小矩阵的计算效率和结果准确性。

3. 矩阵转置:对矩阵进行转置操作,观察转置后矩阵的性质和应用。

4. 逆矩阵:求解矩阵的逆矩阵,并分析逆矩阵在实际问题中的应用。

5. 特征值和特征向量:利用MATLAB软件求解矩阵的特征值和特征向量,分析其在物理、工程等领域的应用。

实验结果与讨论:通过实验发现,MATLAB软件在矩阵运算中具有高效、准确的特点。

对于大规模矩阵的运算,MATLAB能够快速进行计算并给出准确的结果。

在矩阵转置和逆矩阵求解方面,MATLAB也能够满足工程和科学计算的需求。

此外,通过求解矩阵的特征值和特征向量,可以得到矩阵的重要性质,为实际问题的分析和求解提供了有力支持。

结论:本实验利用MATLAB软件进行了矩阵实验,通过对矩阵的运算、转置、逆矩阵、特征值等操作进行了分析和讨论。

实验结果表明,MATLAB在矩阵运算方面具有高效、准确的特点,能够满足工程和科学计算的需求。

希望本实验能够对矩阵运算和MATLAB软件的应用有所启发,为相关领域的研究和应用提供参考。

MATLAB实验报告

MATLAB实验报告

MATLAB实验报告一、实验目的本次 MATLAB 实验旨在深入了解和掌握 MATLAB 软件的基本操作和应用,通过实际编程和数据处理,提高解决问题的能力,培养编程思维和逻辑分析能力。

二、实验环境本次实验使用的是 MATLAB R2020a 版本,运行在 Windows 10 操作系统上。

计算机配置为英特尔酷睿 i5 处理器,8GB 内存。

三、实验内容(一)矩阵运算1、矩阵的创建使用直接输入、函数生成和从外部文件导入等方式创建矩阵。

例如,通过`1 2 3; 4 5 6; 7 8 9` 直接输入创建一个 3 行 3 列的矩阵;使用`ones(3,3)`函数创建一个 3 行 3 列元素全为 1 的矩阵。

2、矩阵的基本运算包括矩阵的加减乘除、求逆、转置等。

例如,对于两个相同维度的矩阵`A` 和`B` ,可以进行加法运算`C = A + B` 。

3、矩阵的特征值和特征向量计算通过`eig` 函数计算矩阵的特征值和特征向量,加深对线性代数知识的理解和应用。

(二)函数编写1、自定义函数使用`function` 关键字定义自己的函数,例如编写一个计算两个数之和的函数`function s = add(a,b) s = a + b; end` 。

2、函数的调用在主程序中调用自定义函数,并传递参数进行计算。

3、函数的参数传递了解值传递和引用传递的区别,以及如何根据实际需求选择合适的参数传递方式。

(三)绘图功能1、二维图形绘制使用`plot` 函数绘制简单的折线图、曲线等,如`x = 0:01:2pi; y = sin(x); plot(x,y)`绘制正弦曲线。

2、图形的修饰通过设置坐标轴范围、标题、标签、线条颜色和样式等属性,使图形更加清晰和美观。

3、三维图形绘制尝试使用`mesh` 、`surf` 等函数绘制三维图形,如绘制一个球面`x,y,z = sphere(50); surf(x,y,z)`。

(四)数据处理与分析1、数据的读取和写入使用`load` 和`save` 函数从外部文件读取数据和将数据保存到文件中。

程序设计实验报告(matlab)

程序设计实验报告(matlab)

程序设计实验报告(matlab)实验一: 程序设计基础实验目的:初步掌握机器人编程语言Matlab。

实验内容:运用Matlab进行简单的程序设计。

实验方法:基于Matlab环境下的简单程序设计。

实验结果:成功掌握简单的程序设计和Matlab基本编程语法。

实验二:多项式拟合与插值实验目的:学习多项式拟合和插值的方法,并能进行相关计算。

实验内容:在Matlab环境下进行多项式拟合和插值的计算。

实验方法:结合Matlab的插值工具箱,进行相关的计算。

实验结果:深入理解多项式拟合和插值的实现原理,成功掌握Matlab的插值工具箱。

实验三:最小二乘法实验目的:了解最小二乘法的基本原理和算法,并能够通过Matlab进行计算。

实验内容:利用Matlab进行最小二乘法计算。

实验方法:基于Matlab的线性代数计算库,进行最小二乘法的计算。

实验结果:成功掌握最小二乘法的计算方法,并了解其在实际应用中的作用。

实验六:常微分方程实验目的:了解ODE的基本概念和解法,并通过Matlab进行计算。

实验内容:利用Matlab求解ODE的一阶微分方程组、变系数ODE、高阶ODE等问题。

实验方法:基于Matlab的ODE工具箱,进行ODE求解。

实验结果:深入理解ODE的基本概念和解法,掌握多种ODE求解方法,熟练掌握Matlab的ODE求解工具箱的使用方法。

总结在Matlab环境下进行程序设计实验,使我对Matlab有了更深刻的认识和了解,也使我对计算机科学在实践中的应用有了更加深入的了解。

通过这些实验的学习,我能够灵活应用Matlab进行各种计算和数值分析,同时也能够深入理解相关的数学原理和算法。

这些知识和技能对我未来的学习和工作都将有着重要的帮助。

matlab实验心得总结

matlab实验心得总结

matlab实验心得总结在通过完成一系列的Matlab实验后,我对这个强大的数学计算软件有了更深入的认识。

通过这些实验,我不仅学到了如何使用Matlab进行数据处理和分析,还体会到了它在科学研究和工程应用中的广泛使用。

实验一:Matlab基础操作在第一次接触Matlab时,我首先学习了它的基本操作。

Matlab提供了友好的用户界面和丰富的命令工具,使得数据处理变得简单且高效。

在实验中,我学会了如何定义变量、进行基本的数学运算和使用矩阵操作等。

这些基础操作为后续的实验打下了坚实的基础。

实验二:数据可视化数据可视化在科学研究和工程领域中起着重要的作用。

在这个实验中,我学会了如何利用Matlab绘制各种图形,如折线图、散点图和柱状图等。

通过调整图形的样式和颜色,使得数据更加直观和易于理解。

同时,我还学会了如何添加标题、坐标轴标签和图例,使得图形具有更好的可读性。

实验三:模拟与仿真Matlab不仅可以进行数据处理和图形绘制,还可以进行模拟和仿真。

在这个实验中,我学会了如何使用Matlab进行数学模型的建立和仿真。

通过设定合适的参数和方程,我可以模拟出各种现实世界中的物理、生物和工程现象。

这对于科学研究和工程设计具有重要的意义。

实验四:信号处理信号处理是Matlab的一个重要应用领域。

在这个实验中,我学会了如何使用Matlab对信号进行分析和处理。

通过应用不同的滤波器,我可以去除信号中的噪声和干扰,提取出感兴趣的信息。

同时,我还学会了如何进行频域分析,通过傅里叶变换将信号转换到频率域,进一步分析信号的频谱特性。

实验五:数值计算Matlab还提供了强大的数值计算功能。

在这个实验中,我学会了如何使用Matlab进行数值计算和优化。

通过使用不同的数值求解方法,我可以解决复杂的数学方程和优化问题,得到精确的计算结果。

这对于科学研究和工程计算具有重要的价值。

总结起来,通过这些实验,我对Matlab的应用能力有了明显的提升。

Matlab实验报告六(三次样条与分段线性插值)

Matlab实验报告六(三次样条与分段线性插值)
数学与信息科学系实验报告
实验名称插值与拟合
所属课程数学软件与实验
实验类型综合型实验
专业信息与计算科学
班级
学号
姓名
指导教师
一、实验概述
【实验目的】
学会在matlab环境下使用几种不同的插值法和拟合两种方法构造函数依据已经知道的某些特殊点来推测实际问题中需要知道但又不便于测量出来的量。
【实验原理】
1.z=interp2(x0,y0,z0,x,y,’method’): 要求x0,y0单调;x, y可取为矩阵, 或x取行向量, y取为列向量, x,y的值分别不能超出x0,y0的范围。
2.分段线性插值与计算量与n无关;n越大, 误差越小.
3.三次样条插值比分段线性插值更光滑。
4.‘linear’ : 分段线性插值;‘spline’ : 三次样条
二、实验内容
问题1 对函数, x([-5,5], 分别用分段线性插值和三次样条插值作插值(其中插值节点不少于20), 并分别作出每种插值方法的误差曲线.
1180 1320 1450 1420 1400 1300 700 900];
mesh(x,y,z)
xi=0:20:2800;
yi=0:20:2400;
zi=interp2(x,y,z,xi',yi,'cubic');
mesh(xi,yi,zi)
3.结果
4.结论及分析
通过实验,结果正确,分析无误。
三、实验小结
1270 1500 1200 1100 1350 1450 1200 1150
1230 1390 1500 1500 1400 900 1100 1060
1180 1320 1450 1420 1400 1300 700 900

初识MATLAB的实验报告

初识MATLAB的实验报告

初识MATLAB的实验报告1. 引言MATLAB(Matrix Laboratory)是一种高级的技术计算环境和编程语言。

它具有强大的矩阵计算能力和丰富的科学和工程绘图功能,被广泛应用于各个领域的科研与工程实践中。

本实验旨在初步了解MATLAB的基本语法和功能,通过实际操作加深对MATLAB编程的理解。

2. 实验目的1. 掌握MATLAB的安装和基本使用方法;2. 学习MATLAB中的常用数学函数和操作;3. 了解MATLAB绘图功能并能够绘制简单的图形。

3. 实验步骤3.1 MATLAB安装首先,在官方网站(3.2 MATLAB入门3.2.1 MATLAB语法MATLAB的语法类似于其他常见的编程语言,每个语句以分号结尾。

在MATLAB 中,可以直接进行基本的数学运算,例如加减乘除、指数、对数等。

通过以下代码可以计算两个变量的和并将结果打印出来:matlaba = 10;b = 20;sum = a + b;disp(sum);3.2.2 MATLAB变量在MATLAB中,可以创建和操作各种类型的变量,例如数值、字符串、矩阵等。

以下代码演示了如何创建一个矩阵:matlabmatrix = [1, 2, 3; 4, 5, 6; 7, 8, 9];disp(matrix);3.2.3 MATLAB函数MATLAB提供了许多内置的数学函数,可以直接调用。

以下代码演示了如何计算正弦函数值并打印结果:matlabx = pi/4;y = sin(x);disp(y);3.3 MATLAB绘图MATLAB具有强大的绘图功能,可以绘制各种图形,如曲线、散点图、柱状图等。

以下代码演示了如何绘制一个简单的正弦曲线:matlabx = linspace(0, 2*pi, 100);y = sin(x);plot(x, y);xlabel('x');ylabel('y');title('Sine Curve');4. 实验结果与分析在完成上述实验步骤后,我们成功安装了MATLAB,并学习了基本的语法、变量和函数的使用方法。

MATLAB实验报告(8个实验)

MATLAB实验报告(8个实验)

四川师范大学MATLAB语言实验报告1系级班年月日实验名称:Intro, Expressions, Commands姓名学号指导教师成绩1ObjectiveThe objective of this lab is to familiarize you with the MATLAB program development environment and to develop your first programs in this environment.2Using MATLAB2.1Starting MATLABLogon to your computer and start MATLAB by double-clicking on the icon on the desktop or by using the Start Programs menu. MATLAB Desktop window will appear on the screen.The desktop consists of several sub-windows. The most important ones are:●Command Window (on the right side of the Desktop) is used to do calculations,enter variables and run built-in and your own functions.●Workspace (on the upper left side) consists of the set of variables (arrays) createdduring the current MATLAB session and stored in memory.●Command History (on the lower left side) logs commands entered in theCommand Window. You can use this window to view previously run statements, and copy and execute selected statements.You can switch between the Launch Pad window and the Workspace window using the menu tabs under the sub-window on the upper left side. Similarly, you can switch between the Command History and Current Directory windows using the menu tabs under the sub-window on the lower left side.2.2Executing CommandsYou can type MATLAB commands at the command prompt “>>” on the Command Window.For example, you can type the formula cos(π/6)2sin(3π/8) as>>(cos(pi/6) ^ 2) * (sin(3 * pi/8))Try this command. After you finish typing, press enter. The command will be interpreted and the result will be displayed on the Command Window.Try the following by observing how the Workspace window changes:>> a = 2; (M ake note of the usage of “;”)>> b = 3;>> c = a ^ 4 ∗ b ∗ 5 + pi ^3You can see the variables a, b and c with their types and sizes on the Workspacewindow, and can see the commands on the Command History window.Spend a few minutes to practice defining array variables (i.e. vectors and matrices)usingthe square bracket (“[ ]”) and colon (“:”) operators, and zeros() and ones() functions.>> ar =[ 1 2 3 4 5 ];>> br =[ 1 2 3 ;4 5 6 ];>> cr = [1 : 3 : 15];• Set dr to first 3 elements of ar.dr=ar(1:3);• Set er to second row of br.er=br(2,:);• Set ar to [dr er]. Find the number of elements of ar.ar=[dr er]; length(ar)2.3 Getting HelpThere are several ways to get help on commands and functions in MATLAB. First ofall you can use the Help menu. You can also use the “?” button. Try to findinformation on the plot function from the help index. Also try to get information onthe same function using the help command (i.e. type help plot). Finally, experimentwith the lookfor command. This command looks for other commands related to agiven keyword.2.4 Some Useful CommandsTry the following commands and observe their results:Which : Version and location infoClear : Clears the workspaceClc : Clears the command windowwho, whos : Lists content of the workspace3 ExercisesPlease solve the following problems in MATLAB. Do not forget to keep a diary ofyour commands and their outputs.(1) Define the variables x y and z as 7.6, 5.5 and 8.1, respective ly, and evaluate:578.422.52⎪⎭⎫ ⎝⎛-x y xz(2) Compute the slope of the line that passes through the points (1,-2) and(5,8).(3) Quiz 1.1: 5(4)1.6 Exercises: 1.1, 1.4(5)2.15 Exercises: 2.6, 2.9, 2.114Quitting MATLABTyping quit on the command window will close the program. Do not forget to send your diary file and M-file to your TA.Do not forget to delete your files from the hard disk of the PC you used in the lab at the end of the lab session.四川师范大学MATLAB语言实验报告2系级班年月日实验名称:Programming, Relational and Logical Expressions姓名学号指导教师成绩1ObjectiveThe objective of this lab is to familiarize you with the MATLAB script files (M-files), subarrays, relational and logical operators.2Script FilesScript files are collections of MATLAB statements that are stored in a file. Instead of typing commands directly in the Command Window, a series of commands may be placed into a file and the entire file may be executed by typing its name in the Command Window. Such files are called script files that are also known as M-files because they have an extension of .m. When a script file is executed, the result is the same as it would be if all of the commands had been typed directly into the Command Window. All commands and script files executed in the Command Window share a common workspace, so they can all share variables in the workspace. Note that if two script files are executed successively, the second script file can use the variables created by the first script file. In this way, script files can communicate with other script files through the data left behind in the workspace. An Edit Window is used to create new M-files or to modify existing ones. The Edit Window is a programming text editor, with the features of MATLAB language highlighted in different colors. You can create a new M-file with the File/New/M-file selection and you can open an existing M-file with the File/Open selection from the desktop menu of MATLAB. (1)Create a new working directory under the current directory and change the currentdirectory to ‘TA’s suggest’.3SubarraysIt is possible to select and use subsets of MATLAB arrays. To select a subset of an array, just include a list of the elements to be selected in the parentheses after the array name. MATLAB has a special function named end that is used to create arraysubscripts. The end function always returns the highest value taken on by a givensubscript. It is also possible to use subarrays on the left-hand side of an assignmentstatement to change only some of the values in an array. If values are assigned to asubarray, only those values are changed but if values are assigned to an array, theentire contents of the array are replaced by the new values.(1) Define the following 5 x 5 array arr1 in MATLAB.⎥⎥⎥⎥⎥⎥⎦⎤⎢⎢⎢⎢⎢⎢⎣⎡----=2274235421209518171651413215111012844563311arr(2) Write a MATLAB statement to select a subset of arr1 and return the subarraycontaining the values as shown.⎥⎦⎤⎢⎣⎡=22745456311arrarr11=arr1([1,5],[2 4 5]);(3) Write two MATLAB statements to select the last row and last column of arr1,separately.arr12=arr1(5,:);或arr12=arr1(end,:); arr13=arr1(:,end);或 arr13=arr1(:,5);(4) Write MATLAB statements to obtain the following array from arr1.⎥⎥⎥⎥⎥⎥⎦⎤⎢⎢⎢⎢⎢⎢⎣⎡-=2257462335432112arrarr2=arr1([1 5],:)';4 Relational and Logical OperatorsRelational and logical operators are the two types of operators that produce true/falseresults in MATLAB programs. MATLAB interprets a zero value as false and anynonzero value as true. Relational operators ( ==, =,>,>=,<,<=) are operators with twooperands that produce either a true (1) or a false (0) result, depending on the values ofthe operands. Relational operators can be used to compare a scalar value with an array.They can also be used to compare two arrays or two strings only if they have the samesize. Be careful not to confuse the equivalence relational operator ( == ) with theassignment operator ( = ). Logic operators ( &, |, xor, ~ ) are operators with one ortwo operands that yield a logical result such as 0 or 1. There are three binary logicoperators: AND (& ), OR ( |), and exclusive OR ( xor ); and one unary operator: NOT( ~ ). In the hierarchy of operations, logic operators are evaluated after allarithmetic and relational operators have been evaluated. The operator is evaluatedbefore other logic operators.(1) Define the following 4 x 5 array arr4 in MATLAB.⎥⎥⎥⎥⎦⎤⎢⎢⎢⎢⎣⎡------=212343212343212543214arr(2) Write an expression using arr4 and a relational operator to produce the followingresult.⎥⎥⎥⎥⎦⎤⎢⎢⎢⎢⎣⎡=110001110011110111115arrarr5=arr4>0;(3) Write an expression using arr4 and a relational operator to produce the followingresult.⎥⎥⎥⎥⎦⎤⎢⎢⎢⎢⎣⎡=010000010000010000016arrarr6=arr4==1;(4) Write a MATLAB program which will generate an (n-1)x(n-1) matrix from agiven nxn matrix which will be equal to given matrix with first row and firstcolumn deleted.arr44=rand(5); arr444=arr35(2:end,2:end);(5) Generalize your program above so that the program should ask the row andcolumn numbers to be deleted and then generate new (n-1)x(n-1) matrix.n=input('input n:');matrixn=rand(n)delrow=input('input row numbers to be deleted:');delcolumn=input('input column numbers to be deleted:');matrixn_1=matrixn([1:delrow-1 delrow+1:end], [1:delcolumn-1 delcolumn+1:end])(6) Quiz 3.1 (P88)5 Quitting MATLABTyping quit on the command window will close the program. Do not forget to sendyour diary file and M-file to your TA.Do not forget to delete your files from the hard disk of the PC you used in the lab atthe end of the lab session.四川师范大学MATLAB 语言实验报告3系 级 班 年 月 日实验名称:Branches and Loops, Logical Arrays.姓名 学号 指导教师 成绩 1 ObjectiveThe objective of this lab is to familiarize you with the MATLAB Branches and Loops,Logical Arrays.2 ExercisesDo not forget to add sufficient documentation and proper indentation to all programsyou write.(1) Write a program that calculates follow equation with for and while loop, and writea program without loop.63263022212+++==∑=Λi i K% for loopk1=0;for ii=1:64k1=k1+2^(ii-1);end% while loopk2=0;n=0;while n>=0&n<64k2=k2+2^n;n=n+1;end% without loopa=0:63;b=2.^a;K3=sum(b);(2) Write a program that accepts a vector of integers as input and counts the numberof integers that are multiples of 3 in that vector. You can assume that the inputcontains only integer values. An example run of your program can be as follows:Enter a vector of integers: [ 1 3 2 8 0 5 6 ]The number of multiples of 3 is 2(3) The root mean square is a way for calculating a mean for a set of numbers. The rmsaverage of a series of numbers is given as:∑==N i i x N rmsaverage 121Write a program that will accept an arbitrary number of input values and calculatethe rmsaverage of the numbers. The program should ask the user for the numberof values to be entered. Test your program with 4 and 10 set of numbers.% The root mean square is a way for calculating a mean for a set of numbers% Initializesum_x2=0;% Get the number of points to input.n=input('Enter number of points:');% Loop to read input valuesfor ii=1:n% Read in next valuex=input('Enter value:');% Calculate square sumssum_x2=sum_x2+x^2;end% Now calculate root mean squareroot_ms=sqrt(sum_x2/n);% Tell userfprintf('The number of data points is: %d\n',n);fprintf('The root mean square of this data set is: %f\n',root_ms);(4) 3.8 exercises:3.5(5) 4.7Exercises: 4.1 4.23 Quitting MATLABTyping quit on the command window will close the program. Do not forget to sendyour M-file to your TA.Do not forget to delete your files from the hard disk of the PC you used in the lab at the end of the lab session.四川师范大学MATLAB语言实验报告4系级班年月日实验名称:MATLAB/SIMULINK package姓名学号指导教师成绩1Objective●To learn how to use MATLAB/SIMULINK package●To learn how to estimate performance parameters from time-domain data2SIMULINK BasicBasic steps(1)Click on the MATLAB button to start MATLAB.(2)Once MATLAB has started up, type simulink (SMALL LETTERS!) at theMATLAB prompt (>>) followed by a carriage return (press the return key). A SIMULINK window should appear shortly, with the following icons: Sources, Sinks, Discrete, Linear, Connections, Extras.(3)Next, go to the File menu in SIMULINK window and choose New in order tobegin building the block diagram representation of the system of interest.(4)Open one or more of the block libraries and drag the chosen blocks into the active.(5)After the blocks are placed, draw lines to connect their input and output ports bymoving the mouse over a port and drag using the left button. To make a line witha right angle in it, release the button where you want the corner, then click on theend of the line and drag to create next segment. To add a second line that runs off of an existing line click the right mouse on an existing line and drag it.(6)Save the system by selecting Save from the File menu.(7)Open the blocks by double-clicking and change some of their internal parameters.(8)Adjust some simulation parameters by selecting Parameters from the Simulationmenu. The most common parameter to change is Stop Time that defines the length of time the simulation will run.(9)Run the simulation by selecting Start from the Simulation menu. You can stop asimulation before completing by selecting Stop from the Simulation menu. (10)View the behavior of the system by attaching Scope blocks to the variables ofinterest, or by using To Workspace blocks to send data to the MATLAB workspace where you can plot the results using standard MATLAB commands.3Exercises(1)Your TA has shown you how to observe and print signals from the scope. Try thisout by printing out the input signal, which should be a -1V to 1V square wave with frequency 0.1 Hz. Note the peak-to-peak voltage difference of this signal.Note to write key blocks parameters.(2) Write a Simulink model to calculate the following differential equation,0)1(222=+--x dt dx x dt x d μInitialized 1)0(=x ,0)0(=dt dx 。

matlab实验报告1

matlab实验报告1

matlab实验报告1MATLAB实验报告1摘要:本实验使用MATLAB软件进行了一系列的实验,主要包括数据处理、图像处理和信号处理。

通过实验,我们掌握了MATLAB软件在科学计算和工程领域的应用,深入了解了MATLAB在数据处理、图像处理和信号处理方面的强大功能。

一、数据处理实验在数据处理实验中,我们使用MATLAB对一组实验数据进行了分析和处理。

首先,我们导入了实验数据并进行了数据清洗和预处理,然后利用MATLAB的统计分析工具对数据进行了描述性统计分析,包括均值、方差、标准差等指标的计算。

接着,我们利用MATLAB的绘图工具绘制了数据的直方图和散点图,直观地展现了数据的分布规律和相关性。

二、图像处理实验在图像处理实验中,我们使用MATLAB对一幅图像进行了处理和分析。

首先,我们读取了图像并进行了灰度化处理,然后利用MATLAB的图像滤波工具对图像进行了平滑和锐化处理,最后利用MATLAB的图像分割工具对图像进行了分割和特征提取。

通过实验,我们深入了解了MATLAB在图像处理领域的应用,掌握了图像处理的基本原理和方法。

三、信号处理实验在信号处理实验中,我们使用MATLAB对一组信号进行了处理和分析。

首先,我们生成了一组模拟信号并进行了频域分析,利用MATLAB的信号滤波工具对信号进行了滤波处理,然后利用MATLAB的频谱分析工具对信号的频谱特性进行了分析。

通过实验,我们深入了解了MATLAB在信号处理领域的应用,掌握了信号处理的基本原理和方法。

综上所述,本实验通过对MATLAB软件的应用实验,使我们对MATLAB在数据处理、图像处理和信号处理方面的功能有了更深入的了解,为我们今后在科学计算和工程领域的应用奠定了良好的基础。

MATLAB软件的强大功能和广泛应用前景,将为我们的学习和科研工作提供有力的支持和帮助。

MATLAB实验报告(8个实验)

MATLAB实验报告(8个实验)

MATLAB实验报告(8个实验)四川师范大学MATLAB语言实验报告1系级班年月日实验名称:Intro, Expressions, Commands姓名学号指导教师成绩1ObjectiveThe objective of this lab is to familiarize you with the MATLAB program development environment and to develop your first programs in this environment.2Using MATLAB2.1Starting MATLABLogon to your computer and start MATLAB by double-clicking on the icon on the desktop or by using the Start Programs menu. MATLAB Desktop window will appear on the screen.The desktop consists of several sub-windows. The most important ones are:●Command Window (on the right side of the Desktop) is used to do calculations,enter variables and run built-in and your own functions.●Workspace (on the upper left side) consists of the set of variables (arrays) createdduring the current MATLAB session and stored in memory.●Command History (on the lower left side) logs commands entered in theCommand Window. You can use this window to view previously run statements, and copy and execute selected statements.You can switch between the Launch Pad window and the Workspace window using the menu tabs under the sub-windowon the upper left side. Similarly, you can switch between the Command History and Current Directory windows using the menu tabs under the sub-window on the lower left side.2.2Executing CommandsYou can type MATLAB commands at the command prompt “>>” on the Command Window.For example, you can type the formula cos(π/6)2sin(3π/8) as >>(cos(pi/6) ^ 2) * (sin(3 * pi/8))Try this command. After you finish typing, press enter. The command will be interpreted and the result will be displayed on the Command Window.Try the following by observing how the Workspace window changes:>> a = 2; (M ake note of the us age of “;”)>> b = 3;>> c = a ^ 4 ? b ? 5 + pi ^3You can see the variables a, b and c with their types and sizes on the Workspacewindow, and can see the commands on the Command History window.Spend a few minutes to practice defining array variables (i.e. vectors and matrices)usingthe square bracket (“[ ]”) and colon (“:”) operators, and zeros() and ones() functions.>> ar =[ 1 2 3 4 5 ];>> br =[ 1 2 3 ;4 5 6 ];>> cr = [1 : 3 : 15];Set dr to ?rst 3 elements of ar.dr=ar(1:3);Set er to second row of br.er=br(2,:);Set ar to [dr er]. Find the number of elements of ar.ar=[dr er]; length(ar)2.3 Getting HelpThere are several ways to get help on commands and functions in MATLAB. First ofall you can use the Help menu. You can also use the “?” button. Try to findinformation on the plot function from the help index. Also try to get information onthe same function using the help command (i.e. type help plot). Finally, experimentwith the lookfor command. This command looks for other commands related to agiven keyword.2.4 Some Useful CommandsTry the following commands and observe their results:Which : Version and location infoClear : Clears the workspaceClc : Clears the command windowwho, whos : Lists content of the workspace3 ExercisesPlease solve the following problems in MATLAB. Do not forget to keep a diary ofyour commands and their outputs.(1) De?ne the variables x y and z as 7.6, 5.5 and 8.1, respective ly, and evaluate:578.422.52??? ??-x y xz(2) Compute the slope of the line that passes through thepoints (1,-2) and(5,8).(3) Quiz 1.1: 5(4)1.6 Exercises: 1.1, 1.4(5)2.15 Exercises: 2.6, 2.9, 2.114Quitting MATLABTyping quit on the command window will close the program. Do not forget to send your diary file and M-file to your TA.Do not forget to delete your ?les from the hard disk of the PC you used in the lab at the end of the lab session.四川师范大学MATLAB语言实验报告2系级班年月日实验名称:Programming, Relational and Logical Expressions 姓名学号指导教师成绩1ObjectiveThe objective of this lab is to familiarize you with the MATLAB script files (M-files), subarrays, relational and logical operators.2Script FilesScript files are collections of MATLAB statements that are stored in a file. Instead of typing commands directly in the Command Window, a series of commands may be placed into a file and the entire file may be executed by typing its name in the Command Window. Such files are called script files that are also known as M-files because they have an extension of .m. When a script file is executed, the result is the same as it would be if all of the commands had been typed directly into the Command Window. All commands and script files executed in the Command Window share a common workspace, so they can all share variables in the workspace. Note that if two script files are executed successively, the second script file can use the variables created by the first script file. In this way, script files can communicate with other script files through the data left behindin the workspace. An Edit Window is used to create new M-files or to modify existing ones. The Edit Window is a programming text editor, with the features of MATLAB language highlighted in different colors. You can create a new M-file with the File/New/M-file selection and you can open an existing M-file with the File/Open selection from the desktop menu of MATLAB.(1)Create a new working directory under the current directory and change the currentdirectory to …TA?s suggest?.3SubarraysIt is possible to select and use subsets of MATLAB arrays. To select a subset of an array, just include a list of the elements to be selected in the parentheses after the array name. MATLAB has a special function named end that is used to create arraysubscripts. The end function always returns the highest value taken on by a givensubscript. It is also possible to use subarrays on the left-hand side of an assignmentstatement to change only some of the values in an array. If values are assigned to asubarray, only those values are changed but if values are assigned to an array, theentire contents of the array are replaced by the new values.(1) Define the following 5 x 5 array arr1 in MATLAB.----=2274235421209518171651413215111012844563311arr(2) Write a MATLAB statement to select a subset of arr1 and return the subarraycontaining the values as shown.=22745456311arrarr11=arr1([1,5],[2 4 5]);(3) Write two MATLAB statements to select the last row and last column of arr1,separately.arr12=arr1(5,:);或arr12=arr1(end,:); arr13=arr1(:,end);或arr13=arr1(:,5);(4) Write MATLAB statements to obtain the following array from arr1.-=2257462335432112arrarr2=arr1([1 5],:)';4 Relational and Logical OperatorsRelational and logical operators are the two types of operators that produce true/falseresults in MATLAB programs. MATLAB interprets a zero value as false and anynonzero value as true. Relational operators ( ==, =,>,>=,<,<=) are operators with twooperands that produce either a true (1) or a false (0) result, depending on the values ofthe operands. Relational operators can be used to compare a scalar value with an array.They can also be used to compare two arrays or two strings only if they have the samesize. Be careful not to confuse the equivalence relational operator ( == ) with theassignment operator ( = ). Logic operators ( &, |, xor, ~ ) are operators with one ortwo operands that yield a logical result such as 0 or 1. There are three binary logicoperators: AND (& ), OR ( |), and exclusive OR ( xor ); and oneunary operator: NOT( ~). In the hierarchy of operations, logic operators are evaluated after allarithmetic and relational operators have been evaluated. The operator is evaluatedbefore other logic operators.(1) Define the following 4 x 5 array arr4 in MATLAB.------=212343212343212543214arr(2) Write an expression using arr4 and a relational operator to produce the followingresult.=110001110011110111115arrarr5=arr4>0;(3) Write an expression using arr4 and a relational operator to produce the followingresult.=010000010000010000016arrarr6=arr4==1;(4) Write a MATLAB program which will generate an (n-1)x(n-1) matrix from agiven nxn matrix which will be equal to given matrix with first row and firstcolumn deleted.arr44=rand(5); arr444=arr35(2:end,2:end);(5) Generalize your program above so that the program should ask the row andcolumn numbers to be deleted and then generate new (n-1)x(n-1) matrix.n=input('input n:');matrixn=rand(n)delrow=input('input row numbers to be deleted:');delcolumn=input('input column numbers to be deleted:');matrixn_1=matrixn([1:delrow-1 delrow+1:end], [1:delcolumn-1 delcolumn+1:end])(6) Quiz 3.1 (P88)5 Quitting MATLABTyping quit on the command window will close the program. Do not forget to sendyour diary file and M-file to your TA.Do not forget to delete your files from the hard disk of the PC you used in the lab atthe end of the lab session.四川师范大学MATLAB 语言实验报告3系级班年月日实验名称:Branches and Loops, Logical Arrays.姓名学号指导教师成绩 1 ObjectiveThe objective of this lab is to familiarize you with the MATLAB Branches and Loops,Logical Arrays.2 ExercisesDo not forget to add sufficient documentation and proper indentation to all programsyou write.(1) Write a program that calculates follow equation with for and while loop, and writea program without loop.63263022212+++==∑= i i K% for loopk1=0;for ii=1:64k1=k1+2^(ii-1);end% while loopk2=0;n=0;while n>=0&n<64k2=k2+2^n;n=n+1;end% without loopa=0:63;b=2.^a;K3=sum(b);(2) Write a program that accepts a vector of integers as input and counts the numberof integers that are multiples of 3 in that vector. You can assume that the inputcontains only integer values. An example run of your program can be as follows:Enter a vector of integers: [ 1 3 2 8 0 5 6 ]The number of multiples of 3 is 2(3) The root mean square is a way for calculating a mean fora set of numbers. The rmsaverage of a series of numbers is given as:∑==N i i xN rmsaverage 121Write a program that will accept an arbitrary number of input values and calculatethe rmsaverage of the numbers. The program should ask the user for the numberof values to be entered. Test your program with 4 and 10 set of numbers.% The root mean square is a way for calculating a mean for a set of numbers% Initializesum_x2=0;% Get the number of points to input.n=input('Enter number of points:');% Loop to read input valuesfor ii=1:n% Read in next valuex=input('Enter value:');% Calculate square sumssum_x2=sum_x2+x^2;end% Now calculate root mean squareroot_ms=sqrt(sum_x2/n);% Tell userfprintf('The number of data points is: %d\n',n);fprintf('The root mean square of this data set is: %f\n',root_ms);(4) 3.8 exercises:3.5(5) 4.7Exercises: 4.1 4.23 Quitting MATLABTyping quit on the command window will close the program. Do not forget to sendyour M-file to your TA.Do not forget to delete your files from the hard disk of the PC you used in the lab at the end of the lab session.四川师范大学MATLAB语言实验报告4系级班年月日实验名称:MATLAB/SIMULINK package姓名学号指导教师成绩1Objective●To learn how to use MATLAB/SIMULINK package●To learn how to estimate performance parameters from time-domain data2SIMULINK BasicBasic steps(1)Click on the MATLAB button to start MATLAB.(2)Once MATLAB has started up, type simulink (SMALL LETTERS!) at theMATLAB prompt (>>) followed by a carriage return (press the return key). A SIMULINK window should appear shortly, with the following icons: Sources, Sinks, Discrete, Linear, Connections, Extras.(3)Next, go to the File menu in SIMULINK window and choose New in order tobegin building the block diagram representation of the system of interest.(4)Open one or more of the block libraries and drag the chosen blocks into the active.(5)After the blocks are placed, draw lines to connect their input and output ports bymoving the mouse over a port and drag using the left button. To make a line witha right angle in it, release the button where you want thecorner, then click on theend of the line and drag to create next segment. To add a second line that runs off of an existing line click the right mouse on an existing line and drag it.(6)Save the system by selecting Save from the File menu.(7)Open the blocks by double-clicking and change some of their internal parameters.(8)Adjust some simulation parameters by selecting Parameters from the Simulationmenu. The most common parameter to change is Stop Time that defines the length of time the simulation will run.(9)Run the simulation by selecting Start from the Simulation menu. You can stop asimulation before completing by selecting Stop from the Simulation menu. (10)View the behavior of the system by attaching Scope blocks to the variables ofinterest, or by using To Workspace blocks to send data to the MATLAB workspace where you can plot the results using standard MATLAB commands.3Exercises(1)Your TA has shown you how to observe and print signals from the scope. Try thisout by printing out the input signal, which should be a -1V to 1V square wave with frequency 0.1 Hz. Note the peak-to-peak voltage difference of this signal.Note to write key blocks parameters.(2) Write a Simulink model to calculate the following differential equation,0)1(222=+--x dt dx x dt x d μInitialized 1)0(=x ,0)0(=dt dx 。

matlab实验报告总结精选

matlab实验报告总结精选

matlab实验报告总结电气工程学院自动化102班 2012年12月21日实验一 MATLAB环境的熟悉与基本运算一、实验目的1.熟悉MATLAB开发环境2.掌握矩阵、变量、表达式的各种基本运算二、实验基本知识1.熟悉MATLAB环境MATLAB桌面和命令窗口、命令历史窗口、帮助信息浏览器、工作空间浏览器、文件和搜索路径浏览器。

2.掌握MATLAB常用命令变量与运算符变量命名规则如下:变量名可以由英语字母、数字和下划线组成变量名应以英文字母开头长度不大于31个区分大小写MATLAB中设置了一些特殊的变量与常量,列于下表。

MATLAB运算符,通过下面几个表来说明MATLAB的各种常用运算符表2 MATLAB算术运算符表3 MATLAB关系运算符表4 MATLAB逻辑运算符表5 MATLAB特殊运算的一维、二维数组的寻访表6 子数组访问与赋值常用的相关指令格式的基本运算表7 两种运算指令形式和实质内涵的异同表的常用函数表8 标准数组生成函数表9 数组操作函数三、实验内容1、新建一个文件夹2、启动,将该文件夹添加到MATLAB路径管理器中。

3、保存,关闭对话框4、学习使用help命令,例如在命令窗口输入help eye,然后根据帮助说明,学习使用指令eye5、学习使用clc、clear,观察command window、command history和workspace等窗口的变化结果。

6、初步程序的编写练习,新建M-file,保存,学习使用MATLAB的基本运算符、数组寻访指令、标准数组生成函数和数组操作函数。

注意:每一次M-file的修改后,都要存盘。

练习A:help rand,然后随机生成一个2×6的数组,观察command window、command history和workspace等窗口的变化结果。

学习使用clc、clear,了解其功能和作用。

答:clc是清除命令窗体内容 clear是清除工作区间输入C=1:2:20,则C表示什么?其中i=1,2,3,?,10。

MATLAB实验报告3

MATLAB实验报告3

MATLAB实验报告3MATLAB实验报告3一、实验目的1.掌握MATLAB程序的调试方法;2.掌握MATLAB中的矩阵操作;3.熟悉MATLAB中处理图像的基本操作。

二、实验内容1.用MATLAB调试程序;2.用MATLAB进行矩阵运算;3.用MATLAB处理图像。

三、实验原理及步骤1.MATLAB程序的调试方法在MATLAB中调试程序可以采用设置断点、逐行运行、单步调试等方法。

设置断点可以在程序中的其中一行上点击左键,会出现一个红色的圆点表示断点已设置。

逐行运行可以通过点击Editor界面上的运行按钮实现。

单步调试可以通过点击断点所在行的左侧按钮实现。

2.矩阵运算在MATLAB中,对于矩阵的运算可以使用一些基本的函数,如矩阵加法、减法、乘法等。

矩阵加法可以使用"+"操作符实现,减法可以使用"-"操作符实现,乘法可以使用"*"操作符实现。

另外,MATLAB还提供了一些更复杂的矩阵运算函数,如矩阵的转置、逆等。

3.图像处理在MATLAB中,可以使用imread函数加载图像文件,使用imshow函数显示图像,使用imwrite函数保存图像。

另外,还可以使用一些图像处理函数对图像进行处理,如灰度化、二值化、平滑滤波等。

四、实验步骤1.调试程序首先,在MATLAB的Editor界面中打开要调试的程序文件。

然后,在程序的其中一行上点击左键,即设置了一个断点。

最后,点击运行按钮,程序会在断点处停下,然后可以通过单步调试和逐行运行来逐步查看程序的执行过程和变量的取值。

2.矩阵运算首先,定义两个矩阵A和B,并赋值。

然后,使用"+"操作符对两个矩阵进行相加,得到矩阵C。

最后,使用disp函数显示矩阵C的值。

3.图像处理首先,使用imread函数加载一张图像。

然后,使用imshow函数显示加载的图像。

接着,使用rgb2gray函数将彩色图像转换为灰度图像。

matlab实验报告

matlab实验报告

matlab实验报告实验报告:Matlab实验分析1. 实验目的本实验旨在通过Matlab软件完成一系列数值计算和数据分析的任务,包括绘制曲线、解方程、矩阵运算等,以加深对Matlab软件的理解和掌握。

2. 实验内容2.1 绘制函数曲线首先,我们通过在Matlab中输入函数的表达式来绘制函数曲线。

例如,我们可以输入y = sin(x)来绘制正弦函数的曲线。

另外,我们还可以设置曲线的颜色、线型和坐标轴范围等。

2.2 解方程接下来,我们使用Matlab来解方程。

对于一元方程,我们可以使用solve函数来求出方程的解。

例如,我们输入syms x; solve(x^2 - 2*x - 8)来解方程x^2 - 2x - 8 = 0。

而对于多元方程组,我们可以使用solve函数的向量输入形式来求解。

例如,我们输入syms x y; solve(x^2 + y^2 - 1, x - y - 1)来求解方程组x^2 + y^2 - 1 = 0和x - y - 1 = 0的解。

2.3 矩阵运算Matlab也可以进行矩阵运算。

我们可以使用矩阵相乘、相加和取逆等运算。

例如,我们可以输入A = [1 2; 3 4]和B = [5 6;7 8]来定义两个矩阵,然后使用A * B来计算它们的乘积。

3. 实验结果与分析在本实验中,我们成功完成了绘制函数曲线、解方程和矩阵运算等任务。

通过Matlab软件,我们可以快速、准确地进行数值计算和数据分析。

使用Matlab的高级函数和工具箱,我们可以更方便地处理复杂的数值计算和数据分析问题。

4. 实验总结通过本次实验,我们进一步加深了对Matlab软件的理解和掌握。

Matlab提供了丰富的函数库和工具箱,适用于各种不同的数值计算和数据分析任务。

在日常科研和工程实践中,Matlab是一个非常强大和方便的工具,可以帮助我们更高效地完成任务。

MATLAB实验报告

MATLAB实验报告

实验二MATLAB语言基础一、实验目的基本掌握MA TLAB向量矩阵数组的生成及基本运算(区分数组运算和矩阵预算)、常用的数学函数。

了解字符串的操作。

二、实验内容(1)向量的生成和运算。

(2)矩阵的创建、引用和运算。

(3)多维数组的创建和运算。

(4)字符创的操作。

三、实验步骤1.向量的生成和运算1)向量的生成<1>、直接输入法<2> 冒号表达式法<3> 函数法:Linspace()是线性等分函数,logspace()是对数等分函数。

2)向量的运算1>维数相同的行、列向量之间可以相加减,标量可以与向量直接相乘除。

2>向量的点积与叉积运算E1和E2虽然表达式相同,但E1是标量,E2是矩阵。

2.矩阵的创建、引用和运算1)矩阵的创建和引用矩阵是由m*n元素构成的矩形结构,行向量和列向量是矩阵的特殊形式。

1>直接输入法:2>抽取法:包括单下标抽取和全下表抽取两种方式,且两种方式抽取的元素都必须以小括号括起来。

3>函数法:利用ones(m;n)创建全1矩阵,zeros()创建全0矩阵,eyes()创建单位矩阵等等。

4>拼接法:纵向拼接横向拼接5>利用拼接函数cat()repmat()和变形函数reshape()>> A1=[1 2 3;9 8 7 ;4 5 6];A2=A1.';>> cat(1,A1,A2) 沿行向拼接ans =1 2 39 8 74 5 61 9 42 8 53 7 6>> cat(2,A1,A2) 沿列向拼接ans =1 2 3 1 9 49 8 7 2 8 54 5 6 3 7 6>> repmat(A1,2,2)ans =1 2 3 1 2 39 8 7 9 8 74 5 6 4 5 61 2 3 1 2 39 8 7 9 8 74 5 6 4 5 6> A=linspace(2,18,9)A =2 4 6 8 10 12 14 16 18 >> reshape(A,3,3)ans =2 8 144 10 166 12 182)矩阵的运算练习(1)用矩阵除法求下列方程组的解x=[x1;x2;x3]>> A=[6 3 4;-2 5 7;8 -1 -3];B=[3;-4;-7];X=A\BX =1.0200-14.00009.7200(2)求矩阵的秩A=[6 3 4;-2 5 7;8 -1 -3];>> rank(A)ans =3[X,lamda]=eig(A)X =0.8013 -0.1094 -0.16060.3638 -0.6564 0.86690.4749 0.7464 -0.4719lamda =9.7326 0 00 -3.2928 00 0 1.5602(3)矩阵的开方>> B=sqrtm(A)B =2.2447 + 0.2706i 0.6974 - 0.1400i 0.9422 - 0.3494i -0.5815 + 1.6244i 2.1005 - 0.8405i 1.7620 - 2.0970i1.9719 - 1.8471i -0.3017 + 0.9557i 0.0236 +2.3845i (4)矩阵的指数与对数:> C=expm(A)C =1.0e+004 *1.0653 0.5415 0.63230.4830 0.2465 0.28760.6316 0.3206 0.3745>> logm(C)ans =6.0000 3.0000 4.0000-2.0000 5.0000 7.00008.0000 -1.0000 -3.0000(6)矩阵的转置D=A'D =6 -2 83 5 -14 7 -3(7)矩阵的提取与翻转:通过各种特定函数如triu(A)、tril(A),diag(A)、flipud (A)、fliplr(A)等等。

(完整word)Matlab实验报告

(完整word)Matlab实验报告

实验一:Matlab操作环境熟悉一、实验目的1.初步了解Matlab操作环境.2.学习使用图形函数计算器命令funtool及其环境。

二、实验内容熟悉Matlab操作环境,认识命令窗口、内存工作区窗口、历史命令窗口;学会使用format 命令调整命令窗口的数据显示格式;学会使用变量和矩阵的输入,并进行简单的计算;学会使用who和whos命令查看内存变量信息;学会使用图形函数计算器funtool,并进行下列计算:1.单函数运算操作。

求下列函数的符号导数(1)y=sin(x);(2) y=(1+x)^3*(2-x);求下列函数的符号积分(1)y=cos(x);(2)y=1/(1+x^2);(3)y=1/sqrt(1—x^2);(4)y=(x1)/(x+1)/(x+2)求反函数(1)y=(x-1)/(2*x+3); (2) y=exp(x);(3) y=log(x+sqrt(1+x^2));代数式的化简(1)(x+1)*(x-1)*(x-2)/(x-3)/(x—4);(2)sin(x)^2+cos(x)^2;(3)x+sin(x)+2*x—3*cos(x)+4*x*sin(x);2.函数与参数的运算操作。

从y=x^2通过参数的选择去观察下列函数的图形变化(1)y1=(x+1)^2(2)y2=(x+2)^2(3) y3=2*x^2 (4) y4=x^2+2 (5) y5=x^4 (6) y6=x^2/2 3.两个函数之间的操作求和(1)sin(x)+cos(x) (2) 1+x+x^2+x^3+x^4+x^5乘积(1)exp(—x)*sin(x) (2) sin(x)*x商(1)sin(x)/cos(x); (2) x/(1+x^2); (3) 1/(x—1)/(x—2); 求复合函数(1)y=exp(u) u=sin(x) (2) y=sqrt(u) u=1+exp(x^2)(3) y=sin(u) u=asin(x) (4) y=sinh(u) u=-x实验二:MATLAB基本操作与用法一、实验目的1.掌握用MATLAB命令窗口进行简单数学运算。

matlab实验报告(实验4)

matlab实验报告(实验4)

学生实验报告开课学院及实验室: 机电学院2012年12月21日学院机电学院年级、专业、班姓名学号实验课程名称MATLAB程序设计成绩实验项目名称实验4: 数据和函数的可视化指导老师一、实验目的1、掌握MATLAB绘图的基本步骤和相关指令调用的先后顺序。

2、掌握MATLAB绘图指令的调用方法。

二、实验内容数学函数从形式上可以分为离散函数和连续函数。

MATLAB对这两种函数数据的可视化都提供了相应的指令。

仔细阅读教材【例5.1-1】的实现代码, 运行并保存结果;并改用stem函数, 画出【例5.1-1】的序列图。

仔细阅读教材【例5.1-2】的实现代码, 运行并保存结果;并分别使用描点和连折线方式, 画出连续函数y=xcosx的近似图形(采样点数自定, 要求画出的图尽量接近原连续函数的图)。

仔细阅读【例5.2-2】的实现代码, 理解plot指令画多条曲线的运用方法, 运行并保存结果;并使用plot函数和legend函数, 在同一个图形窗口上画出y=sint和y=sin(2t)在[0,2pi]区间上的图形, 并标出图例。

仔细阅读【例5.2-4】的实现代码, 理解图形标识选项的运用方法, 运行并保存结果;并修改代码, 把“sin(t)”字体改为正体, 大小改为20, “极大值”改为宋体。

阅读【例5.2-6】, 理解使用hold on指令画多幅图的方法, 运行并保存结果。

阅读【例5.2-8】, 理解使用subplot函数画多个子图的方法, 运行并保存结果。

(1)综合实验: 阅读以下关于通过绘制二阶系统阶跃响应综合演示图形标识的示例, 理解示例中所有图形标识指令的作用, 掌握各个图形标识指令的运用方法, 并在原指令上改动以实现以下功能:(2)把横坐标范围改为0至5pi, 纵坐标范围改为0至2;(3)把图中的横轴的刻度改为从0开始到4pi, 中间各点间隔为pi/2;纵轴刻度改为从0开始到1.5, 中间各点间隔为0.3;(4)把图中的α改为σ。

matlab 实验报告

matlab 实验报告

matlab 实验报告Matlab实验报告引言:Matlab是一种强大的数值计算和可视化软件,广泛应用于科学、工程和经济等领域。

本实验报告将介绍我在使用Matlab进行实验过程中的一些经验和结果。

实验一:矩阵运算在这个实验中,我使用Matlab进行了矩阵运算。

首先,我创建了一个3x3的矩阵A和一个3x1的矩阵B,并进行了矩阵相乘运算。

通过Matlab的矩阵乘法运算符*,我得到了一个3x1的结果矩阵C。

接着,我对矩阵C进行了转置操作,得到了一个1x3的矩阵D。

最后,我计算了矩阵C和矩阵D的点积,并将结果输出。

实验二:数据可视化在这个实验中,我使用Matlab进行了数据可视化。

我选择了一组实验数据,包括时间和温度两个变量。

首先,我将数据存储在一个矩阵中,并使用Matlab的plot函数将时间和温度之间的关系绘制成曲线图。

接着,我使用Matlab的xlabel、ylabel和title函数添加了横轴、纵轴和标题。

最后,我使用Matlab的legend函数添加了图例,以便更好地理解图表。

实验三:数值积分在这个实验中,我使用Matlab进行了数值积分。

我选择了一个函数f(x)进行积分计算。

首先,我使用Matlab的syms函数定义了符号变量x,并定义了函数f(x)。

接着,我使用Matlab的int函数对函数f(x)进行积分计算,并将结果输出。

为了验证结果的准确性,我还使用了Matlab的diff函数对积分结果进行了求导操作,并与原函数f(x)进行了比较。

实验四:信号处理在这个实验中,我使用Matlab进行了信号处理。

我选择了一个音频文件,并使用Matlab的audioread函数读取了该文件。

接着,我使用Matlab的fft函数对音频信号进行了傅里叶变换,并将结果绘制成频谱图。

为了进一步分析信号的特征,我还使用了Matlab的spectrogram函数绘制了信号的时频图。

通过对信号的频谱和时频图的观察,我可以更好地理解信号的频率和时域特性。

matlab实验一实验报告

matlab实验一实验报告

matlab实验一实验报告实验一:Matlab实验报告引言:Matlab是一种强大的数学软件工具,广泛应用于科学计算、数据分析和工程设计等领域。

本实验旨在通过使用Matlab解决实际问题,探索其功能和应用。

一、实验目的本次实验的主要目的是熟悉Matlab的基本操作和常用函数,了解其在科学计算中的应用。

二、实验内容1. 数值计算在Matlab中,我们可以进行各种数值计算,包括基本的加减乘除运算,以及更复杂的矩阵运算和方程求解。

通过编写相应的代码,我们可以实现这些功能。

例如,我们可以使用Matlab计算两个矩阵的乘积,并输出结果。

代码如下:```matlabA = [1 2; 3 4];B = [5 6; 7 8];C = A * B;disp(C);```2. 数据可视化Matlab还提供了强大的数据可视化功能,可以将数据以图表的形式展示出来,更直观地观察数据的规律和趋势。

例如,我们可以使用Matlab绘制一个简单的折线图,来展示某个物体在不同时间下的位置变化。

代码如下:```matlabt = 0:0.1:10;x = sin(t);plot(t, x);xlabel('Time');ylabel('Position');title('Position vs. Time');```3. 图像处理Matlab还可以进行图像处理,包括图像的读取、处理和保存等操作。

我们可以通过Matlab对图像进行增强、滤波、分割等处理,以及进行图像的压缩和重建。

例如,我们可以使用Matlab读取一张图片,并对其进行灰度化处理。

代码如下:```matlabimg = imread('image.jpg');gray_img = rgb2gray(img);imshow(gray_img);```三、实验结果与分析在本次实验中,我们成功完成了数值计算、数据可视化和图像处理等任务。

matlab实验报告实验二

matlab实验报告实验二

matlab实验报告实验二Matlab实验报告实验二引言Matlab是一种功能强大的数学软件,广泛应用于科学研究和工程实践中。

在实验二中,我们将探索Matlab的图像处理功能,并通过实际案例来展示其应用。

图像处理基础图像处理是指对图像进行数字化处理的过程,其目的是改善图像质量、提取有用信息或实现特定的应用需求。

在Matlab中,我们可以利用各种函数和工具箱来实现图像处理的各种任务,如图像增强、滤波、分割和特征提取等。

实验步骤1. 图像读取与显示在Matlab中,我们可以使用imread函数读取图像文件,并使用imshow函数将图像显示在屏幕上。

例如,我们可以读取一张名为"lena.jpg"的图像,并显示出来:```matlabimg = imread('lena.jpg');imshow(img);```2. 图像灰度化图像灰度化是将彩色图像转换为灰度图像的过程。

在Matlab中,我们可以使用rgb2gray函数将彩色图像转换为灰度图像。

例如,我们可以将上一步读取的图像转换为灰度图像:```matlabgray_img = rgb2gray(img);imshow(gray_img);```3. 图像二值化图像二值化是将灰度图像转换为二值图像的过程,其中只包含黑色和白色两种颜色。

在Matlab中,我们可以使用imbinarize函数将灰度图像二值化。

例如,我们可以将上一步得到的灰度图像二值化:```matlabbinary_img = imbinarize(gray_img);imshow(binary_img);```4. 图像平滑图像平滑是指去除图像中的噪声或细节,使得图像更加平滑和清晰。

在Matlab 中,我们可以使用imfilter函数对图像进行平滑处理。

例如,我们可以对上一步得到的二值图像进行平滑处理:```matlabsmooth_img = imfilter(binary_img, fspecial('average'));imshow(smooth_img);```5. 图像边缘检测图像边缘检测是指提取图像中物体边缘的过程,常用于目标检测和图像分割。

matlab实验报告

matlab实验报告

matlab实验报告引言:Matlab(矩阵实验室)是一款功能强大的数值计算和科学计算软件,广泛应用于工程、科学和经济等领域。

本实验报告将探讨我在使用Matlab进行实验过程中的心得体会和实验结果。

实验一:图像处理在这个实验中,我使用Matlab对一张图像进行了处理,并应用了各种图像处理算法。

这包括图像增强、边缘检测和图像分割等技术。

通过Matlab的图像处理工具箱,我能够轻松调用各种算法函数,并对图像进行快速处理。

实验结果表明,Matlab图像处理工具箱提供了丰富的函数和算法,极大地方便了我们的图像处理工作。

实验二:模拟信号处理模拟信号处理是Matlab中的一个重要应用领域。

在这个实验中,我模拟了一个带噪声的正弦信号,并使用Matlab进行了噪声滤波和频谱分析。

通过使用Matlab的滤波函数,我能够有效地去除信号中的噪声,并还原出原始信号。

同时,Matlab提供了功能强大的频谱分析工具,我可以轻松地对信号的频率特性进行分析和可视化。

实验三:数据分析与统计数据分析与统计是Matlab的另一个重要应用领域。

在这个实验中,我使用Matlab对一组实验数据进行了分析和统计。

通过使用Matlab的统计函数和工具,我能够计算出数据的均值、方差、标准差等统计指标,并绘制出数据的直方图和散点图。

这些统计分析结果对我的实验研究提供了有力的支持,并帮助我更好地理解实验数据。

实验四:数值计算与优化数值计算与优化是Matlab的核心功能之一。

在这个实验中,我使用Matlab进行了一组数值计算和优化实验。

通过使用Matlab的数值计算函数和优化工具箱,我能够快速计算出复杂的数学问题,并找到最优解。

同时,在进行优化实验时,我可以设置各种约束条件和目标函数,从而得到最优解的参数值。

这些数值计算和优化工具极大地提高了我的研究效率和准确度。

结论:通过这些实验,我深刻认识到Matlab的强大功能和广泛应用领域。

无论是图像处理、信号处理、数据分析还是数值计算与优化,Matlab都提供了丰富的函数和工具,让我们能够快速高效地完成实验和研究工作。

  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

MATLAB程序设计语言实验报告专业及班级:电子信息工程**:**学号:**********日期 2013年6月20日实验一 MATLAB 的基本使用【一】 实验目的1.了解MATALB 程序设计语言的基本特点,熟悉MATLAB 软件的运行环境;2.掌握变量、函数等有关概念,掌握M 文件的创建、保存、打开的方法,初步具备将一般数学问题转化为对应计算机模型处理的能力;3.掌握二维图形绘制的方法,并能用这些方法实现计算结果的可视化。

【二】 MATLAB 的基础知识通过本课程的学习,应基本掌握以下的基础知识: 一. MATLAB 简介 二. MATLAB 的启动和退出 三. MATLAB 使用界面简介 四. 帮助信息的获取五. MATLAB 的数值计算功能六. 程序流程控制 七. M 文件八. 函数文件九. MATLAB 的可视化 【三】上机练习1. 仔细预习第二部分内容,关于MATLAB 的基础知识。

2. 熟悉MATLAB 环境,将第二部分所有的例子在计算机上练习一遍3.已知矩阵⎥⎥⎥⎦⎤⎢⎢⎢⎣⎡=⎥⎥⎥⎦⎤⎢⎢⎢⎣⎡=123456789,987654321B A 。

求A*B ,A .* B ,比较二者结果是否相同。

并利用MATLAB 的内部函数求矩阵A 的大小、元素和、长度以及最大值。

程序代码:>> A=[1 2 3;4 5 6;7 8 9]; >> B=[9 8 7;6 5 4;3 2 1]; >> A*B ans =30 24 1884 69 54138 114 90>> A.*Bans =9 16 2124 25 2421 16 9 两者结果不同>> [m,n]=size(A)m =3n =3>> b=sum(A)b =12 15 18>> a=length(A)a =3>>max(A)ans =7 8 9 运行结果:4. Fibonacci 数组的元素满足Fibonacci 规则:),2,1(,12=+=++k a a a k k k ;且121==a a 。

现要求该数组中第一个大于10000的元素。

1) 在命令窗口中完成; 2) 利用M 文件完成;3) 自己定义一个函数文件,并在命令窗口中调用该函数完成。

程序代码:解:(1)>> a1=1;>> a2=1; >> b=0;>> while b<10000 b=a1+a2; a1=a2; a2=b; end >> b b =10946(2)function Fibonacci (x,y,z)a1=x; a2=y; b=0;while b<z b=a1+a2; a1=a2; a2=b; end将此函数定义为M 文件。

>> Fibonacci (1,1,1000)>> b =109465. 在同一个图形窗口的两个子窗口中分别画出)4cos(x π(红色、虚线)和)8cos(x π(蓝色、星号)的波形。

要求有标题,x 、y 轴有标注。

程序代码:>> x=-10:0.1:10;y1=cos((pi/4)*x);subplot(2,2,1),plot(x,y1,'r:') xlabel('x1')ylabel('y1=cos((pi/4)*x)') title('余弦函数') >> x=-10:0.1:10; y2=cos((pi/8)*x);subplot(2,2,2),plot(x,y1,'b-.p') xlabel('x2')ylabel('y2=cos((pi/8)*x)') title('余弦函数')运行结果:【四】思考题1.在语句末加分号“;”和不加分号有什么区别?2.M文件和函数文件有什么异同之处?3.矩阵乘(*)和数组乘(.*)有何不同?实验二信号的表示及可视化【一】实验目的1.掌握连续信号的MATLAB表示方法(表达式及图形描述);2.掌握离散序列的MATLAB表示方法(表达式及图形描述);【二】实验原理在MATLAB中通常用两种方法来表示信号,一种是向量表示信号,另一种则是用符号运算的方法来表示信号。

用适当的MATLAB语句表示出信号后,我们就可以利用MATLAB 的绘图命令绘出直观的信号波形。

一. 连续时间信号的表示及可视化从严格意义上来讲,MATLAB并不能处理连续信号,在MATLAB中,是用连续信号在等时间间隔点的样值来近似地表示连续信号的,当取样时间间隔足够小时,这些离散的样值就能较好的近似出连续信号。

1. 向量表示法对于连续时间信号f(t),我们可以用两个行向量f 和t 来表示,其中t 向量是形如t=t 1:p:t 2的MATLAB 命令定义的时间范围向量,t 1为信号起始时间,t 2为终止时间,p 为时间间隔。

向量f 为连续信号f(t)在向量t 所定义的时间点上的样值。

2. 符号运算表示法如果信号可以用一个符号表达式来表示它,则我们可用ezplot 命令绘制出信号的波形。

3.常用连续信号的表示 1)单位阶跃信号单位阶跃信号的定义为:⎩⎨⎧<>=0001)(t t t ε单位阶跃信号是信号分析的基本信号之一,在信号与系统分析中有着十分重要的作用,常用于简化信号的时域表示。

根据单位阶跃信号的特性,我们可以用它来表示时限信号和单边信号(因果信号)。

2)单位冲激信号单位冲激信号的定义为⎩⎨⎧≠==⎰∞∞-0,0)(1)(t t dt t δδδ(t)的定义表明,该信号除原点以外,处处为零,且信号面积为一。

即设有矩形脉冲)(t p n ,则由δ(t)的定义可得)(lim )(0t p t n n →=δ 二. 离散时间信号的表示及可视化1.一般离散信号的表示一般说来,离散时间信号用f(k)表示,其中变量k 为整数,代表离散的采样时间点。

在MATLAB 中,用一个向量f 即可表示一个有限长度的序列。

但是,这样的向量并没有包含其对应的时间序号信息。

所以,要完整地表示离散信号需要用两个向量。

2.典型离散序列的表示下面通过一些典型的离散信号来说明如何用MATLAB 实现离散序列的表示和可视化。

1)单位序列δ(k) 单位序列的定义为⎩⎨⎧≠==0001)(k k k δ由单位序列定义知,只有在k=0时,δ(k)的值为1,而其它时刻为0,因此,用MATLAB 来表示单位序列及绘制其波形非常简单。

2)单位阶跃序列 单位阶跃序列⎩⎨⎧<≥=0001)(k k k ε3)正弦序列正弦序列的表达式为:)cos()(ϕω+=k A k f式中k 为无量纲的整数,ω和ϕ以弧度为单位,ω称为正弦序列的数字角频率,ϕ为初相位。

需要注意的是:并非所有的正弦序列都是周期的。

这是因为离散时间信号的自变量和周期序列的周期都必须是整数,在正弦序列中并非对任意ω都能找到正整数的周期N.现在我们就来讨论正弦序列为周期序列的条件。

【三】上机练习1.认真预习实验原理的内容,将所有例题在计算机上练习一遍。

2. 用MATLAB 命令绘制单边指数信号e-1.5 tε(t)在时间0<t<3区间的波形。

要求有标题,在(3.1,0.05)处标注’t ’,利用axis 调整坐标轴在一个合适的范围,便于观察波形。

程序代码:>> t=0:0.01:3;>> y=exp(-1.5*t)*; >> plot(t,y)>> text(3.1,0.05,'t') >> title('函数')>>axis([-0.1 3.5 0 1.1])运行结果:3. 绘制δ(t-2),-1<t<5的波形。

程序代码:function chongji(t1,t2,t0)dt=0.01;t=t1:dt:t2;n=length(t);x=zeros(1,n);x(1,(-t0-t1)/dt+1)=1/dt;stairs(t,x);axis([t1,t2,0,1.2/dt])title('单位冲激信号')调用:chongji(-1,5,-2)运行结果:4. 绘制ε(k-3),-1≤k≤5及ε(k+1),-5≤k≤2。

程序代码:function jyxulie(k1,k2,k0)k=k1:-k0-1;kk=-k0:k2;n=length(k);nn=length(kk);u=zeros(1,n); %k0前信号赋值为零uu=ones(1,nn); %k0后信号赋值为一stem(kk,uu,'filled')hold onstem(k,u,'filled') hold offaxis([k1,k2,0,1.5]) title('单位阶跃序列') 调用jyxulie(-1,5,-3)运行结果:jyxulie(-5,2,1)5.考虑下面3个信号:f1(n)=cos(2πn/N)+2cos(3πn/N)f2(n)=2cos(2n/N)+2cos(3n/N)f3(n)=cos(2πn/N)+3cos(5πn/N)假设对每个信号N=6。

试确定上述信号是否是周期的。

如果是,则确定信号的周期,并画图表示出该信号的两个周期;如果不是周期的,在[0,4N]的范围内画出该信号,并说明原因。

答:f1(n)=cos(2πn/N)+2cos(3πn/N)是周期的。

周期为12 代码程序代码:>> n=0:24;>> subplot(2,2,1)>> stem(n,cos(n*2*pi/6)+2*cos(n*3*pi/6),'filled')运行结果:f2(n)=2cos(2n/N)+2cos(3n/N)非周期序列f3(n)=cos(2πn/N)+3cos(5πn/N)周期序列周期为60代码>> n=0:24;>> subplot(2,1,1)>> stem(n,2*cos(n*2/6)+2*cos(n*3/6),'filled')>> title('2*cos(n*2/6)+2*cos(n*3/6)')>> n=0:120;>> subplot(2,1,2)>> stem(n,cos(n*2*pi/6)+3*cos(pi*n*5/6),'filled')>> title('cos(n*2*pi/6)+3*cos(pi*n*5/6)')【四】思考题1. 观察例2-1的执行结果,当把时间间隔p取得更小(例如为0.02)时,观察执行结果,比较两结果用何不同,为什么?2.例2-3中的hold on和hole off命令的作用是什么?实验三信号的时域运算、时域变换及MATLAB实现【一】实验目的1.掌握信号时域运算的MATLAB实现方法2.掌握信号时域变换的MATLAB实现方法【二】实验原理信号的时域运算包括信号的相加、相乘,信号的时域变换包括信号的平移、反折、倒相及信号的尺度变换。

相关文档
最新文档