Install necessary packages

library(Deriv)
library(mosaic)
library(mosaicCalc)

Derivatives

Find the derivatives with the respect to x of the following:

  1. \(F(x|x≥0) = 1−e^{−λx}\)
myf1 = function(x)1-exp(-l*x)
Deriv(myf1)
## function (x) 
## l * exp(-(l * x))
  1. \(F(x|b>a) = \frac{x-a}{b−a}\)
myf2 = function(x)(x-a)/(b-a)
Deriv(myf2)
## function (x) 
## 1/(b - a)
  1. \(F(x|a<x≤c≤b) = \frac{(x-a)^2}{(b−a)(c-a)}\)
myf3 = function(x)(x-a)^2/((b-a)(c-a))
Deriv(myf3)
## function (x) 
## 2 * ((x - a)/(b - a)(c - a))
  1. \(F(x|a<x≤c≤b) = 1-\frac{(b-x)^2}{(b−a)(c-a)}\)
myf4 = function(x)1-(b-x)^2/((b-a)(c-a))
Deriv(myf4)
## function (x) 
## 2 * ((b - x)/(b - a)(c - a))

Integrals

Solve the following definite and indefinite integrals:

  1. \(\int_0^{10} 3x^3 ~dx\)
myf5 = function(x)3*x^3
integrate(myf5, 0, 10)
## 7500 with absolute error < 8.3e-11
  1. \(\int_0^{x} x\lambda e^{-\lambda x} ~dx \\ u=x, ~du=dx, ~dv=e^{-\lambda x}, ~v=-\frac{e^{-\lambda x}}{\lambda} \\ \lambda\int_0^{x} x e^{-\lambda x} ~dx = \lambda [-x\frac{e^{-\lambda x}}{\lambda}+ \int_0^{x} \frac{e^{-\lambda x}}{\lambda} ~dx]_0^{x} \\ =\lambda [-x\frac{e^{-\lambda x}}{\lambda}- \frac{e^{-\lambda x}}{\lambda^2}]_0^{x} =-x e^{-\lambda x} - \frac{e^{-\lambda x}}{\lambda} - (0 - \frac{1}{\lambda}) \\ =-x e^{-\lambda x} - \frac{e^{-\lambda x}}{\lambda} + \frac{1}{\lambda} = \frac{1}{\lambda} - e^{-\lambda x}(x+\frac{1}{\lambda})\)

  2. \(\int_0^{0.5}\frac{1}{b−a} ~dx\)

myf7 = function(x)1/(b-a)
integrate(myf5, 0, 0.5)
## 0.046875 with absolute error < 5.2e-16
  1. \(\int_0^xx\frac{1}{\Gamma(\alpha)\beta^\alpha}x^{\alpha-1}e^{-\beta x} ~dx \\ \int_0^xx\frac{1}{\Gamma(\alpha)\beta^\alpha}x^{\alpha-1}e^{-\beta x} ~dx = \frac{1}{\Gamma(\alpha)\beta^\alpha}\int_0^xx^{\alpha}e^{-\beta x} ~dx \\ t=\beta x, ~dt=\beta dx, ~dx=\frac{1}{\beta}dt \\ \frac{1}{\Gamma(\alpha)\beta^\alpha}\int_0^{t/\beta} (\frac{t}{\beta})^{\alpha}e^{-t} ~\frac{dt}{\beta} = \frac{1}{\Gamma(\alpha)\beta^\alpha}[\frac{1}{\beta^{\alpha+1}}\int_0^{t/\beta} t^{\alpha}e^{-t} ~dt] \\ u=t^{\alpha}, ~du=\alpha t^{\alpha-1} dx, ~dv=e^{-t}, v=-e^{-t} \\ \frac{1}{\Gamma(\alpha)\beta^{2 \alpha+1}}[\int_0^{t/\beta} t^{\alpha}e^{-t} ~dt]=\frac{1}{\Gamma(\alpha)\beta^{2 \alpha+1}}[-e^{-t}t^{\alpha} + \alpha\int_0^{t/\beta} t^{\alpha-1}e^{-t} ~dt] \\ \frac{1}{\Gamma(\alpha)\beta^{2 \alpha+1}}[-t^{\alpha}e^{-t} + \alpha\Gamma(\alpha)]_0^{x} = \frac{1}{\beta^{2 \alpha+1}}[-\frac{x^{\alpha}e^{-x}}{\Gamma(\alpha)} + \alpha - (0+\alpha)] = \frac{-x^{\alpha}e^{-x}}{\beta^{2 \alpha+1}\Gamma(\alpha)}\)

