MATLAB crash course 1 / 27
MATLAB crash course
Cesar E. Tamayo Economics - Rutgers September 27th, 2013
1/27
MATLAB crash course Cesar E. Tamayo Economics - Rutgers September - - PowerPoint PPT Presentation
MATLAB crash course 1 / 27 MATLAB crash course Cesar E. Tamayo Economics - Rutgers September 27th, 2013 1/27 MATLAB crash course 2 / 27 Program Program I Interface: layout, menus, help, etc.. I Vectors and matrices I Graphics: I Plots,
MATLAB crash course 1 / 27
1/27
MATLAB crash course 2 / 27 Program
I Plots, sublots, surfaces,3D, etc.. I Editing existing graphs
I Basic system of equations I Di¤erence equations
2/27
MATLAB crash course 3 / 27 Interface: layout, menus, help, etc..
I type: exp(1) I type: 3*55 I type: clc then clear
I select instructions)right click)’evaluate’ I (header, with and without ";" , %coments, clear, etc..)
3/27
MATLAB crash course 4 / 27 Vectors and matrices
I type start:step:end as in: q=1:1:6 I or simply g=linspace(1,6,6) I linspace has more uses: type h=linspace( 1
start, 5 end,10 size)
4/27
MATLAB crash course 5 / 27 Vectors and matrices
I u=[1,3,9 ] I w=[2 11 (1/0)/inf]
I create z=[3 4 6] I Now concatenate vertically: x=vertcat(u,w,z) I Now you have a 3 3 matrix!! I Conc. horizontally: xt=horzcat(u,w,z) or simply xt=[u w z] 5/27
MATLAB crash course 6 / 27 Vectors and matrices
I Try: xin*x ... then try xin’*x ... now try xin.*x
I beta=inv(x’*x)*x’*y ... I Its OLS β = (X 0X )1 X 0Y 6/27
MATLAB crash course 7 / 27 Graphics
7/27
MATLAB crash course 8 / 27 Graphics
8/27
MATLAB crash course 9 / 27 Graphics
9/27
MATLAB crash course 10 / 27 Graphics
10/27
MATLAB crash course 11 / 27 Loops, functions and handles
11/27
MATLAB crash course 12 / 27 Loops, functions and handles
12/27
MATLAB crash course 13 / 27 Loops, functions and handles
13/27
MATLAB crash course 14 / 27 Loops, functions and handles
14/27
MATLAB crash course 15 / 27 Loops, functions and handles
15/27
MATLAB crash course 16 / 27 Optimization
16/27
MATLAB crash course 17 / 27 Optimization
17/27
MATLAB crash course 18 / 27 Optimization
the structure containing
Matlab’s vector for
"show me the iterations"
use matlab’s "active-set" algorithm
18/27
MATLAB crash course 19 / 27 Solving systems of equations
19/27
MATLAB crash course 20 / 27 Solving systems of equations
20/27
MATLAB crash course 21 / 27 Solving systems of equations
1Remember, an orthogonal matrix is such that QT = Q1 so that
21/27
MATLAB crash course 22 / 27 Solving systems of equations
22/27
MATLAB crash course 23 / 27 Solving systems of equations
23/27
MATLAB crash course 24 / 27 Solving systems of equations
24/27
MATLAB crash course 25 / 27 Solving systems of equations
25/27
MATLAB crash course 26 / 27 Shortcuts and additional stu¤
I ¯
N ∑N i=1 xi = mean(x)
I px = sqrt(x) I
1 N ∑N i=1 (xi ¯
I ln x = log(x) I φ (x) = normpdf(x) I Φ (x) = normcdf(x) I Hodrik-Prescott …lter: hpfilter(x)
I Upper triangular A=triu(rand(5,3)) I Lower triangular A=tril(rand(5,3))
I Trace: trace(A) I Determinant: det(A) 26/27
MATLAB crash course 27 / 27 Shortcuts and additional stu¤
I http://www.stanford.edu/~roymill/cgi-
27/27