Lecture 13:Matlab简介(二) 张伟平 Monday 7th December,2009
Lecture 13: Matlab {0() ‹ï² Monday 7th December, 2009
Contents 1 Programming ) 1.1Mfle...................。......... 1.1.1 Program Control Statements............. 2 1.1.2M-File Functions........·.···.····· 13 l.2 anonymous functions··+.······.·········· 18 2 Computational statistics with Matlab 21 2.1 Functions on Probability and Statistics.·..········ 21 2.1.1 Probability distribution ............... 21 2.1.2 Descriptive statistics..................23 2.1.3 Statistical plotting................... 24 21.4 Linear model...·.······· 24 2.l.5 Multivariate Statistics··.··.·····.···· 26 2.2 Monte Carlo with Matlab...·....·..··.····· 28 2.2.1 Monte Carlo Assessment of Hypothesis Testing··· 28 2.2.2 MCMC with matlab.················· 31 Previous Next First Last Back Forward 2
Contents 1 Programming 1 1.1 M file . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 1.1.1 Program Control Statements . . . . . . . . . . . . . 2 1.1.2 M-File Functions . . . . . . . . . . . . . . . . . . . . 13 1.2 anonymous functions . . . . . . . . . . . . . . . . . . . . . . 18 2 Computational statistics with Matlab 21 2.1 Functions on Probability and Statistics . . . . . . . . . . . . 21 2.1.1 Probability distribution . . . . . . . . . . . . . . . . 21 2.1.2 Descriptive statistics . . . . . . . . . . . . . . . . . . 23 2.1.3 Statistical plotting . . . . . . . . . . . . . . . . . . . 24 2.1.4 Linear model . . . . . . . . . . . . . . . . . . . . . . 24 2.1.5 Multivariate Statistics . . . . . . . . . . . . . . . . . 26 2.2 Monte Carlo with Matlab . . . . . . . . . . . . . . . . . . . 28 2.2.1 Monte Carlo Assessment of Hypothesis Testing . . . 28 2.2.2 MCMC with matlab . . . . . . . . . . . . . . . . . . 31 Previous Next First Last Back Forward 2
3 Symbolic computation with matlab 37 3.1 Creating Symbolic Variables and Expressions········ 37 3.2 Calculus..···.·.·.··..·....·..·.···39 4 Optimization 42 4.1 Unconstrained Minimization Example.....·...·.·42 4.2 Nonlinear Inequality Constrained Example..........43 Previous Next First Last Back Forward 1
3 Symbolic computation with matlab 37 3.1 Creating Symbolic Variables and Expressions . . . . . . . . 37 3.2 Calculus . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39 4 Optimization 42 4.1 Unconstrained Minimization Example . . . . . . . . . . . . 42 4.2 Nonlinear Inequality Constrained Example . . . . . . . . . . 43 Previous Next First Last Back Forward 1
Chapter 1 Programming Matlab有两种命令执行方式:一种就是在命令窗口进行交互式命令执行.用 户输入一个命令,Matlab解释执行一个命令.这种方式在有些场合(比如需要 循环)是不方便的:另一种执行方式就是M文件执行方式.用户将所有命令放在 一个文件里(称为M文件,以.m为扩展名),matlab执行该文件里所有命令直至 结束 1.1 M file 用matlab语言编写的程序称为M文件.它是由若千个matlab命令构成的,用以 实现某些操作或者某个算法.M文件有两类,一类称为命令文件(Script file), 类称为函数文件(Function file).它们的扩展名都为.m.区别在于 Previous Next First Last Back Forward 1
Chapter 1 Programming Matlab k¸´·-â1ê™: ò´“¥3·-Iù?1p™·-â1. ^ r—\òá·-, Matlab)º â1òá·-. ˘´ê™3k |‹('XIá ÃÇ)¥ÿêB; ,ò´â1ꙓ¥M©áâ1ê™. ^rÚ§k·-ò3 òá©áp(°èM©á, ±.mè*–¶), matlabâ1T©áp§k·-Üñ (Â. 1.1 M file ^matlabäÛ?ßS°èM©á. ߥdeZámatlab·-§, ^± ¢y, ˆä½ˆ, áé{. M©ák¸a, òa°è·-©á(Script file), òa°èºÍ©á(Function file). ßÇ*–¶—è.m. ´O3u Previous Next First Last Back Forward 1
一命令文件没有输入参数,也不返回输出参数:函数文件可以有输入参数, 也可以有返回输出参数: 命令文件可以在命令窗口里输入该文件名称,即可运行里面的命令:函 数文件则不行,须以函数调用的方式来调用此函数 命令文件对工作空间里的变量直接操作,结果也完全返回到工作空间里。 而函数文件里定义的变量为局部变量,函数执行完毕后就被清除 1.1.1 Program Control Statements 程序的控制分为下面几种: 音顺序结构 顺序结构是最简单的程序结构,程序中的语句将按照顺序依次执行,直至最 后一个语句.一般涉及到数据的输入,数据的计算,数据的输出 input输入语句语法结构 TCode Previous Next First Last Back Forward 2
➢ ·-©ávk—\ÎÍ, èÿࣗ—ÎÍ; ºÍ©áå±k—\ÎÍ, èå±kࣗ—ÎÍ. ➢ ·-©áå±3·-Iùp—\T©á¶°, =å$1p°·-; º Í ©áKÿ1, L±ºÍN^ê™5N^dºÍ. ➢ ·-©áÈÛäòmpC˛Üˆä, (Jèà£Ûäòmp. ºÍ©áp½¬C˛è¤‹C˛, ºÍâ1.“òÿ. 1.1.1 Program Control Statements ßSõõ©èe°A´µ ✿ ^S( ^S(¥Å{¸ßS(, ßS•äÈÚUÏ^Sùgâ1, ÜñÅ òáäÈ. òÑ 9Í‚—\, Í‚Oé, Í‚——. input —\äÈ ä{( ↑Code Previous Next First Last Back Forward 2