Вы находитесь на странице: 1из 3

Syntax and Basic Commands Precision is a built-in function that gives the effective number of (decimal) digits of precision

in a number % refers to the last result generated, %% penultimate result generated. To refer to previous results it is better to assign them with a name. () to alter order of computations, [] are reserved to functions, {} are reserved to lists. Factorial is a built-in function that computes the factorial of a number ScientificForm Power[base, exponent] , if we type Precision[%]MachinePrecision, current value of Machine Precision $MachinePrecision. Sqrt Exp N[,digits of precision] numerical approximation

LHS = RHS 1. Evaluate rhs only once 2. Assigns its result to be the value of lhs when lhs appers, it is replaced by the already evaluated rhs LHS := RHS 1. Assigns rhs to the unevaluated value of lhs when lhs appears, rhs gets evaluated afresh and its value replaces lhs. Variable names begin with a letter otherwise a multiplication is implied. - Clear is a built-in function that clears value and definitions for symbols - Set values to symbols a and b by using a List; then compute Limit[function, variable] Derivative: D[f[x,y], x] : first partial derivative with respect to x; D[f,{x,n}] gives the multiple derivative with respect to x ( or a I write ,x,x or ,x,y ); f for first derivative instead of D. Examples from economics - Cobb Douglas Utility function - Total Cost function: is a function of one variable Q, representing the produced quantity (output) - Average Cost is given by Total Cost divided by the produced quantity Q - Marginal Cost is given by the first derivative of the Total Cost (with respect to Q) - Then we consider the two-input Production Function (H is capital L is Labor) and assign it to the output Q - The Marginal Productivity of Labor is the first partial derivative of the Production Function Q(with respect to labor L). - The Average Product for Labor is given by: output Q divided by labor L If I ask myself whether the production exhibits diminishing (marginal) returns (marginal productivity of labor). To examine the return to labor, we take the second partial derivative of the production function Q with respect to L. If its negative then the inputs do exhibit diminishing return. Up to this point we have assumed that capital H does not depend on labor L. - If H depends on L, then to define the marginal productivity of labor we would need to take the total derivative Dt of the production function with respect to labor L. {output is first derivative + 100 sqrt L Dt[H,L].

If H and L are independent of each other, DT[H,L == 0 and the output is simply the first derivative: command is ( Dt[Q,L]/.Dt[H,L]->0 )

Integrals can be computed exactly (using the fundamental theorem of calculus) or approximated numerically (using quadrature formulae) - Integrate[f, paramenter] indefinite integral - Integrate or NIntegrate[f,{parameter, interval}] definite integral - We can also compute improper integrals The built-in functions above do not include the Constant of Integration, but we can find it recalling differential equations e.g. dsol = DSolve[Y'[t] == f[t], Y[t], t] dsol[[1, 1, 2]] H1 =dsol [[1, 1, 2]] / . t 1 const= Solve[H1==number] The complete solution is then given by HC=H+const[[1,1,2]]. ReplaceAll ( /. ) is abuilt-in function that applies a rhs rule or list of rules to each matching subpart of a lhs expression Part ( [[, , ]] ) is a built in function that gives part of an expression

Example from economics To derive the total cost curve from a marginal cost curve plus a known initial condition (usually the fixed cost). Supply and Demand analysis involves a system of 2 linear equations, sharing the 2 variables Price and Quantity. Equilibrium values of price and quantity are found by solving the 2x2 system simultaneously MatrixForm[variables that indicates list of lists] or variable // MatrixForm. MatrixForm should be used only to format the output, do not use it when a matrix is being defined: the statement that defines a matrix or a vector & the statement that formats the output should be kept separated (two different statements). Table is a built in that can be used to define lists, vectors, nested lists, and matrices: Table[I, {I,1,3,1}] and the output is a list {1,2,3} or table1=Table[i+7, {I,3},{j,3}] and MatrixForm[table1] Dot[,] or vector . vector, matrix . vector, matrix . matrix Outer[Times,list1,lis2] and Times is multiplication between scalars Transpose of a matrix Det determinant of a matrix Inverse of a matrix Tr trace of a matrix Eigenvalues of a matrix Eigenvectors of a matrix Eigensystem of a matrix Norm of a matrix or vector

Solving equations Equal(==) is not to be confused with Set (=) Solve is a built in function that attempts to solve systems of equations or inequalities (use Rule before??), solutions are given as lists of replacement rules We can assign to the symbol ysol the solution sol, using ReplaceAll We can assign to the symbol ysol the solution sol using Part(that gets rid of the List) First picks first

- Last picks last By default Solve searches for both real or complex solutions, most economic problems require a non-complex solution - Flatten eliminates by default all inner sets of brackets, leaving only the most external set. Differential Equations Differential and difference equations are the mathematical foundation of economy dynamics. Differential equations are used to solve problems within a continuous time framework while difference equations are used to solve problems within a discrete time framework. Starting form ODE e PDE, they can be solve symbolically or numerically with Mathematica. - ode1 := P'[t] == 2*P[t] + 10 dsol = DSolve[ode1, P[t], t] {{P[t] -> -5 + E^(2 t) C[1]}} (first order ode, ode1 states that the change in price is equal to 10 plus twice the current (solved symbolically). The we obtain with Part a family of solutions with parameter C[1] and we can plot it for an interval. To determine a single solution we need to know the initial condition P[0]. - We can also create the plot of P[t] For a second order ode Interpolating Data is a list of numbers Interpolation with a piecewise function if = interpolating[data] Interpolation of data with a polynomial ip=InterpolatinPolynomial[data,x] Expand[ip] Fitting of data with regression line, that is to say least squares first order approximation : fx = Fit[data, {1, x}, x] // Chop Fitting of data with least squares second order (parabola) approximation: fx2 = Fit[data, {1, x, x^2}, x] // Chop ListPlot of data points

Вам также может понравиться