GithubHelp home page GithubHelp logo

fanwangecon / math4econ Goto Github PK

View Code? Open in Web Editor NEW
46.0 13.0 20.0 64.45 MB

Mathematics for Economists (Matlab Live Codes)

Home Page: https://fanwangecon.github.io/Math4Econ/

License: MIT License

MATLAB 85.53% R 2.34% TeX 0.46% JavaScript 11.67%
matlab economics-models economics optimization matlab-codes household-finance mathematics bookdown

math4econ's Introduction

HitCount Star Fork Star DOI

This is a work-in-progress course website for Mathematics for Economists. Course covers a limited subset of topics from Mathematics for Economists (Simon and Blume 1994), and uses various definitions from the book. Applications focus on two period borrowing and savings problems. Matlab's symbolic toolbox is used throughout.

bookdown site and bookdown pdf.

Materials are written in matlab livescript files and shown as HTML files. To obtain matlab codes, see here and here for github set up. For HTML files, click on the links below.

From other repositories: For dynamic borrowing and savings problems, see MEconTools and Dynamic Asset Repository; For code examples, see also Matlab Example Code, Stata Example Code, Python Example Code, R Example Code; For intro econ with Matlab, see Intro Mathematics for Economists, and for intro stat with R, see Intro Statistics for Undergraduates. See here for all of Fan's public repositories.

Files are from the Math4Econ repository. Please contact FanWangEcon for issues or problems.

1 Notations and Functions

  1. Real Number and Intervals: mlx | m | pdf | html
    • Definition and draw a line.
    • m: linspace() + line() + set(gca, yaxis off) + pbaspect()
  2. Interval Notations and Examples: mlx | m | pdf | html
    • Closed, open intervals.
  3. What is a Function?: mlx | m | pdf | html
    • Domain, argument, do-domain, image/value, range.
    • Graph a circle.
    • m: sin() + plot()
  4. Function Notations: mlx | m | pdf | html
    • Consistent function naming.
  5. Monomials and Polynomial of the 3rd Degree: mlx | m | pdf | html
    • Monomial, polynomial, degree of polynomial.
    • Graph polynomial of the 3rd degree and monomials of different degrees.
    • m: syms x + f(x) = a + x + fplot(@(x) f(x,a), [x_low, x_high])
  6. Local and Global Maximum: mlx | m | pdf | html
    • local and global maximum.
    • m: syms + solve() + diff() + double() + double(solve(diff(f,x),x)), fplot(f,[x_low, x_high])

2 Commonly Used Functions

  1. Exponential and Compounding Interest Rates: mlx | m | pdf | html
    • Exponential function and rules: a^b. Base e exponential, e = 2.71828.
    • Infinitely compounding interest rate (continuous time).
    • e^r: borrow 1 dollar, given r, meaning r percent interest, e^r is how much to pay back in principle + interests given infinite compounding.
    • Log linear equation with a constant term, substraction and division.
    • m: exp() + fplot() + double(subs())
  2. Exponential and Log Functions: mlx | m | pdf | html
    • log and natural log (log in matlab base e, log in google base 10).
    • log rules, and why: log(xy) = log(x) + log(y); log(x^a) = alog(x).
    • log difference and small rates of change.
    • m: linspace() + log()

3 Derivatives

  1. Derivative Definition and Rules: mlx | m | pdf | html
    • Derivative notations, limit definition, and key rules.
    • m: syms + diff()
  2. Continuity and Differentiability: mlx | m | pdf | html
    • Continuous point, set and function, continuously differentiable.
  3. Elasticity and Derivative: mlx | m | pdf | html
    • Elasticity of demand at price p, given h change in p.
    • Point elasticity of demand at price p.
    • Elasticity and the limiting definition of derivative.
  4. First Order Taylor Approximation: mlx | m | pdf | html
    • Differential: change along the tangent line to approximate change in function value.
    • First order taylor approximation and the limiting definition of derivative.
    • Differential approximating marginal productivity of labor.
    • m: syms + f(L) = L^a + sub(f, 1)
  5. Higher Order Derivatives Cobb Douglas: mlx | m | pdf | html
    • Cobb-Douglas production function, first and second derivatives.
    • Convex and Concave functions.
    • m: syms + f(L) = L^a + diff(diff(f, L),L) + fplot() + title({‘title one’ ‘subtitle’}) + ylabel({‘ylab abc’ ‘ylab efg’}) + legend{[‘line a’],[‘lineb’],, ‘Location’,’NW’}

