Matlab快速入门.docx_第1页
Matlab快速入门.docx_第2页
Matlab快速入门.docx_第3页
Matlab快速入门.docx_第4页
Matlab快速入门.docx_第5页
已阅读5页,还剩7页未读, 继续免费阅读

下载本文档

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

文档简介

Matlab在科研中的应用浙江大学控制系2013年11月10日目 录IntroductionCurrent Directory BrowserEditor/DebuggerMatrices and Magic SquaresEntering MatricesYou 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.A = 16 3 2 13; 5 10 11 8; 9 6 7 12; 4 15 14 1MATLAB displays the matrix you just entered.A =16 3 2 135 10 11 89 6 7 124 15 14 1sum, transpose, and diagsum(A)MATLAB replies withans =34 34 34 34Aans =16 5 9 43 10 6 152 11 7 1413 8 12 1sum(A)produces a column vector containing the row sumsans =34343434diag(A) %找对角线上的元素ans =161071sum(diag(A)ans =34fliplr(A) %左右翻转sum(diag(fliplr(A)ans =34A(1,4) + A(2,4) + A(3,4) + A(4,4)This producesans =34The Colon Operator %冒号操作符1:101 2 3 4 5 6 7 8 9 10To obtain nonunit spacing, specify an increment. For example,100:-7:50is100 93 86 79 72 65 58 51and0:pi/4:piis0 0.7854 1.5708 2.3562 3.1416A(1:k,j)is the first k elements of the jth column of A.sum(A(1:4,4)computes the sum of the fourth column.sum(A(:,end)sum(1:16)/4which, of course, isans =34The magic FunctionB = magic(4)B =16 2 3 135 11 10 89 7 6 124 14 15 1A = B(:,1 3 2 4) %每一行 与B相应的列对应A =16 3 2 135 10 11 89 6 7 124 15 14 1ExpressionsLike most other programming languages, MATLAB provides mathematicalexpressions, but unlike most programming languages, these expressionsinvolve entire matrices. The building blocks of expressions are:VariablesNumbersOperatorsFunctionsOperatorsExpressions use familiar arithmetic operators and precedence rules.+ Addition- Subtraction* Multiplication/ Division Left division (described in “Matrices and LinearAlgebra” in Using MATLAB) Power Complex conjugate transpose( ) Specify evaluation orderSeveral special functions provide values of useful constants.pi 3.14159265i Imaginary unit, -1j Same as ieps Floating-point relative precision, 2-52realmin Smallest floating-point number, 2-1022realmax Largest floating-point number, (2-e)21023Inf InfinityNaN Not-a-numbereps = 1.e-6clear epsWorking with MatricesGenerating Matriceszeros All zerosones All onesrand Uniformly distributed random elementsrandn Normally distributed random elementsZ = zeros(2,4)Z =0 0 0 00 0 0 0F = 5*ones(3,3)F =5 5 55 5 55 5 5N = fix(10*rand(1,10)N =4 9 4 4 8 5 2 6 8 0R = randn(4,4)R =1.0668 0.2944 -0.6918 -1.44100.0593 -1.3362 0.8580 0.5711-0.0956 0.7143 1.2540 -0.3999-0.8323 1.6236 -1.5937 0.6900The load Command16.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.0Store the file under the name magik.dat. Then the commandload magik.datAn easy way to read data into MATLAB in many text or binary formats is touse Import Wizard.M-FilesFor example, create a file containing these five lines.A = .16.0 3.0 2.0 13.05.0 10.0 11.0 8.09.0 6.0 7.0 12.04.0

温馨提示

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

评论

0/150

提交评论