Matlab
Matlab
Violeta Ivanova, Ph.D. Educational Technology Consultant MIT Academic Computing [email protected]
This Tutorial
!
Class materials
web.mit.edu/acmath/matlab/16.62x
Topics
" " " "
MATLAB Basics Review Data Analysis Statistics Toolbox Curve Fitting Toolbox
16.62x MATLAB Tutorials
Other References
!
Course16 Tutorials
" "
Help in MATLAB
!
Help Browser
"
Help->Help MATLAB
16.62x MATLAB Tutorials
MATLAB
+ Mathematics + Data Analysis + Programming + Graphics
! !
Vectors
!
Row vector
>> R1 = [1 6 3 8 5] >> R2 = [1 : 5] >> R3 = [-pi : pi/3 : pi]
Column vector
>> C1 = [1; 2; 3; 4; 5] >> C2 = R2'
Matrices
!
Creating a matrix
>> A = [1 2.5 5 0; 1 1.3 pi 4] >> A = [R1; R2]
Accessing elements
>> A(1,1) >> A(1:2, 2:4) >> A(:,2)
16.62x MATLAB Tutorials
Matrix Operations
!
Operators + and >> X = [x1 x2]; Y = [y1 y2]; A = X+Y A = x1+y1 x2+y2
! !
Operators *, /, and ^
>> Ainv = A^-1 Matrix math is default!
Built-In Functions
!
Graphics
!
Annotating graphs
>> >> >> >> legend (z = f(t)) title (Position vs. Time) xlabel (Time) ylabel (Position)
16.62x MATLAB Tutorials
Multiple Plots
!
Subplots on a figure
>> >> >> >>
Missing Data
!
Data Statistics
!
Correlation
!
Basic Fitting
!
Polynomials
!
Fitting a polynomial
>> X = [x1 x2 xn]; Y = [y1 y2 yn] >> Pm = polyfit(X, Y, m)
16.62x MATLAB Tutorials
Statistics Toolbox
Probability Distributions Descriptive Statistics Linear & Nonlinear Models Hypothesis Tests Statistical Plots
Descriptive Statistics
!
Central tendency
>> >> >> >> m gm med mod = = = = mean(X) geomean(X) median(X) mode(X)
Dispersion
>> s = std(X) >> v = var(X)
Probability Distributions
!
Parameter estimation
>> m = expfit(data) >> [m, s] = normfit(data)
16.62x MATLAB Tutorials
Linear Models
!
Definition:
y = X! + "
y: n x 1 vector of observations X: n x p matrix of predictors !: p x 1 vector of parameters ": n x 1 vector of random disturbances
Linear Regression
!
Residuals plot
>> rcoplot(R, Rint)
16.62x MATLAB Tutorials
One-way ANOVA
>> anova1(X,group)
Multiple Comparisons
>> [p, tbl, stats] = anova1(X,group) >> [c, m] = multcompare(stats)
Two-way ANOVA
>> [P, tbl, stats] = anova2(X, reps)
Statistical plots
>> boxplot(X, group)
Questions?
Analyzing a Fit
Exercise 2: Regression
!
Questions?