数学软件MATLAB实验报告 实验八

合集下载

matlab实验报告总结精选

matlab实验报告总结精选

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

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

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

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

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

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

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

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

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

高等数学:MATLAB实验

高等数学:MATLAB实验
以上两种格式中的x、y都可以是表达式.plot是绘制二维 曲线的基本函数,但在使用 此函数之前,需先定义曲线上每一 点的x及y的坐标.
MATLAB实验
2.fplot绘图命令 fplot绘图命令专门用于绘制一元函数曲线,格式为:
fplot('fun',[a,b]) 用于绘制区间[a,b]上的函数y=fun的图像.
MATLAB实验 【实验内容】
MATLAB实验
由此可知,函数在点x=3处的二阶导数为6,所以f(3)=3为 极小值;函数在点x= 1处的二阶导数为-6,所以f(1)=7为极大值.
MATLAB实验
例12-10 假设某种商品的需求量q 是单价p(单位:元)的函 数q=12000-80p,商 品的总成本C 是需求量q 的函数 C=25000+50q.每单位商品需要纳税2元,试求使销售 利润达 到最大的商品单价和最大利润额.
MATLAB实验
MATLAB实验
MATLAB实验
MATLAB实验
MATLAB实验
MATLAB实验
MATLAB实验
MATLAB实验
MATLAB实验 实验九 用 MATLAB求解二重积分
【实验目的】 熟悉LAB中的int命令,会用int命令求解简单的二重积分.
MATLAB实验
【实验M步A骤T】 由于二重积分可以化成二次积分来进行计算,因此只要
MATLAB实验
MATLAB实验
MATLAB实验
MATLAB实验
MATLAB实验
实验七 应用 MATLAB绘制三维曲线图
【实验目的】 (1)熟悉 MATLAB软件的绘图功能; (2)熟悉常见空间曲线的作图方法.
【实验要求】 (1)掌握 MATLAB中绘图命令plot3和 mesh的使用; (2)会用plot3和 mesh函数绘制出某区间的三维曲线,线型

matlab实验报告模板

matlab实验报告模板

《高等数学》实验报告(二)实验项目名称:多元函数积分学分组第八组组员姓名学号专业班级实验软件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实验报告

MATLAB实验报告

实验一、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在信号处理和系统建模方面也有广泛的应用。

在本实验中,我学习了Matlab的信号处理工具箱和系统建模工具。

MATLAB实验报告(8个实验)

MATLAB实验报告(8个实验)

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

MATLAB实验报告(8个实验)

MATLAB实验报告(8个实验)

MATLAB实验报告(8个实验)四川师范⼤学MATLAB语⾔实验报告1系级班年⽉⽇实验名称:Intro, Expressions, Commands姓名学号指导教师成绩1ObjectiveThe objective of this lab is to familiarize you with the MATLAB program development environment and to develop your first programs in this environment.2Using MATLAB2.1Starting MATLABLogon to your computer and start MATLAB by double-clicking on the icon on the desktop or by using the Start Programs menu. MATLAB Desktop window will appear on the screen.The desktop consists of several sub-windows. The most important ones are:●Command Window (on the right side of the Desktop) is used to do calculations,enter variables and run built-in and your own functions.●Workspace (on the upper left side) consists of the set of variables (arrays) createdduring the current MATLAB session and stored in memory.●Command History (on the lower left side) logs commands entered in theCommand Window. You can use this window to view previously run statements, and copy and execute selected statements.You can switch between the Launch Pad window and the Workspace window using the menu tabs under the sub-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 。

MATLAB数学实验报告

MATLAB数学实验报告

数学实验报告一、实验目的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处的值为零。

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

实验八:概率论与数理统计的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置信区间。

第一类与第二,三类有差异,第二类和第三类没有显著差异。

相关文档
最新文档