Matlab tutorial slides

      4
Josh Xiaomin Josh Xiaomin Xi Xi PhD Candidate PhD Candidate Feb 27, 2013 Feb 27, 2013 A tutorial from A tutorial from INFORMS OSU Josh Xiaomin XiA Matlab Tutorial 2 / INF Overview Overview  Introduction  Installation (Toolboxes)  Layout of Matlab Windows  Basics of Matlab language  Arithmetic Operations  Variables  Matrix  Plot  Functions: inline & sym  Programming in Matlab  m-file  Optimization in Matlab INFORMS OSU Josh Xiaomin XiA Matlab Tutorial 3 / INF Intro Intro  MATLAB: MATrix and LABoratory  First developed by Dr.

Bạn đang xem: Matlab tutorial slides

Cleve Molder: Fortran based  In 1984, MathWorks was founded: C based INFORMS OSU Josh Xiaomin XiA Matlab Tutorial 4 / INF Intro: Installation Intro: Installation  Go to: http://ocio.osu.edu/software/directory/slwin/ INFORMS OSU Josh Xiaomin XiA Matlab Tutorial 5 / INF Intro: Installation Intro: Installation  Select the tool boxes that you need  e.g. Matlab, curve fitting, optimization, statistics, symbolic math, etc. INFORMS OSU Josh Xiaomin XiA Matlab Tutorial 6 / INF Intro: Matlab Windows Intro: Matlab Windows Layout Layout  Command Window  Command History  Current Directory Browser  Workspace Browser INFORMS OSU Josh Xiaomin XiA Matlab Tutorial 7 / INF Overview Overview  Introduction  Installation (Toolboxes)  Layout of Matlab Windows  Basics of Matlab language  Arithmetic Operation  Variables  Matrix  Plot  Functions: inline & sym  Programming in Matlab  m-file INFORMS OSU Josh Xiaomin XiA Matlab Tutorial 8 / INF Basics: Arithmetic Basics: Arithmetic Operations Operations + plus - minus * multiply / right divide left divide ^ exponential 2+3=5 2-3= -1 2*3=6 2/3=0.6667 23=1.5000 2^3=8 INFORMS OSU Josh Xiaomin XiA Matlab Tutorial 9 / INF Basics: Variables Basics: Variables  How to lớn define a variable name  Numbers và letter, but first component must be a letter  Case sensitive  No space, punctuations (except underline)  Special variables  ans  NaN, nan  Inf, -Inf  pi  i, j  realmax, realmin  However, you can redefine these variables, và use “clear” to clear redefinition. INFORMS OSU Josh Xiaomin XiA Matlab Tutorial 10 / INF Basics: Matrix Basics: Matrix  How lớn define a matrix/vector  A = <1 2 3 4; 4 5 6 7> ~~ <1:4; 4:7> (!!! Comma, colon, semicolon bracket)  Special matrix  zeros(m,n)  ones(m,n)  diag(vec)  Matrix operation  Basic arithmetic operation (!!! Period & dimensions)  Inverse (inv) & transpose (apostrophe)  Read/change matrix component (!!! parenthesis)  Stacking và breaking  Size(), length(), eig() <...>... Josh Xiaomin Xi 12 / INF Overview  Introduction  Installation (Toolboxes)  Layout of Matlab Windows  Basics of Matlab language  Arithmetic Operation  Variables  Matrix  Plot  Functions  Programming in Matlab  m-file: run large program, build large function  Control flow: if-else, while, for A Matlab Tutorial INFORMS OSU Josh Xiaomin Xi 13 / INF M file  Replace command window when running... 5x4x3x2x1=120 n A Matlab Tutorial INFORMS OSU Josh Xiaomin Xi 16 / INF Optimization In Matlab  Common optimization functions  linprog: linear programming  Quadprog: quadratic programming  fmincon: constrained non-linear minimization  fminsearch, fminunc: unconstrained nonlinear minimization  fsolve: non-linear system of equations solve  lsqlin: linear least square with linear constraints A Matlab Tutorial. ..

Xem thêm: Finally Servicing Young Married Beefcake Martin, European Street Cafe

Sub-sections  Better structure  Good for complicated programming/logic A Matlab Tutorial INFORMS OSU Josh Xiaomin Xi 14 / INF Control Flow If condition1  If-Else expression(s) 1; If condition else if condition2 expression(s) 1; expression(s) 2; else else expression(s) 2; expression(s) 3; over end 10 20  F = 30 40  A Matlab Tutorial INFORMS OSU t≤0 0 = 2 F = 40; else if... Bar bar chart Subplot one figure with sub figures A Matlab Tutorial INFORMS OSU Josh Xiaomin Xi 11 / INF Basics: Functions f = 3 sin( 2 x 2 − y )  Use “sym” / “syms”  Use “inline” f=inline(‘3*sin(2*x^2-y)’) syms x y; f=3*sin(2*x^2-y) f=inline(‘3*sin(2*x^2-y)’,’x’,’y’) f(1,1) Df=diff(f) Df2=diff(f,2) subs(f,x,4) fin=inline(char(f)) fin(1,1) A Matlab Tutorial INFORMS OSU Josh Xiaomin Xi 12 / INF Overview... Linprog  linprog: linear programming Min f(x) = –5x1 –4x2 –6x3 s.t x1 – x2 + x3 ≤ đôi mươi 3x1 + 2x2 + 4x3 ≤ 42 3x1 + 2x2 ≤ 30 0 ≤ x1, 0 ≤ x2, 0 ≤ x3 http://www.mathworks.com/help/optim/ug/linprog.html A Matlab Tutorial INFORMS OSU Josh Xiaomin Xi 18 / INF . 2013 A tutorial from A tutorial from INFORMS OSU Josh Xiaomin XiA Matlab Tutorial 2 / INF Overview Overview  Introduction  Installation (Toolboxes)  Layout of Matlab Windows  Basics of Matlab. Functions: inline & sym  Programming in Matlab  m-file  Optimization in Matlab INFORMS OSU Josh Xiaomin XiA Matlab Tutorial 3 / INF Intro Intro  MATLAB: MATrix and LABoratory  First developed. That you need  e.g. Matlab, curve fitting, optimization, statistics, symbolic math, etc. INFORMS OSU Josh Xiaomin XiA Matlab Tutorial 6 / INF Intro: Matlab Windows Intro: Matlab Windows Layout Layout 