MATLAB实验报告
- 格式:doc
- 大小:106.50 KB
- 文档页数:3
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的线性代数计算库,进行最小二乘法的计算。
实验结果:成功掌握最小二乘法的计算方法,并了解其在实际应用中的作用。
实验六:常微分方程实验目的:了解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语言实验报告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实验报告1MATLAB实验报告1摘要:本实验使用MATLAB软件进行了一系列的实验,主要包括数据处理、图像处理和信号处理。
通过实验,我们掌握了MATLAB软件在科学计算和工程领域的应用,深入了解了MATLAB在数据处理、图像处理和信号处理方面的强大功能。
一、数据处理实验在数据处理实验中,我们使用MATLAB对一组实验数据进行了分析和处理。
首先,我们导入了实验数据并进行了数据清洗和预处理,然后利用MATLAB的统计分析工具对数据进行了描述性统计分析,包括均值、方差、标准差等指标的计算。
接着,我们利用MATLAB的绘图工具绘制了数据的直方图和散点图,直观地展现了数据的分布规律和相关性。
二、图像处理实验在图像处理实验中,我们使用MATLAB对一幅图像进行了处理和分析。
首先,我们读取了图像并进行了灰度化处理,然后利用MATLAB的图像滤波工具对图像进行了平滑和锐化处理,最后利用MATLAB的图像分割工具对图像进行了分割和特征提取。
通过实验,我们深入了解了MATLAB在图像处理领域的应用,掌握了图像处理的基本原理和方法。
三、信号处理实验在信号处理实验中,我们使用MATLAB对一组信号进行了处理和分析。
首先,我们生成了一组模拟信号并进行了频域分析,利用MATLAB的信号滤波工具对信号进行了滤波处理,然后利用MATLAB的频谱分析工具对信号的频谱特性进行了分析。
通过实验,我们深入了解了MATLAB在信号处理领域的应用,掌握了信号处理的基本原理和方法。
综上所述,本实验通过对MATLAB软件的应用实验,使我们对MATLAB在数据处理、图像处理和信号处理方面的功能有了更深入的了解,为我们今后在科学计算和工程领域的应用奠定了良好的基础。
MATLAB软件的强大功能和广泛应用前景,将为我们的学习和科研工作提供有力的支持和帮助。
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 。
实验结果及分析实验1:程序如下x=1:10y=2*x;plot(x,y)仿真结果:实验结果分析:仿真结果是条很规则的直线,X轴和Y轴一一对应,清楚明了,而序又特别简单。
所以用Maltab 软件很方便地画出规则的直线,方便研究。
实验结果及分析1、A=2、A=1A=实验结果及分析实验三 Matlab在信号与系统中的应用实验名称实验1、掌握信号与系统课程中基本知识的Matlab编程、仿真方法目的实验原理实验1程序:b=[1];a=[1 1];p=;t=0:p:5;x=exp(-3*t);subplot(1,2,1);impulse(b,a,0:p:5);title('冲激响应');subplot(1,2,2);step(b,a,0:p:5);title('阶跃响应');实验内容<设计性实验>1、用MATLAB在时域中编程求解y′(t)+y(t)=f(t), f(t)= exp(-3t)ε(t)的冲激响应、阶跃响应。
在simulink仿真环境下,设计系统框图,分析系统的冲激响应、阶跃响应。
<设计性实验>(选做)2、用MATLAB在时域中编程求解y′(t)+y(t)=f(t), f(t)=(1+exp(-3t))ε(t)的冲激响应、阶跃响应,要求用conv编程实现系统响应。
在simulink仿真环境下,设计系统框图,分析系统的冲激响应、阶跃响应。
实验结果及分析实验1仿真结果:simulink仿真环境下冲激响应阶跃响应实验名称实验四 Matlab在数字信号处理中的应用实验结果及分析实验1仿真结果:6khz12kHZ。
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实验报告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实验分析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语言基础一、实验目的基本掌握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)等等。
实验一: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命令窗口进行简单数学运算。
学生实验报告开课学院及实验室: 机电学院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进行了矩阵运算。
首先,我创建了一个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的基本操作和常用函数,了解其在科学计算中的应用。
二、实验内容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中,我们可以利用各种函数和工具箱来实现图像处理的各种任务,如图像增强、滤波、分割和特征提取等。
实验步骤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. 图像边缘检测图像边缘检测是指提取图像中物体边缘的过程,常用于目标检测和图像分割。
第1篇一、实验背景随着计算机技术的飞速发展,数学软件在数学研究、工程应用、科学计算等领域发挥着越来越重要的作用。
数学软件如MATLAB、Mathematica、MathCAD等,为数学工作者提供了强大的计算、图形、符号处理等功能。
本实验旨在通过使用数学软件MATLAB进行数学实验,提高我们的数学素养和实际操作能力。
二、实验目的1. 熟悉MATLAB软件的基本操作和常用命令;2. 培养运用MATLAB解决实际问题的能力;3. 提高数学建模和数学计算能力;4. 深化对数学理论知识的理解。
三、实验内容1. MATLAB基本操作:学习MATLAB的界面、命令窗口、编辑器、图形窗口等基本操作;2. 数值计算:掌握MATLAB的数值计算功能,如求和、求积、求导、积分等;3. 符号计算:学习MATLAB的符号计算功能,如代数运算、微积分运算、解方程等;4. 数据处理:掌握MATLAB的数据处理功能,如数据读取、数据存储、数据排序等;5. 图形绘制:学习MATLAB的图形绘制功能,如二维图形、三维图形、参数曲线等;6. 数学建模:运用MATLAB进行数学建模,解决实际问题。
四、实验过程1. 安装MATLAB软件,熟悉软件界面和基本操作;2. 学习MATLAB编程基础,掌握常用命令和函数;3. 阅读教材和参考书籍,了解MATLAB在数学领域的应用;4. 按照实验指导书,完成实验任务,如数值计算、符号计算、数据处理、图形绘制等;5. 分析实验结果,总结实验经验,撰写实验报告。
五、实验心得1. 熟练掌握MATLAB软件的基本操作和常用命令是进行数学实验的前提。
在本实验中,我通过不断练习,熟练掌握了MATLAB的界面操作、命令输入和图形绘制等功能。
2. MATLAB在数值计算方面具有强大的功能。
通过本实验,我学会了使用MATLAB 进行求和、求积、求导、积分等数值计算,提高了我的数学计算能力。
3. MATLAB的符号计算功能让我对数学理论知识的理解更加深刻。
matlab实验报告引言:Matlab(矩阵实验室)是一款功能强大的数值计算和科学计算软件,广泛应用于工程、科学和经济等领域。
本实验报告将探讨我在使用Matlab进行实验过程中的心得体会和实验结果。
实验一:图像处理在这个实验中,我使用Matlab对一张图像进行了处理,并应用了各种图像处理算法。
这包括图像增强、边缘检测和图像分割等技术。
通过Matlab的图像处理工具箱,我能够轻松调用各种算法函数,并对图像进行快速处理。
实验结果表明,Matlab图像处理工具箱提供了丰富的函数和算法,极大地方便了我们的图像处理工作。
实验二:模拟信号处理模拟信号处理是Matlab中的一个重要应用领域。
在这个实验中,我模拟了一个带噪声的正弦信号,并使用Matlab进行了噪声滤波和频谱分析。
通过使用Matlab的滤波函数,我能够有效地去除信号中的噪声,并还原出原始信号。
同时,Matlab提供了功能强大的频谱分析工具,我可以轻松地对信号的频率特性进行分析和可视化。
实验三:数据分析与统计数据分析与统计是Matlab的另一个重要应用领域。
在这个实验中,我使用Matlab对一组实验数据进行了分析和统计。
通过使用Matlab的统计函数和工具,我能够计算出数据的均值、方差、标准差等统计指标,并绘制出数据的直方图和散点图。
这些统计分析结果对我的实验研究提供了有力的支持,并帮助我更好地理解实验数据。
实验四:数值计算与优化数值计算与优化是Matlab的核心功能之一。
在这个实验中,我使用Matlab进行了一组数值计算和优化实验。
通过使用Matlab的数值计算函数和优化工具箱,我能够快速计算出复杂的数学问题,并找到最优解。
同时,在进行优化实验时,我可以设置各种约束条件和目标函数,从而得到最优解的参数值。
这些数值计算和优化工具极大地提高了我的研究效率和准确度。
结论:通过这些实验,我深刻认识到Matlab的强大功能和广泛应用领域。
无论是图像处理、信号处理、数据分析还是数值计算与优化,Matlab都提供了丰富的函数和工具,让我们能够快速高效地完成实验和研究工作。
MATLAB实验报告
一、实验名称
实验5图形绘制(2)
二、实验目的:
熟悉和掌握MA TLAB的多种二维和三维图形绘制函数。
三、实验内容:
1.二维图形绘制函数
x=-2:0.1:2; y=sin(x);
subplot(221) %将图形窗口划分成2*2的四块,当前编辑第1块
stairs(x,y) %绘制梯形图
title('(a) stairs') %加标注
subplot(222) %当前编辑2*2的图形窗口中的第2块
compass(cos(x),y) %绘制罗盘图
title('(b) compass')
y1=randn(1,10000);
subplot(223)
hist(y,20) %绘制出柱状图
title('(c) hist')
subplot(224)
[u,v]=meshgrid(-2:0.2:2,-1:0.15:1);%为三维绘图产生x,y数据矩阵
z=u.*exp(-u.^2-v.^2);
contour(u,v,z) %绘制矩阵的等高线
title('(d) contour')
2.误差限图绘制函数
x=-2:0.2:2;
y=sin(x);
L=rand(1,length(x))/10;
U=rand(1,length(x))/10; %产生数据
errorbar(x,y,L,U,':') %绘制误差限图
3.复数图绘制函数
z=[2+3i,2+2i,1-2i,4i,-3];
x=[2,2,1,0,-3];
y=[3,2,-2,4,0]; %将复数输入
subplot(1,2,1),compass(z,'r') %在一分为二的图形框中的左图绘制罗盘图
subplot(1,2,2),feather(x,y,'b') %在图形框中的右图绘制速度向量图
4.标准球面绘制程序。
subplot(2,2,1) %将图形窗口划分成2*2的四块,当前编辑第1块
sphere(3); %绘制球形图,图形由2*2块组成
title('n=3') %加标题
axis equal %让绘制图形的各个坐标轴等长
subplot(2,2,2) %当前编辑第2块
sphere(6); %绘制球形图,图形由6*6块组成
title('n=6')
axis equal
subplot(2,2,3)
sphere(10)
title('n=10')
axis equal
subplot(2,2,4)
sphere(15);
title('n=15')
axis equal
5.绘制三维网格图
绘制下面给出的二元函数的网格图。
222
2y x y x sin z ++=
[x,y]=meshgrid(-8:0.5:8,-10:0.5:10);
R=sqrt(x.^2+y.^2)+eps;
z=sin(R)./R; %算出z 值
mesh(x,y,z); %绘制网格曲线
四、回答问题:
本次实验未预留问题。
五、遇到的问题及解决:
做思考题2的时候由于选择的数值范围不正确,导致输出的结果为复数,从而无法输出图像。
解决方法是认真思考求出函数的定义域
六、体会:
本次实验学会了很多作图函数的使用方法。
难点是弄清楚函数的具体格式与使用方法。
体会是:多学多练,孰能生巧,日积月累,必有提高。
思考题:
1.试绘制出 2222)1(1)(11
)y ,x (f z y x y x ++++-==的三维曲面图。
[x,y]=meshgrid(-0.9:0.1:0.9,-2:0.2:2); %设置合理区间
a=sqrt(1-x.^2+y.^2);
b=sqrt(1+x.^2+y.^2);
z=1./a+1./b; %求出z 值
surf(x,y,z) %画出三维曲面图
2.某校共有1560名学生,其中计算机系有213名学生,外语系有387名学生,音乐系有220名学生,美术系有280名学生,中文系有280名学生,理科系180名学生,分别画出饼图、条形图示意学生分布。
X=[213 387 220 280 280 180];
pie(X); %画饼图
hold on;
pie(X,{'计算机系','外语系','音乐系','美术系','中文系','理科系'}) %画饼图并标注
bar(X) %画条形图
gtext({'计算机系';'外语系';'音乐系';'美术系';'中文系';'理科系'}) %交互式标注。