Install necessary packages
library(Deriv)
library(mosaic)
library(mosaicCalc)
Find the derivatives with the respect to x of the following:
myf1 = function(x)1-exp(-l*x)
Deriv(myf1)
## function (x)
## l * exp(-(l * x))
myf2 = function(x)(x-a)/(b-a)
Deriv(myf2)
## function (x)
## 1/(b - a)
myf3 = function(x)(x-a)^2/((b-a)(c-a))
Deriv(myf3)
## function (x)
## 2 * ((x - a)/(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))
Solve the following definite and indefinite integrals:
myf5 = function(x)3*x^3
integrate(myf5, 0, 10)
## 7500 with absolute error < 8.3e-11
\(\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})\)
\(\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
With the following matrix:
\[X = \begin{array} {rrr} 1 & 2 & 3 \\ 3 & 3 & 1 \\ 4 & 6 & 8 \end{array}\]
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
det(X)
## [1] -4
\[\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
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