4 Univariate Applications

  1. Marginal Product of Labor: mlx | m | pdf | html
    • Marginal product for each additional units of workers given different levels of capital.
    • m: plot() + scatter() + legend(['k=',num2str(K1)], ['k=',num2str(K1)])
  2. Derivative of Cobb-Douglas Production Function: mlx | m | pdf | html
    • Marginal product of labor given different levels of capitals.
    • m: syms + diff() + fplot()
  3. Derivative Approximation: mlx | m | pdf | html
    • Marginal product and tangent lines.
    • m: syms + diff() + fplot() + lengend{}
  4. Household's Savings Problem: mlx | m | pdf | html
    • Endowments today and tomorrow, borrowing and savings, no shocks.
    • Grid based or analytical solution.
    • Supply curve of savings (asset).
    • m: max() + diff() + solve() + plot() + scatter()
  5. Firm's Borrowing Problem: mlx | m | pdf | html
    • Profit maximization choosing capital, with labor fixed.
    • Grid based or analytical solution.
    • Demand curve of capital (asset).
    • Overlay demand and supply curves, visualize interest rate equilibrium
    • m: max() + diff() + solve() + plot() + scatter()

5 Matrix Basics

  1. Laws of Matrix Algebra: mlx | m | pdf | html
    • Scalar: Associative + Communtative + Distributive laws; Matrix: all apply except A times B != B times A.
    • m: transpose()
  2. Matrix Addition and Multiplication: mlx | m | pdf | html
    • Scalar, matrices, and matrix dimensions.
    • m: dot product
  3. Creating Matrixes in Matlab: mlx | m | pdf | html
    • Vectors, matrixes and multiple matrixes.
    • m: ceil() + eye() + tril() + triu() + rand(N,M,Q)

6 System of Equations

  1. System of Linear Equations: mlx | m | pdf | html
    • One or multiple linear equations.
    • Coefficient matrix and augmented form.
  2. Solving for Two Equations and Two Unknowns: mlx | m | pdf | html
    • Two equations and two unknowns matrix form.
    • Graphical intersection of two lines.
    • Using linear solver linsolve.
    • m: linsolve + double(solve(y_1 - y_2 == 0))
  3. System of Linear Equations Row Echelon Form: mlx | m | pdf | html
    • Two equations and two unknowns.
    • Elementary row operations and row echelon form.
  4. Matrix Inverse: mlx | m | pdf | html
    • Find the inverse of a matrix.

7 Matrix Applications

  1. Firm Maximization Problem with Capital and Labor: mlx | m | pdf | html
    • First order conditions Cobb-Douglas production function with Capital and Labor.
    • Log linearize first order conditions, matrix form and linsolve Cobb-Douglas production function.
    • Own and cross price elasticities
    • m: linsolve() + simplify(exp(linsolve())) + mesh() + meshgrid() + contourf() + clabel() + zlabel()
  2. Household Maximization with Two Goods and Budget: mlx | m | pdf | html
    • Preference over two good, cobb douglas utility.
    • Indifference curves and budget set.
    • m: linspace() + meshgrid() + mesh() + contourf() + clabel() + colormap() + zlabel() + plot()
  3. Capital Demand and Supply Equilibrium Analysis: mlx | m | pdf | html
    • Simplified nonlinear form of demand and supply as functions or the interest rate.
    • First order Taylor linear approximation of nonlinear demand and supply.
    • m: diff() + subs(S,r,1) + linsolve()
  4. First Order Taylor Approximation of Demand and Supply Curves: mlx | m | pdf | html
    • Exact solutions for (approximated) equilibrium interest rate and asset supply/demand given linearized demand and supply equations.
    • Graphical illustration of exact equilibrium and linear approximated equilibrium.
    • Analyze how productivity, elasticity, wealth, discount factor impact equilibrium prices and quantity given exact solutions to linear approximation.
    • m: linspace() + subs(diff(S,r), r, r0) + subs(D, {Z,beta}, {Z_num, beta_num}) + fplot() + plot() + line.Color + line.LineStyle

8 Uncertainty

  1. Risky Assets and Different States of the World: mlx | m | pdf | html
    • Bad and good states of the world.
    • Safe savings and risky investments with uncertain returns.
    • Borrowing to finance risky investments.
    • m: solve(diff(U, D)==0, diff(U, B)==0, D, B)

