数学软件MATLAB实验报告 实验八
- 格式:doc
- 大小:150.50 KB
- 文档页数:6
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。
《高等数学》实验报告(二)实验项目名称:多元函数积分学分组第八组组员姓名学号专业班级实验软件Matlab2010b完成日期实验成绩一、实验目的:加强对Matlab 软件的基本操作,会利用符号计算中int 积分嵌套命令求二重积分、三重积分。
会合理运用int 嵌套命令求解第一类、第二类曲线积分及第一类、第二类曲面积分以及Green 公式及Gauss 公式解题。
结合已经学习的内容,学会分析上述有关内容的综合问题并利用软件给出正确的解答。
二、 实验内容、步骤与结果:8. 计算二重积分 arctan D y d xσ⎰⎰ 其中D 是由圆224x y += 、 及直线y=0, y=x 所围成的在第一象限内的闭区域。
>> syms x y rho theta>> i=int(int(atan(tan(theta))*rho,rho,1,2),theta,0,(0.25)*pi)i =(3*pi^2)/6418. 计算三重积分 e x y z dxdydz ++Ω⎰⎰⎰,其中, 是平面x+y+z=1与三个坐标面围成的立体。
>> syms x y z;>> i=int(int(int(exp(x+y+z),z,0,1),y,0,1-x),x,0,1)i =exp(1) - 128. 计算曲线积分 2()()L x y dx x y dy ++-⎰,其中,L 沿直线从(1,0) 到(0,1), 再沿直线从(0,1)到(-1,0)。
过程syms x y;p=x^2+y;q=x-y;fun=(x^2+y)*diff(p,x)+(x-y)*diff(q,y);I=int(fun,x,1,0);I=int(fun,y,0,1)I =1/2+2*x^3I=int(fun,x,0,-1);I=int(fun,y,1,0)I =-1/2-2*x^3结果由(1,0)到(0,1)I =1/2+2*x^3由(0,1)到(-1,0)I =-1/2-2*x^338求半径为a的球面面积。
实验一、Matlab 软件的安装与基本使用一、实验目的和要求:学会MA TLAB 软件的安装方法,熟悉MA TLAB 的工作环境及其基本功能的设置,以及基本指令的使用,了解MA TLAB 数值数组及其矩阵操作的使用、复数的输入方法。
二、实验内容和步骤:1、完成MA TLAB 软件的安装。
2、安装完成后启动MA TLAB 软件,熟悉MA TLAB 的工作环境。
打开MA TLAB 7,默认打开的窗口包括: (1)命令窗口(Command Window); (2)命令历史窗口(Command History); (3)工作间管理窗口(Workspace);(4)当前路径窗口(Current Directory)此外,还有捷径键、编译窗口、图形窗口和帮助窗口等其他种类的窗口,结合课本实例,熟悉每个窗口的功能和基本使用。
3、(1)求23)]47(212[÷-⨯+的运算结果,注意命令后有无分号的作用。
命令及结果如下:t=[12+2*(7-4)]/3^2t = 2(2)求20012x x v t at =++的值,其中t=5s 、010x m =、015/v m s =、29.81/sec a m =-。
命令及结果如下:syms t x0 v0 a; t=5,x0=10,v0=15,a=-9.18; x=x0+v0*t+1/2*a*t^2 t = 5 x0 = 10 v0 = 15 x = -29.7500(3) 设3x =, 4v =,用MA TLAB 命令求下列各式的值:1)22log()x v + 命令及结果如下:syms x v x=3,v=4; log(x^2+v^2)x = 3 ans =3.21892)2(2)x v - 命令及结果如下:syms x vx=3,v=4;f=(sqrt(x-3))/(x-2*v)^2 x = 3 f = 0 3) |sin 2|vx e命令及结果如下: syms x v x=3,v=4;t=abs(2*x)*exp(v) x = 3t = 327.58894、用三种不同的方法输入矩阵1234246836912a ⎛⎫ ⎪= ⎪ ⎪⎝⎭,运行并观察实验结果,矩阵的三种基本输入方法如下:a=[1,2,3,4;3,4,6,8;3,6,9,12] a =1 2 3 4 3 4 6 8 3 6 9 12>> a=[1,2,3,43,4,6,8 3,6,9,12]a =1 2 3 4 3 4 6 8 3 6 9 12>> >>利用M 文件创建 1 2 3 4 3 4 6 8 3 6 9125、输入复数矩阵⎥⎦⎤⎢⎣⎡-+++=i ii i24356223B ,并求其实部、虚部、模和幅角(分别用弧度和角度表示),了解MA TLAB 向量化运算的特点。
matlab计算机实验报告Matlab计算机实验报告引言Matlab是一种强大的计算机软件,广泛应用于科学计算、数据分析和工程设计等领域。
本实验报告旨在介绍我对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实验报告(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 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 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 ?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 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 array subscripts. 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 any nonzero value as true. Relational operators ( ==, =,>,>=,<,<=) are operators with two operands that produce either a true (1) or a false (0) result, depending on the values of the 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 same size. Be careful not to confuse the equivalence relational operator ( == ) with the assignment operator ( = ). Logic operators ( &, |, xor, ~ ) are operators with one ortwo operands that yield a logical result such as 0 or 1. There are three binary logic operators: 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 evaluated before 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 following result.=110001110011110111115arrarr5=arr4>0;(3) Write an expression using arr4 and a relational operator to produce the following result.=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 and column 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 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 语⾔实验报告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 programs you 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 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 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 。
数学实验报告一、实验目的1.学会用软件对矩阵进行一些数值运算。
2.学会用软件解线性方程组。
3.掌握逆矩阵的一种应用:整数逆矩阵加密、解密方法。
4.熟悉三维空间中的线性变换,加深对正交变换保持距离不变性的理解。
5.掌握泰勒级数在近似计算中的应用,从而理解数值逼近思想。
6.了解无理数e和欧拉常数C的由来历史。
7.了解圆周率π的计算历史,掌握计算圆周率π近似值的多种方法。
8.利用幂级数展开式计算无理数e和欧拉常数C的近似值。
9.学会根据实际问题建立线性规划模型。
10.掌握用软件求解线性函数极值问题。
11.学会建立0-1规划模型,掌握用软件求解0-1规划问题。
二、实验内容1.实验五:练习1:1.(1)程序代码[2,11,1;32,13;1,43,5][1;42][]()结果显示特解:(0.8571,-0.7143,0,0)基础解系:ξ1=(0.1429,-1.2857,1,0),ξ2=(0.1429,0.7143,0,1)通解:0.1429 0.1429 0.8571-1.2857 0.7143 -0.7143k1 1 + k2 0 + 0 12єR0 10感想与反思:A.通过解这道题,熟练掌握了用软件解线性方程组的方法B.手工解线性方程组非常繁琐,通过这道题,进一步认识到的强大2.实验五.练习2.24*4的加密锁:程序代码[3 7 15 22;2 5 11 17;3 6 13 21;9 18 36 46](q)(q)[68 105 108 105 103 101 110 99 101 32 105 115 116 32 116 104 101 32 109 111 116 104 101 114 32 111 102 32 115 117 99 99 101 115 115 32](w,4,9)(q)*b结果显示6*6的加密锁代码[2 3 4 2 1 6;7 7 11 9 2 17;4 6 9 5 2 12;8 7 12 9 2 17;3 3 4 2 1 6;6 4 6 6 1 2](q)(q)[68 105 108 105 103 101 110 99 101 32 105 115 116 32 116 104 101 32 109 111 116 104 101 114 32 111 102 32 115 117 99 99 101 115 115 32](w,6,6)*a(q)*b感想与反思:A.通过解这道题,熟练掌握了逆矩阵的一种应用:整数逆矩阵加密、解密方法B.用矩阵就可以完成对于信息的加密和解密,体会到了矩阵和的神奇C.在选择密码锁矩阵时可以对于一个单位矩阵进行多次初等变换,便于找到3.实验七,练习2.1程序代码单数阶导数在0处的值为零。
班级:通信班姓名:彭羊平学号: 222008315222033实验一:matlab的基本操作一、实验目的:1、了解MATLAB的集成环境,熟悉其基本操作。
2、了解MATLAB的基础知识,包括矩阵的建立、简单操作、逻辑操作和关系运算。
3、熟悉基本的数学函数和逻辑函数。
4、在命令窗口输入命令完成一些简单的功能,为MATLAB程序设计奠定基础。
二、实验内容:1、利用diag等函数产生下列矩阵:然后利用reshape函数将它们变换成行向量。
2、利用rand函数产生(0,1)间均匀分布的10*10随机矩阵A,然后统计A中大于等于0.6的元素的个数。
3、有一矩阵A,找出矩阵中值大于1的元素,并将它们重新排列成列向量B。
4、在一测量矩阵A(6*6),存在有奇异值(假设大于100的值为奇异值),编程实现删去奇异值所在的行。
三、实验结果:1、程序如下:a=fliplr(diag([8,-7,2])+diag([5,3],-1))a=reshape(a,1,9)b=diag([2,5,8])+diag([4],2)+diag([7],-2) b=reshape(b,1,9)结果如下:2、程序如下:A=rand(10)A=A>0.6sum(sum(A))结果如下:3、程序如下:A=fix(5*rand(5))a=A>1;K=find(a);for k=1:length(K)B(k)=A(K(k));endB=B'结果如下:4、程序如下:A=fix(100*rand(8))+5 B=A>100;k=find(any(B'))A(k,:)=0结果如下:班级:通信班姓名:彭羊平学号: 222008315222033实验二: matlab绘图(1)一、实验目的:1、了解MATLAB图形系统和各种图形函数。
2、熟悉MATLAB的基本图形操作,具备MATLAB画图能力。
3、熟悉各种数学函数,并通过图形函数画出。
实验报告说明:matlab 课程实验需撰写8个实验报告,每个实验报告内容写每次实验内容中标号呈黑体大号字显示的题目。
第一次实验内容:实验一 MATLAB 运算基础一、实验目的1.熟悉启动和退出MATLAB 的方法。
2.熟悉MATLAB 命令窗口的组成。
3.掌握建立矩阵的方法。
4.掌握MATLAB 各种表达式的书写规则以及常用函数的使用。
二、实验内容1.先求下列表达式的值,然后显示MATLAB 工作空间的使用情况并保存全部变量。
(1)22sin 8511z e ︒=+(2)12ln(2z x =,其中2120.455i +⎡⎤=⎢⎥-⎣⎦(3)0.30.33sin(0.3), 3.0, 2.9, 2.8,,2.8,2.9,3.02a ae e z a a --=+=---提示:利用冒号表达式生成a 向量,求各点的函数值时用点乘运算。
(4)2220141122123t t z t t t t t ⎧≤<⎪=-≤<⎨⎪--≤<⎩,其中t =0:0.5:2.5 提示:用逻辑表达式求分段函数值。
2.已知12344347873657A -⎡⎤⎢⎥=⎢⎥⎢⎥⎣⎦,131203327B -⎡⎤⎢⎥=⎢⎥⎢⎥-⎣⎦求下列表达式的值:(1) A+6=B 和A-B+I(其中I 为单位矩阵)。
(2) A*B 和A.*B 。
(3) A^3和A^.3 。
(4) A/B 和B\A 。
(5)[A ,B]和[A([1,3],;);B^2] 。
3.设有矩阵A 和B12345678910111213141516171819202122232425A ⎡⎤⎢⎥⎢⎥⎢⎥=⎢⎥⎢⎥⎢⎥⎣⎦, 30161769023497041311B ⎡⎤⎢⎥-⎢⎥⎢⎥=-⎢⎥⎢⎥⎢⎥⎣⎦(1) 求它们的乘积C 。
(2) 将矩阵C 的右下角3×2子矩阵赋给D (3) 查看MATLAB 工作空间使用情况。
4.完成下列操作:(1)求[100,999]之间能被21整除的数的个数。
实验报告(2) 求方程6823+-x x x >> a=[1 -8 6 -30])分别用直线和曲线拟合上海近15试验2: Matlab之基本程序设计(2)分别把x和b看成变量求syms a b c xf='a*x^2+b*x+c'(3)分别把x、求不定积分(1)dx c bx ax )(2++⎰4、求级数的和:∑∞=12 1nn n=sym('n');p1=symsum(1/n^2,n,1,inf) p1 =2、采用图形保持,在同一坐标)cos(25.02x e y x π-=。
>> x=0:pi/100:2*pi;y1=0.2*exp(-0.5*x).*cos(4*pi*x);plot(x,y1,'-b<');hold on3、用不同的标度在同一坐标)cos(25.02x e y x π-=。
>> x=0:pi/100:2*pi;y1=0.2*exp(-0.5*x).*cos(4*pi*x);y2=2*exp(-0.5*x).*cos(pi*x);plotyy(x,y1,x,y2)>>5、在π20≤≤x 区间内,绘制曲线x e y 5.012-=和形标注(至少包括图形标题、x 轴标注、y 及图例)。
试验5: Matlab之高级图形绘制1、绘制)tr 的极坐标图。
sin(tcos()>> t=0:pi/50:2*pi;r=sin(t).*cos(t);polar(t,r,'k-p')3、在同一个界面上绘制下面两个图形:万元)分别为:2347,1827,2043数的向量图(7+2i,2-3i,和-1.5-6i subplot(1,2,1);pie([2347,1827,2043,3025]);title('饼图');legend('一季度','二季度','三季度','四季度subplot(1,2,2);4、绘制三维曲面图sin(sin(y x z +=[x,y]=meshgrid(0:0.25:4*pi);z=sin(x+sin(y))-x/10;mesh(x,y,z);5、在XY 平面内选择区域[-8,8]]8,8[-⨯分别使用制2222/sin(y x y x z ++=的4种三维曲面图。
MATLAB 实验报告一、实验名称实验8 MATLAB 应用二、实验目的:了解MATLAB 在曲线拟合、插值和解线性方程方面的应用三、实验内容:1.曲线拟合已知离散点上的数据集[(x1,y1),(x2,y2),…,(xn,yn)],求得一解析函数y=f(x),使f(x)在原离散点xi 尽可能接近给定yi 值,这一过程叫曲线拟合,最常用的曲线拟合是最小二乘拟合,拟合结果可使误差的平方和最小,即找出使∑=n 1i 2i i y -)f(x 最小的f(x)。
x=[0.5,1.0,1.5,2.0,2.5,3.0];y=[1.75,2.45,3.81,4.80,7.00,8.60];p=polyfit(x,y,2); %最小二乘法拟合数据x1=0.5:0.05:3.0;y1=polyval(p,x1); %计算多项式在指定点的值plot(x,y,'*r',x1,y1,'-b'); %将拟合数据用曲线表示并将原数据点也标在图上2.一维插值year=1900:10:2010product=[75.995,91.972,105.711,123.203,131.669,...150.697,179.232,203.212,226.505,249.633,256.344,267.893];p2005=interp1(year,product,2005) %一维内插x=1900:1:2010y=interp1(year,product,x,'cubic'); %一维内插,三次曲线内插方式plot(year,product,'o',x,y) %作出图像四、回答问题:本次实验未预留问题五、遇到的问题及解决:思考题1由于没有使用点除,因而导致程序运行出错,改正后问题解决。
六、体会:MA TLAB ,重在实践,多学多练,必有提高。
思考题:1. 求定积分⎰=40)(dx x f a ,式中2x 2x 1sin 216ln ln )(2>≤⎪⎩⎪⎨⎧++=当当)π(x x x f quad.ma=quadl('log(x.^2)',0,2);b=quadl('log(16)./(2+sin((x+1).*pi))',2,4);c=a+b运行状况:>> quadWarning: Log of zero.> In inlineeval at 13In inline.feval at 34In quadl at 64In quad at 1c =1.97412.已知x=[1.2 1.8 2.1 2.4 2.63.0 3.3],y=[4.855.2 5.66.2 6.57.0 7.5],求对x 和y 进行6阶多项式拟合的系数。
MATLAB实验报告MATLAB实验报告姓名:学号:专业班级:指导⽼师:地点:⽇期:2012.12.17⽬录实验⼋............................................... - 3 -⼀、实验内容...................................... - 3 -⼆.实验结果:.................................... - 3 - 三.实验代码:.................................... - 4 - 实验九............................................... - 5 - 实验⼗⼀............................................. - 7 - ⼀.实验内容...................................... - 7 - ⼆.实验结果...................................... - 7 - 三.实验代码...................................... - 7 - 实验⼗⼆............................................. - 7 - ⼀.实验内容...................................... - 7 - ⼆.实验结果...................................... - 8 - 三.实验代码:................................... - 11 -实验⼋⼀、实验内容2、将100个学⽣5门功课的成绩存⼊矩阵P中,进⾏如下处理:(1)分别求每门课的最⾼分、最低分及相应学⽣序号。
(2)分别求没门功课的平均分和标准⽅差。
实验八用MATLAB进行系统频率特性分析
实验目的:
了解MATLAB的系统频率特性分析工具,掌握Bode图和Nyquist图的绘制方法。
实验设备:计算机、MATLAB软件。
实验步骤:
1.打开MATLAB软件,新建一个m文件,输入以下代码:
%定义传递函数
sys=tf([1],[1 1]);
%绘制Bode图
bode(sys)
%绘制Nyquist图
nyquist(sys)
2.运行代码,观察Bode图和Nyquist图的绘制结果。
3.尝试更改传递函数的参数,比如改变分母或分子多项式的系数,再次运行代码,观察绘图结果的变化。
实验原理:
系统频率特性分析是指对于输入信号的不同频率,系统对这些频率的响应情况进行分析。
MATLAB软件能够通过系统传递
函数的输入,绘制系统的Bode图和Nyquist图。
Bode图是一种常用于描述系统频率特性的图形,它将系统的
幅频特性和相频特性绘制在同一个图中。
在Bode图上,水平
轴为对数频率,纵轴为幅值(dB)和相位角(度数)。
Nyquist图也是一种用于描述系统频率特性的图形,它通过绘
制系统的复数频率响应函数对应的极点和零点的轨迹,来分析系统的稳定性。
在Nyquist图上,水平轴为实部,纵轴为虚部。
实验结果:
通过运行MATLAB程序,成功绘制了传递函数对应的Bode
图和Nyquist图,并且观察到了更改参数后绘图结果发生了相
应的变化。
实验一基本操作和简单语句输入一、实验环境计算机MATLAB软件二、实验目的1.熟悉MA TLAB的命令窗口。
2、掌握MATLAB的一些基本操作, 能够进行一般的数值计算。
3.实现语句的重调和修改。
三、实验内容与步骤1.启动MA TLAB2.观察MA TLAB窗口的各个组成部分(1)了解菜单栏各窗口项的功能, 用鼠标打开MA TLAB的各个菜单, 在状态栏里显示当前鼠标所指的菜单项的含义。
(2)用鼠标指向常用工具栏的每个工具按钮, 了解各工具按钮的含义。
3.命令窗口的打开和关闭(1)查看菜单窗口中有哪些菜单命令。
(2)在命令窗口中输入命令a=3;b=4;y=a*b+a/b, 然后回车, 查看命令显示结果。
>> a=3;b=4;y=a*b+a/b,y =12.7500(3)利用MA TLAB中编辑命令时常用的按键功能, 调用上一个语句, 对它进行修改(如把分号改成逗号, 看运行结果), 并把运行结果复制到word中保存。
>> a=3,b=4,y=a*b+a/b,a =3b =4y =12.7500(4)关闭命令窗口。
(5)打开命令窗口。
4.使用MA TLAB帮助熟悉MATLAB的帮助系统, 通过帮助系统了解有关内容。
5、在命令窗口中输入demo, 将出现MA TLAB的演示窗, 通过演示窗, 对MATLAB的功能进行一次浏览。
四、练习1.计算y=x^3+(x-0.98)^2/(x+1.25)^3-5*(x+1/x), x=2, x=3时的值。
>> x=2;y=x^3+(x-0.98)^2/(x+1.25)^3-5*(x+1/x)y =-4.4697>> x=3;y=x^3+(x-0.98)^2/(x+1.25)^3-5*(x+1/x)y =10.38652.计算cos(pi/3)-sqrt(9-sqrt(2))>> cos(pi/3)-sqrt(9-sqrt(2))ans =-2.25423.已知: a=3,A=4,b=a^2,B=b^2-1,c=a+A-2*B,C=a+B+2*c, 求: C>> a=3;A=4;b=a^2;B=b^2-1;c=a+A-2*B;C=a+B+2*cC =-2234.复数z1=1+3*i,z2=1+2*i,z3=2*exp((pi/6)*i),求z=(z1*z2)/z3>> z1=1+3*i;z2=1+2*i;z3=2*exp((pi/6)*i);z=(z1*z2)/z3z =-0.9151 + 3.4151i实验二矩阵和数组的操作一、实验环境计算机MATLAB软件二、实验目的1.掌握矩阵和数组的一般操作, 包括创建、保存、修改和调用等。
实验八基于MATLAB控制系统的频率法串联超前校正设计一、实验目的1、对给定系统设计满足频域性能指标的串联校正装置。
2、掌握频率法串联有源和无源超前校正网络的设计方法。
3、掌握串联校正环节对系统稳定性及过渡过程的影响。
二、实验原理用频率法对系统进行超前校正的基本原理,是利用超前校正网络的相位超前特性来增大系统的相位裕量,以达到改善系统瞬态响应的目标。
为此,要求校正网络最大的相位超前角出现在系统的截止频率(剪切频率)处。
串联超前校正的特点:主要对未校正系统中频段进行校正,使校正后中频段幅值的斜率为-20dB/dec,且有足够大的相位裕度;超前校正会使系统瞬态响应的速度变快,校正后系统的截止频率增大。
这表明校正后,系统的频带变宽,瞬态响应速度变快,相当于微分效应;但系统抗高频噪声的能力变差。
1、用频率法对系统进行串联超前校正的一般步骤为:1)根据稳态误差的要求,确定开环增益K。
2)根据所确定的开环增益K,画出未校正系统的波特图,计算未校正系统的相位裕度。
3)计算超前网络参数a和T。
4)确定校正网络的转折频率。
5)画出校正后系统的波特图,验证已校正系统的相位裕度。
6)将原有开环增益增加倍,补偿超前网络产生的幅值衰减,确定校正网络组件的参数。
三、实验内容1、频率法有源超前校正装置设计例1、已知单位负反馈系统被控制对象的传递函数为:试用频率法设计串联有源超前校正装置,使系统的相位裕度 ,静态速度误差系数 。
clc; clear;delta=2; s=tf('s');G=1000/(s*(0.1*s+1)*(0.001*s+1));margin(G) 原系统bode 图[gm,pm]=margin(G) phim1=50;phim=phim1-pm+delta; phim=phim*pi/180;alfa=(1+sin(phim))/(1-sin(phim)); a=10*log10(alfa); [mag,phase,w]=bode(G); adB=20*log10(mag); Wm=spline(adB,w,-a); t=1/(Wm*sqrt(alfa)); Gc=(1+alfa*t*s)/(1+t*s); [gmc,pmc]=margin(G*Gc) figure;margin(G*Gc) 矫正后bode figure(1);step(feedback(G,1)) 矫正后01 figure(2);step(feedback(G*Gc,1)) 矫正后02结果显示: gm = 1.0100 pm =0()(0.11)(0.0011)K G s s s s =++045γ≥11000v K s -=0.0584gmc =7.3983pmc =45.7404分析:根据校正前后阶跃响应的曲线可知:校正后的系统满足动态性能指标以及频域性能指标。
实验一 Matlab基本操作1.实验课程名称数学实验2.实验项目名称Matlab基本操作3.实验目的和要求了解Matlab的基本知识,熟悉其上机环境,掌握利用Matlab进行基本运算的方法。
4.实验内容和原理内容:三角形的面积的海伦公式为:area=)s-sa--)()(s(csb其中: s=(a+b+c)/2原理:将一般数学问题转化成对应的计算机模型并进行处理的能力。
了解Matlab的基本功能,会进行简单的操作。
5.主要仪器设备计算机与Windows 2000/XP系统;Matlab等软件。
6.操作方法与实验步骤步骤:(1)在M文件编辑窗口输入以下程序,并以文件名”area_helen.m”保存:a= input(‘a=‘) ; b= input(‘b=‘) ; c= input(‘c=‘) ;s= (a+b+c)/2;area=sqrt (s* (s-a) * (s-b) * (s-c))(2)在命令窗口输入文件名“area_helen”,按回车键,即可运行上面的程序,输入三边长,立即可得三角形面积(3)第二题在命令窗口输入b=6;a=3;c=a*b,d=c-2*b(4) 按回车键,即可运行上面的程序7.实验结果与分析<1> a=3; b=4; c=5;时,aera=6 当a为3,b为4,c为5时,s=6,aera=6<2> c= 18,d=6,a为3,b为6时,c=18,d=6实验二 Matlab的数值计算1.实验课程名称数学实验2.实验项目名称Matlab的数值计算3.实验目的和要求了解一些简单的矩阵、向量、数组和多项式的构造和运算方法实例,懂得编写简单的数值计算的Matlab程序。
熟悉一些Matlab的简单程序,会用Matlab的工具箱,懂得Matlab的安装和简单的使用。
4.实验内容和原理内容:从函数表:)1(),5.0(),2( ,0x 1x 021x 1x f(x) 32-⎪⎩⎪⎨⎧≤≤<>+=f f f x x求设)1(),2( ,1211)(2-⎩⎨⎧≤>+=f f x xx x x f 求设 原理:利用矩阵、向量、数组、和多项式的构造和运算方法,用常用的几种函数进行一般的数值问题求解。
解:设三个回路电流分别为、、则:1m I 2m I 3m I 图1图2MATLAB 把矩阵指令和结果如下:];[02U I m 解:设三个回路电流分别为、、,则:1m I 2m I 3m I 图3图4u I m 5.03-= 补充方程为: iI I m m =-31 i I I m m 5.012=- u I I m m =-32 由此可以解出、、、、。
A I m 11=A I m 32=A I m 33-=A i 4=A u 6= 将方程整理为: 14000)11(0321=+++-++U u i I I I m m m 000)11(00321=-++-++U u i I I I m m m 005.00000321=+++++U u i I I I m m m 00000321=++--+U u i I I I m m m 0005.000321=++-++-U u i I I I m m m 00000321=+-+-+U u i I I I m m m 然后用MATLAB 计算如下:其中];;;;;[321o m m m U u i I I I x =a=[1+1 0 -1 0 0 1;0 1+1 -1 0 0 -1;0 0 1 0 0.5 0;1 0 -1 -1 0 0;-1 10 -0.5 0 0;0 1 -1 0 -1 0];%定义a 矩阵b=[14;0;0;0;0;0];x=a\b %定义b 矩阵并求解运行结果为:x = 1 3 -3 4 6 9在以上例题中,采用的思想是找准未知量,采用分离变量的方法让未知量在方程组的一侧,然后把方程组写成矩阵形式Ax=B ,未知量构成的矩阵(后者列向量)x=A\B 。
所以在MATLAB 中建立好矩阵就可以求解了,节约了运算时间,以上例子都是手工带入数据整理方程组的,但注意的是:数据的值其实是取代的对应的元件,因此也可以用符号表示方法化简方程组后,编制M 文件,由MATLAB 带入数据进行运算.。
实验8 数据的统计描述和分析一、实验目的:1.理解和掌握数据统计描述和分析的基本概念与原理、常用方法及用MATLAB实现的方法;2.能够用MATLAB有关数据的统计描述和分析的方法解决实际问题,并根据所得的解给出实际问题合理的解释。
二、实验内容:1.设)X,求N~22,3((1)}5{|>X|P,}3XP;P,}2{><XP,}2{<104<{<-X程序1、>> a=normcdf(2,3,2);>> b=normcdf(5,3,2);>> b-aans =0.53282、>> a=normcdf(-4,3,2);>> b=normcdf(10,3,2);>> b-aans =0.99953、>> a=normcdf(-2,3,2);>> b=1-normcdf(2,3,2);>> a+bans =0.69774、>> b=1-normcdf(3,3,2)b =0.5000(2)满足条件}P>X<的常数c。
c={c{}XP程序:>> a=norminv(0.5,3,2)a =32.用某仪器间接测量温度(单位:℃),重复测量5次,得数据如下:1205,1265,1245,1260,1275已知测量值服从正态分布,试求温度的真值的置信水平为%95的置信区间。
程序>> x=[1205,1265,1245,1260,1275];>> [uh,sigh,u,sig]=normfit(x)结果uh = 1250sigh = 27.3861u = 1.0e+003 *1.21601.2840。
matlab实验报告引言:Matlab(矩阵实验室)是一款功能强大的数值计算和科学计算软件,广泛应用于工程、科学和经济等领域。
本实验报告将探讨我在使用Matlab进行实验过程中的心得体会和实验结果。
实验一:图像处理在这个实验中,我使用Matlab对一张图像进行了处理,并应用了各种图像处理算法。
这包括图像增强、边缘检测和图像分割等技术。
通过Matlab的图像处理工具箱,我能够轻松调用各种算法函数,并对图像进行快速处理。
实验结果表明,Matlab图像处理工具箱提供了丰富的函数和算法,极大地方便了我们的图像处理工作。
实验二:模拟信号处理模拟信号处理是Matlab中的一个重要应用领域。
在这个实验中,我模拟了一个带噪声的正弦信号,并使用Matlab进行了噪声滤波和频谱分析。
通过使用Matlab的滤波函数,我能够有效地去除信号中的噪声,并还原出原始信号。
同时,Matlab提供了功能强大的频谱分析工具,我可以轻松地对信号的频率特性进行分析和可视化。
实验三:数据分析与统计数据分析与统计是Matlab的另一个重要应用领域。
在这个实验中,我使用Matlab对一组实验数据进行了分析和统计。
通过使用Matlab的统计函数和工具,我能够计算出数据的均值、方差、标准差等统计指标,并绘制出数据的直方图和散点图。
这些统计分析结果对我的实验研究提供了有力的支持,并帮助我更好地理解实验数据。
实验四:数值计算与优化数值计算与优化是Matlab的核心功能之一。
在这个实验中,我使用Matlab进行了一组数值计算和优化实验。
通过使用Matlab的数值计算函数和优化工具箱,我能够快速计算出复杂的数学问题,并找到最优解。
同时,在进行优化实验时,我可以设置各种约束条件和目标函数,从而得到最优解的参数值。
这些数值计算和优化工具极大地提高了我的研究效率和准确度。
结论:通过这些实验,我深刻认识到Matlab的强大功能和广泛应用领域。
无论是图像处理、信号处理、数据分析还是数值计算与优化,Matlab都提供了丰富的函数和工具,让我们能够快速高效地完成实验和研究工作。
实验八:概率论与数理统计的MATLAB 实现实验目的与要求:能运用MATLAB 提供的针对概率统计课程的工具箱。
实验内容:1、用normpdf函数计算正态概率密度函数。
该函数的调用格式为:Y=normpdf(X,MU,SIGMA)2、用normpdf函数计算正态分布的分布函数。
该函数的调用格式为:F=normcdf(X,MU,SIGMA)3、用chi2inv函数计算卡方分布的分布函数的逆函数。
分布函数的逆函数及其调用格式:x=chi2inv(P,v)4、随机取8只活塞环,测得他们直径为(以mm计):74.001 74.005 74.003 74.001 74.000 73.998 74.006 74.002。
设环直径的测量值服从正态分布,现估计总体的方差2程序代码:x=[74.001 74.005 74.003 74.001 74.000 73.998 74.006 74.002];p=mle('norm',x);sigma2hatmle=p(2)^25、从一批灯泡中随机的取5只做寿命试验,测得寿命(以小时计)为:1050 1100 1120 1250 1280设灯泡寿命服从正态分布,求灯泡寿命平均值的95%置信区间。
程序代码:x=[1050 1100 1120 1250 1280];[p,ci]=mle('norm',x,0.05)6、下面列出的是某工厂随机选取的20只部件的装配时间(分):9.8 10.4 10.6 9.6 9.7 9.9 10.9 11.1 9.6 10.210.3 9.6 9.9 11.2 10.6 9.8 10.5 10.1 10.5 9.7设装配时间的总体服从正态分布,标准差为0.4,是否可以认为装配时间的均值在0.05的水平上不小于10.0H :10<μ vs 1H :10≥μ程序:%正态总体的方差已知时的均值检验x1=[9.8 10.4 10.6 9.6 9.7 9.9 10.9 11.1 9.6 10.2]; x2=[10.3 9.6 9.9 11.2 10.6 9.8 10.5 10.1 10.5 9.7]; x=[x1 x2]';m=10;sigma=0.4;a=0.05;[h,sig,muci]=ztest(x,m,sigma,a,1)因此,在0.05的水平下,可以认为装配时间的均值不小于10。
7、某种电子元件的寿命x (以小时计)服从正态分布,2δμ和均未知。
现测得16只元件的寿命如下:159 280 101 212 224 379 179 264 222 362 168 250 149 260 485 170 问是否有理由认为元件的平均寿命大于225(小时)?0H :225≤μ vs 1H :225>μ程序:%正态总体的方差求知时的均值检验x=[159 280 101 212 224 379 179 264 222 362 168 250 149 260 485 170]; m=225;a=0.05;[h,sig,muci]=ttest(x,m,a,1)由于sig=0.257,因此没有充分的理由认为元件的平均寿命大于225小时。
而对于0H :225≥μ vs 1H :225<μ程序:%正态总体的方差求知时的均值检验x=[159 280 101 212 224 379 179 264 222 362 168 250 149 260 485 170]; m=225;a=0.05;[h,sig,muci]=ttest(x,m,a,-1)由于sig=0.743,因此更没有充分的理由认为元件的平均寿命小于225小时。
8、在平炉上进行一项实验以确定改变操作方法的建议是否会增加钢的得率,实验是在同一平炉上进行的。
每练一炉钢,除操作方法外,其他条件都尽可能做到相同。
先用标准方法练一炉,然后用建议的新方法练一炉,以后交替进行,各练10炉,其钢的得率分别为: 标准方法 78.1 72.4 76.2 74.3 77.4 78.4 76.0 75.5 76.7 77.3 新方法 79.1 81.0 77.3 79.1 80.0 79.1 79.1 77.3 80.2 82.1设这两个样本相互独立,且分别来自正态总体,均值和方差都未知。
问建议的新操作方法是否能提高钢的得率? (1)建立假设H0:1μ=2μ H1:1μ<2μX=[78.1 72.4 76.2 74.3 77.4 78.4 76.0 75.5 76.7 77.3]; Y=[79.1 81.0 77.3 79.1 80.0 79.1 79.1 77.3 80.2 82.1]; [h,sig,ci]=ttest2(X,Y ,0.05,-1)结果h = 1,表明在05.0=α的显著水平下,可以拒绝原假设,即认为建议的新操作方法较原方法优。
9、下面列出了84个伊特拉斯坎人男子的头颅的最大宽度(mm ),试检验这些数据是否处于正态分布。
141 148 132 138 154 142 150 146 155 158 150 140 147 148 144 150 149 145 149 158 143 141 144 144 126 140 144 142 141 140 145 135 147 146 141 136 140 146 142 137 148 154 137 139 143 140 131 143 141 149 148 135 148 152 143 144 141 143 147 146 150 132 142 142 143 153 149 146 149 138 142 149 142 137 134 144 146 147 140 142 140 137 152 145x1=[141 148 132 138 154 142 150 146 155 158];x2=[150 140 147 148 144 150 149 145 149 158];x3=[143 141 144 144 126 140 144 142 141 140];x4=[145 135 147 146 141 136 140 146 142 137];x5=[148 154 137 139 143 140 131 143 141 149];x6=[148 135 148 152 143 144 141 143 147 146];x7=[150 132 142 142 143 153 149 146 149 138];x8=[142 149 142 137 134 144 146 147 140 142];x9=[140 137 152 145];x=[x1 x2 x3 x4 x5 x6 x7 x8 x9];[H,P,JBSTAT,CV]=jbtest(x)由于P=0.7610,因此有充分理由认为上述数据是来自正态总体。
10、一位经济学家对生产电子计算机设备的企业收集了在一年内生产力提高指数(用0到100内的数表示)并按过去三年间在科研和开发上的平均花费分为三类:A1:花费少,A2:花费中等,A3花费多。
生产力提高的指数如下表所示:水平生产力指数提高A1 7.6 8.2 6.8 5.8 6.9 6.6 6.3 7.7 6A2 6.7 8.1 9.4 8.6 7.8 7.7 8.9 7.9 8.3 8.7 7.1 8.4A3 8.5 9.7 10.17.8 9.6 9.5请列出方差分析表,并进行多重比较。
y1=[7.6 8.2 6.8 5.8 6.9 6.6 6.3 7.7 6.0];y2=[6.7 8.1 9.4 8.6 7.8 7.7 8.9 7.9 8.3 8.7 7.1 8.4];y3=[8.5 9.7 10.1 7.8 9.6 9.5];y=[y1 y2 y3];A1=ones(numel(y1),1);A2=2*ones(numel(y2),1);A3=3*ones(numel(y3),1);A=[A1;A2;A3];[p,table,stats]=anova1(y,A)p =4.3307e-005table ='Source' 'SS' 'df' 'MS' 'F' 'Prob>F''Groups' [20.1252] [ 2] [10.0626] [15.7205] [4.3307e-005]'Error' [15.3622] [24] [ 0.6401] [] []'Total' [35.4874] [26] [] [] []stats =gnames: {3x1 cell}n: [9 12 6]source: 'anova1'means: [6.8778 8.1333 9.2000]df: 24s: 0.8001>> B=multcompare(stats,0.05)B =1.00002.0000 -2.1366 -1.2556 -0.37451.0000 3.0000 -3.3752 -2.3222 -1.26922.00003.0000 -2.0657 -1.0667 -0.0677ans =由multcompare函数知,第1,、2列标志水平,第四列表示均值的估计,第三列和第五列表示μi—μj置信区间。
第一类与第二,三类有差异,第二类和第三类没有显著差异。