Packages

library(mosaic)
library(lpSolve)
library(lpSolveAPI)

Alot of calculus functions, and concepts can be done in R. For example, Differential Cal which dives things into small pices and tells us how change form one moment to th next. Also, Integrates Cal which joins small pices together and tells us how much something is made.

Creating Functions

There are different ways of making a mathematical function in R. One way is using the mosaic package. Another is using R own function command. Like is shown bellow:

Give numbers to \(g\) and \(h\):

Example 1

# This is showing that g is a function of x and x is {3*x + 5}.
g = function(x) {3*x + 5} 
# 
g(6)
## [1] 23

Example 2

# Creating functions
h = function(x, m, b) {m*x + b} 
#
h(2,4,6)
## [1] 14
# Plotting the Functions
s1 <- findZeros(x^2 + y^2 + z^2 - 10 ~ x & y & z, near = 0, within = 10, nearest = 1000)

cloud(z ~ x + y, data = s1, pch = 19)

\(U =xy\) \(\frac{\partial U}{\partial x} = U_x =y\)

Example of Calculus function

# Simple Calculus Function
f = function(x){ x^2 + 2*x - x}
f(3)
## [1] 12

There are different methods of making function. Here is another one.

## [1] 0

Build in R functions
sqrt()
cos()
acos()
sin()
log()
exp()
pi will give pie

Ploting Functions

# Plotting functions
plotFun(A*x^2 ~ A, A.lim=range(-2,3), x=10)

plotFun(sqrt(abs(g(x))) ~ x, x.lim=range(-5,5))

Calculus in Microeconomics

  1. Utility maximazation
  2. Profit maximazation
  3. Cost minimazation
  4. Indifference map
  5. Indifference curve
  6. Income and substitution effect
  7. Elasticity
  8. Utility function
  9. Demand function.
  10. Optimize with constraint

Optimize with Constraints

Lets say we have two functions. The first one is revenue = R: \(R(x,y) = x^2 + y,\). The second function would be the bunget.
Maximize
\[R(x,y) = x^2 + y,\] Constraint
\[x^2-y^2=1\] Make the Functions. The fallowing code is using the mosaic package.

R = makeFun(x^2 + y ~ x&y) # This is the opjective function.
B = makeFun(x^2 - y^2 ~ x&y)
# ~ x&y is saying is a function of x and y. 

Plot the Functions. This is what the objective function would look like.

plotFun(R(x,y)~x&y, 
        xlim = range(-10,10), ylim = range(-10,10),
        filled = F, # This fills the the space between the contours. 
        xlab = "X Good",
        ylab = "Y Good",
        interactive = T)

Plotting both function, the Budget function and the Revenue function

plotFun(B(x,y)~x&y, 
        levels = 1, 
        xlim = range(-10,10), ylim = range(-10,10), 
        filled = F, 
        add = T, # To add into the previous plot
        col = "r")

Examples

Example I Manufacture company where x = the good manufacture f(C) = C(x) = 20x + 1500, R(x) = -x^2 +180x Fix cost = 1500 marginal cost = 20 Profit function = P(x) = -x^2 + 160x - 1500 Break-even point = P(x) = -x^2 + 160x - 1500 => x^2 - 160x + 1500 = 0 => (x - 10)(x -150) = 0 = 10 & 150 maximize daily profits = x = -b/2a = -160/2*-1 = 80.