9 Equality Constrained Optimization

  1. Profit Maximization and Cost Minimization: mlx | m | pdf | html
    • Profit maximization and cost minimization with Cobb Douglas production function given quantity constraint. Constant or decreasing returns to scales, optimal capital and labor given quantity constraint.
    • m: GRADIENT = subs(GRADIENT, {A,p,w,r,q,alpha,beta},{1,1,1,1,2,0.3,0.7}) + solu = solve(GRADIENT(1)==0, GRADIENT(2)==0, GRADIENT(3)==0, K, L, m, ‘Real’, true)
  2. Firm Marginal Cost and Profit given Constant Returns to Scale: mlx | m | pdf | html
    • Profit maximization over outputs given cost minimization.
    • Marginal costs and constant returns to scales, perfect competition and zero profits.
  3. Marshallian Constrained Utility Maximization: mlx | m | pdf | html
    • Budget constrained intertemporal utility maximization.
    • Marshallian solutions, indirect utility
    • Analytical solution, matlab symbolic solution, matlab fminunc numerical solutions
    • m: diff() + gradient() + fmincon()
  4. Hicksian Constrained Expenditure Minimization: mlx | m | pdf | html
    • Optimal expenditure minimization choice given indirect utility.
    • Hicksian solutions (Dual Problem).
    • Analytical solution, matlab symbolic solution.
    • m: diff() + gradient()
    • graph: budget + indifference + endowment and optimal choices
  5. Income and Substitution Effects: mlx | m | pdf | html
    • Slusky decomposition, expenditure minimization given two prices.
    • Analytical solution, matlab symbolic solution.
    • m: diff() + gradient()

10 Inequality Constrained Optimization

  1. Firm Profit Maximization Problem with Borrowing Constraint: mlx | m | pdf | html
    • Constrained on capital/borrowing, solve for cases.
    • If constraint binds, re-optimize labor choice given capital bound.
  2. Borrowing and Savings with Borrowing Constraint: mlx | m | pdf | html
    • Unconstrained and constrained problem.
    • Analytical solution and fmincon solution.
    • Optimal borrowing/savings with varying endowments and interests rates.
    • m: U = @(b) log(z1 - b) + matlabFunction(subs(U, {z1, z2}, {z1v, z2v})); + fmincon(U, b0, A, q); + optimoptions('FMINCON','Display','off');
  3. Labor and Borrowing/Savings Choices with Borrowing Constraint: mlx | m | pdf | html
    • Unconstrained work/leisure and borrow/savings problem.
    • Constrained work/leisure and borrow/savings problem given borrow bound.
    • Analytical and matlab symbolic solutions.
    • Numerical solution with fmincon.
    • m: d_L_b = diff(L, b); + d_L_H = diff(L, H); + GRAD = [d_L_b; d_L_H] + solu = solve(GRAD(1)==0, GRAD(2)==0, b, H, 'Real', true); + solu = simplify(solu) + fmincon(U_neg, b0, A, q) + fmincon(U_neg, b0, A, q, [], [], [], [], [], options) + legendCell = cellstr(num2str(Z2_vec', 'Z2=%-d')) + plot()

11 Equilibrium and Policy

  1. Equilibrium Interest Rate and Tax: mlx | m | pdf | html
    • Households supply savings or borrow (with constraint) to smooth consumption.
    • Firms borrow to finance capital inputs.
    • Solve for excess demand and supply of assets and equilibrium interest rate.
    • The effect of a tax on savings and subsidy for borrowing on equilibrium interest rate.
    • m: U_neg = @(x) -1(log(z1 - x(1)) + beta_vec(j)*log(z2 + x(1)r_vec(i)(1-tau))) + excess_credit_supply = (sum(b_opti_mat, 2) + (-1)FIRM_K') + min(abs(excess_credit_supply)) + plot(r, excess_credit_supply)
  2. Equilibrium Interest Rate and Wage: mlx | m | pdf | html
    • Households supply labor and enjoy leisure, firms demand labor.
    • Households borrow with constraints and supply savings, firm demand capital.
    • Solve for excess supply of assets and labor over wage and interest rates grid.
    • Solve for market clearing wage and interest rates.
    • m: U_neg = @(x) -1(log(z1 + W_vec(j)x(2) - x(1)) + psilog(x(3)) + beta_vec(h)log(z2 + x(1)(R_vec(i)))) + options = optimoptions('FMINCON','Display','off'); + [x_opti,U_at_x_opti] = fmincon(U_neg, b0, A, q, [], [], [], [], [], options); + KD(i,j) = subs(K_opti,{r,w},{R(i), W(j)}) + LD(i,j) = subs(L_opti,{r,w},{R(i), W(j)}) + jet(numel(chart)) + plot(R, b_opti); + plot(R, -k_opti);*

Please contact for issues or problems.

DOI

RepoSize CodeSize Language Release License

math4econ's People

Contributors

fanwangecon avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.