Linear Algebra

With the following matrix:

\[X = \begin{array} {rrr} 1 & 2 & 3 \\ 3 & 3 & 1 \\ 4 & 6 & 8 \end{array}\]

  1. Invert it using Gaussian row reduction.
X <- matrix(c(1,3,4,2,3,6,3,1,8),3,3)
solve(X)
##      [,1] [,2]  [,3]
## [1,] -4.5 -0.5  1.75
## [2,]  5.0  1.0 -2.00
## [3,] -1.5 -0.5  0.75
  1. Find the determinant.
det(X)
## [1] -4
  1. Conduct LU decomposition

\[\begin{bmatrix} 1 & 2 & 3 \\ 3 & 3 & 1 \\ 4 & 6 & 8 \end{bmatrix} = \begin{bmatrix} l_{11} & 0 & 0 \\ l_{21} & l_{22} & 0 \\ l_{31} & l_{32} & l_{33} \end{bmatrix} \begin{bmatrix} u_{11} & u_{12} & u_{13} \\ 0 & u_{22} & u_{23} \\ 0 & 0 & u_{33} \end{bmatrix}\]

Set \(l_{11}, l_{22}, l_{33}\) to 1

Row-reduce matrix X to make it upper triangular Step 1: R2 = R2-3R1, Step 2: R3 = R3-4R1, Step 3: R3 = R3-2/3R2

\[\begin{bmatrix} 1 & 2 & 3 \\ 0 & -3 & -8 \\ 4 & 6 & 8 \end{bmatrix} \rightarrow \begin{bmatrix} 1 & 2 & 3 \\ 0 & -3 & -8 \\ 0 & -2 & -4 \end{bmatrix} \rightarrow \begin{bmatrix} 1 & 2 & 3 \\ 0 & -3 & -8 \\ 0 & 0 & 4/3 \end{bmatrix}\]

with the rightmost matrix above being the upper triangular matrix U. The lower triangular matrix L is populated with 1s in the its diagonal and the other coefficients replaced with the factors from the row reduction steps (3, 4, 2/3) yielding:

\[\begin{bmatrix} 1 & 2 & 3 \\ 3 & 3 & 1 \\ 4 & 6 & 8 \end{bmatrix} = \begin{bmatrix} 1 & 0 & 0 \\ 3 & 1 & 0 \\ 4 & 2/3 & 1 \end{bmatrix} \begin{bmatrix} 1 & 2 & 3 \\ 0 & -3 & -8 \\ 0 & 0 & 4/3 \end{bmatrix}\]

Let’s verify using R that X = LU:

L <- matrix(c(1,3,4,0,1,2/3,0,0,1),3,3)
U <- matrix(c(1,0,0,2,-3,0,3,-8,4/3),3,3)
L%*%U
##      [,1] [,2] [,3]
## [1,]    1    2    3
## [2,]    3    3    1
## [3,]    4    6    8
  1. Multiply the matrix by it’s inverse.
X <- matrix(c(1,3,4,2,3,6,3,1,8),3,3)
invX <- solve(X)
X%*%invX
##               [,1]          [,2]         [,3]
## [1,]  1.000000e+00 -2.220446e-16 4.440892e-16
## [2,] -4.440892e-16  1.000000e+00 2.220446e-16
## [3,]  0.000000e+00  0.000000e+00 1.000000e+00