library(Deriv)
library(mosaicCalc)
## Loading required package: mosaicCore
##
## Attaching package: 'mosaicCalc'
## The following object is masked from 'package:stats':
##
## D
# Derivatives
f1 = function(x) 1-exp(-(L*x))
Deriv(f1)
## function (x)
## L * exp(-(L * x))
f2 = function(x) (x-a)/(b-a)
Deriv(f2)
## function (x)
## 1/(b - a)
f3 = function(x) (x-a)^2 / ((b-a)*(c-a))
Deriv(f3)
## function (x)
## 2 * ((x - a)/((b - a) * (c - a)))
f4 = function(x) 1- (b-x)^2 / ((b-a)*(c-a))
Deriv(f4)
## function (x)
## 2 * ((b - x)/((b - a) * (c - a)))
# Integrals
f5 = function(x) 3*x^3
integrate(f5, 0, 10)
## 7500 with absolute error < 8.3e-11
#f6 = function(x) x*L*exp(-(L*x))
u <- function(x) L*x
du <- Deriv(u)
v <- antiD(exp(-L*x)~x, force.numeric = FALSE)
#v*du = -exp(-L*x)
f <- function(x) antiD(-exp(-L*x)~x)
#attempted to do integration by parts by failed when integrating
f7 = function(x) 1/(b-a)
# Error when integrate(f7, 0, 0.5)
f8 = function(x) {x* (1/(Gamma(a)*b^a)) * x^(a-1) * exp(-(b*x))}
# Error when integrate(f8, 0, x)
# Linear Algebra
X <- matrix(c(1,2,3,3,3,1,4,6,8), ncol=3, byrow = TRUE)
X
## [,1] [,2] [,3]
## [1,] 1 2 3
## [2,] 3 3 1
## [3,] 4 6 8
#9. Invert it using Gaussian row reduction.
library(matlib)
inv(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
#10. Find the determinant.
det(X)
## [1] -4
#11. Conduct LU decomposition.
library(matrixcalc)
##
## Attaching package: 'matrixcalc'
## The following object is masked from 'package:matlib':
##
## vec
lu.decomposition(X)
## $L
## [,1] [,2] [,3]
## [1,] 1 0.0000000 0
## [2,] 3 1.0000000 0
## [3,] 4 0.6666667 1
##
## $U
## [,1] [,2] [,3]
## [1,] 1 2 3.000000
## [2,] 0 -3 -8.000000
## [3,] 0 0 1.333333
#12. Multiply the matrix by its inverse.
XI <- inv(X)
X %*% XI
## [,1] [,2] [,3]
## [1,] 1 0 0
## [2,] 0 1 0
## [3,] 0 0 1