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的线性代数计算库,进行最小二乘法的计算。
实验结果:成功掌握最小二乘法的计算方法,并了解其在实际应用中的作用。
实验六:常微分方程实验目的:了解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环境下使用几种不同的插值法和拟合两种方法构造函数依据已经知道的某些特殊点来推测实际问题中需要知道但又不便于测量出来的量。
【实验原理】
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实验报告(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实验报告1MATLAB实验报告1摘要:本实验使用MATLAB软件进行了一系列的实验,主要包括数据处理、图像处理和信号处理。
通过实验,我们掌握了MATLAB软件在科学计算和工程领域的应用,深入了解了MATLAB在数据处理、图像处理和信号处理方面的强大功能。
一、数据处理实验在数据处理实验中,我们使用MATLAB对一组实验数据进行了分析和处理。
首先,我们导入了实验数据并进行了数据清洗和预处理,然后利用MATLAB的统计分析工具对数据进行了描述性统计分析,包括均值、方差、标准差等指标的计算。
接着,我们利用MATLAB的绘图工具绘制了数据的直方图和散点图,直观地展现了数据的分布规律和相关性。
二、图像处理实验在图像处理实验中,我们使用MATLAB对一幅图像进行了处理和分析。
首先,我们读取了图像并进行了灰度化处理,然后利用MATLAB的图像滤波工具对图像进行了平滑和锐化处理,最后利用MATLAB的图像分割工具对图像进行了分割和特征提取。
通过实验,我们深入了解了MATLAB在图像处理领域的应用,掌握了图像处理的基本原理和方法。
三、信号处理实验在信号处理实验中,我们使用MATLAB对一组信号进行了处理和分析。
首先,我们生成了一组模拟信号并进行了频域分析,利用MATLAB的信号滤波工具对信号进行了滤波处理,然后利用MATLAB的频谱分析工具对信号的频谱特性进行了分析。
通过实验,我们深入了解了MATLAB在信号处理领域的应用,掌握了信号处理的基本原理和方法。
综上所述,本实验通过对MATLAB软件的应用实验,使我们对MATLAB在数据处理、图像处理和信号处理方面的功能有了更深入的了解,为我们今后在科学计算和工程领域的应用奠定了良好的基础。
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-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实验报告

实验结果及分析实验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。
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
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({'计算机系';'外语系';'音乐系';'美术系';'中文系';'理科系'}) %交互式标注。