Dynamic Macroeconomic Modeling with Matlab
Dynamic Macroeconomic Modeling with Matlab
Dynamic Macroeconomic Modeling with Matlab
Create successful ePaper yourself
Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.
3 A Short Introduction to <strong>Matlab</strong><br />
Functions can be saved in m files in the same way as scripts. They have to be introduced<br />
according to<br />
function output = functionname(x1, x2)<br />
where functionname is the name of the function, output is the function output, and x1, x2,<br />
etc. are the input arguments. For example, the following function named test would yield the<br />
square of the input argument x if executed<br />
function output = test(x)<br />
output=x*x;<br />
>> test(3)<br />
ans = 9<br />
Exercises<br />
1. sin, cos, exp, sqrt, pi, inf, NaN, i<br />
Calculate<br />
√ 2, √ −2,<br />
2. size, eye, zeros, rand, randn, det, inv<br />
cos(π) + 2 · e 0<br />
sin(π) + 1 , sin(1010 · π),<br />
1 −1<br />
,<br />
0 0 ,<br />
Create two 3×3 matrices A and B <strong>with</strong> random entries equally distributed on the interval<br />
[0; 10] and check, if<br />
holds.<br />
(A + I)(A − I) = A 2 − I<br />
(A + B) t = A t + B t<br />
(AB) t = B t A t<br />
det(AB) = det(A) · det(B)<br />
A −1 −1 = A<br />
3. Define the parameters α = 0.3, β = 0.4, δ = 0.05, and A = 10 and calculate<br />
for k = 1, 1.1, 1.2,...,3.<br />
Ak α+β − δk<br />
0<br />
0