matlabBasics

# matlabBasics - Matlab Basics Paul Schrimpf Paul Schrimpf...

This preview shows pages 1–10. Sign up to view the full content.

Matlab Basics Paul Schrimpf January 14, 2009 Paul Schrimpf () Matlab Basics January 14, 2009 1 / 24

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Overview Goals I Matlab features I Program design I Numerical methods Paul Schrimpf () Matlab Basics January 14, 2009 2 / 24
Topics to be covered Essentials of Matlab Using Matlab’s features to design good programs I Example: dynamic programming Optimization and integration I Example: maximum likelihood Object-oriented programming I Example: automatic diﬀerentiation Paul Schrimpf () Matlab Basics January 14, 2009 3 / 24

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Matlab References help function or more detailed, doc function Matlab Primer MATLAB on Athena 10.34 Matlab tutorial Numerical Computing with Matlab Art of Matlab Paul Schrimpf () Matlab Basics January 14, 2009 4 / 24
Operators Matrix Operators 1 a+b; 2 a - b; 3 a * b; 4 aˆn; 5 A'; 6 A \ b; % returns x s.t. A * x=b 7 A / b; % returns x s.s. x * A=b Array Operators 1 a. * b; 2 a.ˆn; 3 a. \ b; % these are 4 a./b; % equivalent 5 a & b; % don't confuse with && 6 a | b; % don't confuse with | | 7 a; t Paul Schrimpf () Matlab Basics January 14, 2009 5 / 24

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Avoid Matrix Inversion 1 K = 2000; N = K+1; b = ones(K,1); 2 x = randn(N,K); y = x * b + randn(N,1); 3 xx = x' * x; 4 xy = x' * y; 5 6 % from slow to fast . .. 7 tic; bhat1 = (xx)ˆ( - 1) * xy; toc; 8 tic; bhat2 = inv(xx) * xy; toc; 9 tic; bhat3 = xx \ xy; toc; \ is also more accurate, see purpose of inv Example: funWithInv.m Paul Schrimpf () Matlab Basics January 14, 2009 6 / 24
Array Functions Arrays of Constants 1 eye(10); % 10 by 10 identity 2 zeros(3); % 3 by 3 of zeros 3 zeros(2,3); % 2 by 3 of zeros 4 ones(31,35,69); 5 1:5; % [1 2 3 4 5] Vector Functions 1 sum(a,2); % sum along 2nd dimension of x 2 max(a); % max along 1st dimension of a 3 any(a,2); % a(:,1) | a(:,2) | ... 4 all(b); % b(1,:) & b(2,:) & . .. 5 cumprod(a); % cumulative product Paul Schrimpf () Matlab Basics January 14, 2009 7 / 24

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
More Functions All standard mathematical functions – linear algebra, special functions, polynomials, etc Manipulating arrays – sort, permute, ﬁnd, set operations Strings – regexp, ﬁndstr, etc Use the Matlab Function Reference Paul Schrimpf () Matlab Basics January 14, 2009 8 / 24
Flow Control 1 if (j==3) 2 % ... some commands . ..

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### Page1 / 24

matlabBasics - Matlab Basics Paul Schrimpf Paul Schrimpf...

This preview shows document pages 1 - 10. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online