数学建模培训讲稿.doc_第1页
数学建模培训讲稿.doc_第2页
数学建模培训讲稿.doc_第3页
数学建模培训讲稿.doc_第4页
数学建模培训讲稿.doc_第5页
已阅读5页,还剩76页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

Matlab在教学中的应用 IntroductionMatlab & Simulink应用领域技术计算数学计算、分析、可视化和算法开发控制系统设计控制系统基于模型的设计,包括嵌入式系统仿真、快速原型及代码生成等数字信号处理分析信号,开发算法和设计数字信号处理系统通信系统设计和仿真复杂通信系统图像处理图像采集、分析、可视化和算法开发测试和测量测试和测量应用中硬件连接性和数据分析计算生物学生物数据和系统的分析、可视化与仿真计算金融金融建模、分析及应用程序开发 产品概览MATLABThe MATLAB product family provides a high-level programming language, an interactive technical computing environment, and functions for:Algorithm developmentData analysis and visualizationNumeric computationMATLAB serves as the foundation for all other MathWorks products.Products for Math and Optimizationl Optimization ToolboxSolve standard and large-scale optimization problemsl Symbolic Math ToolboxPerform mathematics using symbolic computation and variable-precision arithmeticl Partial Differential Equation ToolboxSolve partial differential equations using finite element methodsl Global Optimization ToolboxSolve multiple maxima, multiple minima, and nonsmooth optimization problemsProducts for Statistics and Data Analysisl Statistics ToolboxPerform statistical analysis, modeling, and algorithm developmentl Neural Network ToolboxDesign and simulate neural networksl Curve Fitting ToolboxFit curves and surfaces to data using regression, interpolation, and smoothingl Spline ToolboxCreate and manipulate spline approximation models of datal Model-Based Calibration ToolboxCalibrate complex powertrain systems 复杂的动力总成系统校准l Bioinformatics ToolboxRead, analyze, and visualize genomic, proteomic, and microarray datal System Identification ToolboxCreate linear and nonlinear dynamic models from measured input-output dataProducts for Database Connectivity and Reportingl Database ToolboxExchange data with relational databasesl MATLAB Report GeneratorGenerate documentation for MATLAB applications and dataProducts for Application Deploymentl MATLAB CompilerBuild standalone executables and software components from MATLAB codel Spreadsheet Link EXUse MATLAB from Microsoft Excell MATLAB Builder EXDeploy MATLAB code as Microsoft Excel add-insl MATLAB Builder NE Deploy MATLAB code as .NET and COM componentsl MATLAB Builder JA Deploy MATLAB code as Java classes课堂资源查找课程资料、视频、代码、模型、书籍以及更多课堂教学资源的链接。通过科系或主题轻松找到资源。查找课程资料、视频、代码、模型、书籍以及更多课堂教学资源的链接。通过科系或主题轻松找到资源。互动视频教程通过在课程学习中推荐一个或多个免费教程,帮助学生入门并熟练使用 MATLAB和 Simulink: MATLABSimulink信号处理 (新)控制系统 (新)Matlab桌面命令窗口 Command Window 命令窗口是命令行语句和命令文件执行的主要窗口。 在命令窗口中直接输入命令或MATLAB函数,系统自动反馈结果。历史命令窗口Command History历史命令窗口中显示已执行过的命令,用户可以根据需要设置命令的多少,单击窗口的右上角的箭号会独立显示该窗口,在该窗口的某一命令上单击鼠标右键会弹出菜单。当前目录Current Directory当前目录浏览器Current Directory Browser工作空间浏览器Workspace Browser工作空间窗口是MATLAB的一个变量管理中心,可以显示变量的名称、尺寸、字节和类别等信息,同时用不同的图标表示矩阵、字符数组、元胞数组、构架数组等变量类型。Matlab中有趣的演示实例Matlab中有许多有意思的实例,特举部分实例以供参考.观看演示的方法1. 单击Matlab命令窗口左下角的Start按钮2. 从弹出的菜单中选择Demos命令F&Q或直接在Matlab窗口中输入Demos3. 单击相应的选项进入不同的演示.graf2d:XY平面绘图(火柴棒)graf2d2:XYZ立体绘图(切片)lorenz:Lorenz吸引子动画演示bibes:L形薄膜振动life:生命发展游戏xpbombs:仿windows系统的扫雷游戏travel:旅行商问题动画演示bandem:香蕉最优化展示graf2d graf2d2 ? Error: The input character is not valid in MATLAB statements or expressions.在命令窗口中演示会出现: View the published version of this demo to learn more about graf2d2.mlorenz Matrices and Arrays 矩阵和数组Matrices and Magic SquaresAbout Matricesload durer whos Name Size Bytes Class Attributes X 648x509 2638656 double caption 2x28 112 char map 128x3 3072 double image(X)colormap(map)axis image load detailimage(X)colormap(map)axis imageaxis off Entering Matrices& You can enter matrices into MATLAB in several different ways: Enter an explicit list of elements. 直接输入矩阵的各个元素 Load matrices from external data files. 从外部数据文件中调用矩阵 Generate matrices using built-in functions. 用内部函数命令生成矩阵 Create matrices with your own functions in M-files. 自建一个M-文件生成矩阵 A = 16 3 2 13; 5 10 11 8; 9 6 7 12; 4 15 14 1 A = 16 3 2 13 5 10 11 8 9 6 7 12 4 15 14 1 Start by entering Drers matrix as a list of its elements. You only have to follow a few basic conventions: Separate the elements of a row with blanks or commas. Use a semicolon, ; , to indicate the end of each row. Surround the entire list of elements with square brackets, . Column separator: , or space 列分隔符: , 或空格 Row separator: ; or enter 行分隔符: ; 或 回车符sum, tranpose, and diagsum(A) ans = 34 34 34 34 sum(A) ans = 34 34 34 34 sum(diag(A) ans = 34 flipud(A) ans = 4 15 14 1 9 6 7 12 5 10 11 8 16 3 2 13 sum(diag(flipud(A) ans = 34 for k=0:4rot90(A,k)rot90(A,k)end ans = 16 3 2 13 5 10 11 8 9 6 7 12 4 15 14 1ans = 16 5 9 4 3 10 6 15 2 11 7 14 13 8 12 1ans = 13 8 12 1 2 11 7 14 3 10 6 15 16 5 9 4ans = 4 15 14 1 9 6 7 12 5 10 11 8 16 3 2 13ans = 1 14 15 4 12 7 6 9 8 11 10 5 13 2 3 16ans = 1 12 8 13 14 7 11 2 15 6 10 3 4 9 5 16ans = 4 9 5 16 15 6 10 3 14 7 11 2 1 12 8 13ans = 13 2 3 16 8 11 10 5 12 7 6 9 1 14 15 4ans = 16 3 2 13 5 10 11 8 9 6 7 12 4 15 14 1ans = 16 5 9 4 3 10 6 15 2 11 7 14 13 8 12 1 SubscriptA=magic(4) A = 16 2 3 13 5 11 10 8 9 7 6 12 4 14 15 1 A(1,4) + A(2,4) + A(3,4) + A(4,4) ans = 34 t = A(4,5) ? Index exceeds matrix dimensions. X = A;X(4,5) = 17 X = 16 3 2 13 0 5 10 11 8 0 9 6 7 12 0 4 15 14 1 17 t = X(4,5) t = 17 The Colon Operationx=a:dx:bx=linspace(a,b,n)生成的结果为行向量,通过命令x=x 变为列向量x=0:2:6 x = 0 2 4 6 x=linspace(0,6,4) x = 0 2 4 6 x 1:10 ans = 1 2 3 4 5 6 7 8 9 10 100:-7:50 ans = 100 93 86 79 72 65 58 510:pi/4:pi ans = 0 0.7854 1.5708 2.3562 3.1416 t=0:5:100 t = Columns 1 through 12 0 5 10 15 20 25 30 35 40 45 50 55 Columns 13 through 21 60 65 70 75 80 85 90 95 100t=0:5:100; 分号的作用是抑制结果的显示. To surpress the command line output when the vector t is createdSubscript expressions involving colons refer to portions of a matrix:A(1:k,j)is the first k elements of the jth column of A.sum(A(1:4,4) ans = 34 sum(A(:,end) ans = 34 Why is the magic sum equal to 34?sum(1:16) ans = 136 sum(1:16)/4 ans = 34 The colon operation can be used to created an evenly spaced vector, and to index multiple values in an array. 冒号操作可用于创建均匀分布的向量, 用于数组中多个值的寻访.The magic FunctionB = magic(4) B = 16 2 3 13 5 11 10 8 9 7 6 12 4 14 15 1 A = B(:,1 3 2 4) A = 16 3 2 13 5 10 11 8 9 6 7 12 4 15 14 1 ExpressionsVariablesMatlab variables are data containers . Matlab变量是数据容器All variables are arrays 所有的变量都是数组Variables come in different sizes 变量有不同的维数 Variables come in differert types : double, single, cell, structure, 变量有不同的类型 :双精度型, 单精度型, 元胞, 架构等用赋值语句创建变量n=6.02e23 n = 6.0200e+023 上述语句中,n为变量名(Variable Name), 6.02e23为变量值(Value), =为赋值运算符(Assign Operator)MATLAB中变量的命名规则是:1)变量名必须是不含空格的单个词;2)变量名区分大小写;3)变量名必须以字母打头,之后可以是任意字母、数字或下划线,变量名中不允许使用标点符号。4) 尽管变量名的长度可以是任意的, 但Matlab只能有效识别前N个字符, N是函数 namelengthmax的返回值.Although variable names can be of any length, MATLAB uses only the firstN characters of the name, (where N is the number returned by the functionnamelengthmax), and ignores the rest.N = namelengthmax N = 63 Numbers数据类型包括数值型、字符串型、元胞型、构架型等。数值型有单精度型、双精度型和整数型。整数型有uint8,uint16,uint32和uint64等无符号型和int8,int16,int32和int64等符号型整数。数值型数据可以用带小数点的形式和科学计数法表示,数值的表示范围是10-30810+308。 科学记数法用e及后面的数字表示10的相应幂次. 在输出时有多种数值显示格式可供选择。 theta=pi/2 theta = 1.5708 一般在计算时采用双精度型,其精度约为16位有效数字, 一般显示时只 以小数点后四位的精度显示,若结果的有效数字不在这一范围,以科学记数法显示数据显示格式可通过命令format、vpa等改变。显示格式的改变不会影响数据的实际值,所以不会影响计算精度。OperatorsExpressions use familiar arithmetic operators and precedence rules.+Addition 加法-Subtraction 减法* Multiplication乘法/Division 除法Left division 左除power 乘幂Complex conjugate transpose 复数共轭转置( )Specify evaluation order 指定运算次序format longtheta theta = 1.570796326794897 format short y=2+i*sin(theta) y = 2.0000 + 1.0000i Once created, the name of a variable is used as a tag, allowing access and manipulation of the data assigned to it. 变量一旦建立, 变量名可用作标签, 允许对赋给它的数据进行访问及运算.Accessing Data in Matlab 数据访问MATLAB命令窗口中用户变量名可用who或whos 查寻。who Your variables are:n rho t theta x y whos Name Size Bytes Class Attributes n 1x1 8 double rho 1x1 16 double complex t 1x1 8 double theta 1x1 8 double x 1x1 8 double y 1x1 16 double complex Variable Editor 变量编辑双击Workspace窗口中的变量名,打开变量编辑器(Variable Editor ). Locating data in Matlab 数据定位以上信息也从工作间浏览器(Workspace Browser)观察到。变量的值可以通过键入变量名得到。FunctionSeveral special functions provide values of useful constants.特殊变量取 值ans用于结果的缺省变量名pi圆周率3.14159265.epsFloating-point relative precision, 浮点的相对精度flops浮点运算数infInfinity 无穷大,如1/0NaN Not-a-number,如0/0i,jImaginary unit,i=j=虚数单位nargin函数输入变量数目nargout函数输出变量数目realmin Smallest floating-point number, 最小可用正实数realmaxLargest floating-point number最大可用正实数eps = 1.e-6 eps = 1.0000e-006 eps eps = 1.0000e-006 clear eps eps ans = 2.2204e-016 doc 打开了help窗口, 依次点击MatlabFunction-By CategoryMathematicsElementary Math 出现函数索引再在右栏窗口选择Exponential 可找到函数exp和sqrt的简单介绍.通过函数索引,可查阅到同类其他函数,如点击nthroot, 可得到如下介绍.nthroot Real nth root of real numbers Syntax y = nthroot(X, n)Descriptiony = nthroot(X, n) returns the real nth root of the elements of X. Both X and n must be real and n must be a scalar. If X has negative entries, n must be an odd integer.Examplenthroot(-2, 3) ans = -1.2599 returns the real cube root of -2.By comparison, (-2)(1/3) ans = 0.6300 + 1.0911i returns a complex cube root of -2.输入 help elfun 会出现什么结果输入 help elfun输入 help elmatExamples of Expressions for rho=(1+sqrt(5-i)/2 rho = 1.6236 - 0.1113i z=exp(rho) z = 5.0397 - 0.5630i t=2t = 0.2000 x=sin(3*t+pi/2) x = 0.8253 Working with MatricesGenerating Matrices特殊 矩阵的建立zeros(m,n)All zeros. 产生一个m行、n列的零矩阵;ones(m,n) All ones. 产生一个m行、n列的元素全为1的矩阵;eye(m,n) Identity matrices 产生一个m行、n列的单位矩阵randUniformly distributed random elements 均匀分布的随机数randnNormally distributed random elements 正态分布的随机数ones(3) % 产生3阶全1矩阵ans = 1 1 1 1 1 1 1 1 1 5*ones(3) ans = 5 5 5 5 5 5 5 5 5 zeros(2,4) ans = 0 0 0 0 0 0 0 0 I=eye(3) I = 1 0 0 0 1 0 0 0 1 N = fix(10*rand(1,10) N = 8 9 1 9 6 0 2 5 9 9 R = randn(4,4) R = -0.4326 -1.1465 0.3273 -0.5883 -1.6656 1.1909 0.1746 2.1832 0.1253 1.1892 -0.1867 -0.1364 0.2877 -0.0376 0.7258 0.1139 The load Function通过load命令或选择菜单FileImport Data命令加载MAT数据文件来创建矩阵。The load function reads binary files containing matrices generated by earlier MATLAB sessions, or reads text files containing numeric data.For example l outside of MATLAB, create a text file containing these four lines:16.0 3.0 2.0 13.05.0 10.0 11.0 8.09.0 6.0 7.0 12.04.0 15.0 14.0 1.0l Save the file as magik.txt in the current directory. The statementload magik.txt reads the file and creates a variable, magik, containing the example matrix.magik magik = 16 3 2 13 5 10 11 8 9 6 7 12 4 15 14 1 An easy way to read data into MATLAB from many text or binary formats is to use the Import Wizard. 过程如下: FileImport Data选择文件名magik.txtNextFinishM-Files建立一个文件名为magik.m的M-文件, 文件的内容如下:A = 16.0 3.0 2.0 13.05.0 10.0 11.0 8.09.0 6.0 7.0 12.04.0 15.0 14.0 1.0 ;保存后在命令窗口运行magik A A = 16 3 2 13 5 10 11 8 9 6 7 12 4 15 14 1 ConcatenationB = A A+32; A+48 A+16 B = 16 3 2 13 48 35 34 45 5 10 11 8 37 42 43 40 9 6 7 12 41 38 39 44 4 15 14 1 36 47 46 33 64 51 50 61 32 19 18 29 53 58 59 56 21 26 27 24 57 54 55 60 25 22 23 28 52 63 62 49 20 31 30 17 sum(B) ans = 260 260 260 260 260 260 260 260 sum(B,2) ans = 196 196 196 196 324 324 324 324 Deleting Row and ColumnsX = A; X(:,2) = X = 16 2 13 5 11 8 9 7 12 4 14 1 X(1,2) = ? Subscripted assignment dimension mismatch. X(2:2:10) = X = 16 9 2 7 13 12 1 More about Matrices and ArraysLinear AlgebraA=magic(4) A = 16 2 3 13 5 11 10 8 9 7 6 12 4 14 15 1 A+A ans = 32 7 12 17 7 22 17 22 12 17 12 27 17 22 27 2 A*A ans = 378 206 212 360 206 370 368 212 212 368 370 206 360 212 206 378 d=det(A) d = 0 The determinant of this particular matrix happens to be zero, indicating that the matrix is singular:R=rref(A) R = 1 0 0 1 0 1 0 3 0 0 1 -3 0 0 0 0 Because the matrix is singular, it does not have an inverse.X=inv(A) Warning: Matrix is close to singular or badly scaled. Results may be inaccurate. RCOND = 1.306145e-017.X = 1.0e+014 * 0.9382 2.8147 -2.8147 -0.9382 2.8147 8.4442 -8.4442 -2.8147 -2.8147 -8.4442 8.4442 2.8147 -0.9382 -2.8147 2.8147 0.9382 e = eig(A) e = 34.0000 8.9443 -8.9443 0.0000 v = ones(4,1) v = 1 1 1 1 A*v ans = 34 34 34 34 P = A/34 P = 0.4706 0.0588 0.0882 0.3824 0.1471 0.3235 0.2941 0.2353 0.2647 0.2059 0.1765 0.3529 0.1176 0.4118 0.4412 0.0294 sum(P) ans = 1 1 1 1 sum(P,2) ans = 1 1 1 1P5 ans = 0.2511 0.2491 0.2492 0.2506 0.2495 0.2504 0.2502 0.2499 0.2501 0.2498 0.2496 0.2505 0.2494 0.2508 0.2509 0.2489 poly(A) ans = 1.0e+003 * 0.0010 -0.0340 -0.0800 2.7200 -0.0000 int8(poly(A) ans = 1 -34 -80 127 0 polyA=poly(sym(magic(4) polyA =x4-34*x3-80*x2+2720*x Arrays数组运算+Addition 加法-Subtraction 减法.* Element-by-element multiplication 点乘运算./Element-by-element division 点除运算.Element-by-element left division 点左除运算.Element-by-element power 点乘幂运算.Unconjugated array transpose 非共轭转置Building TablesArray operations are useful for building tables. Suppose n is the column vectorn=(0:9); pows = n n.2 2.n pows = 0 0 1 1 1 2 2 4 4 3 9 8 4 16 16 5 25 32 6 36 64 7 49 128 8 64 256 9 81 512 The elementary math functions operate on arrays element by element.format short gx = (1:0.1:2);logs = x log10(x) logs = 1 0 1.1 0.041393 1.2 0.079181 1.3 0.11394 1.4 0

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论