library(Deriv)
Question 1
f1 = function(x) 1 - (exp(- lambda * x))
answer1 = Deriv(f1)
answer1
## function (x)
## lambda * exp(-(lambda * x))
Question 2
f2 = function(x) (x - a) / (b - a)
answer2 = Deriv(f2)
answer2
## function (x)
## 1/(b - a)
Question 3
f3 = function(x) (x - a) ^ 2 / ((b - a) (c - a))
answer3 = Deriv(f3)
answer3
## function (x)
## 2 * ((x - a)/(b - a)(c - a))
Question 4
f4 = function(x) 1 - ((b - x) ^ 2 / ((b - a) (c - a)))
answer4 = Deriv(f4)
answer4
## function (x)
## 2 * ((b - x)/(b - a)(c - a))
Question 5
f5 = function(x) (3 * (x ^ 3))
answer5 = integrate(Vectorize(f5), 0, 10)
answer5
## 7500 with absolute error < 8.3e-11
library(mosaicCalc)
## Loading required package: mosaicCore
## Registered S3 method overwritten by 'mosaic':
## method from
## fortify.SpatialPolygonsDataFrame ggplot2
##
## Attaching package: 'mosaicCalc'
## The following object is masked from 'package:stats':
##
## D
Question 6
f6 = antiD(x * lambda * exp(- lambda * x) ~ x)
f6
## function (x, lambda, C = 0)
## {
## numerical_integration(.newf, .wrt, as.list(match.call())[-1],
## formals(), from, ciName = intC, .tol)
## }
## <environment: 0x00000000164c3620>
Question 7
a <- 0
b <- -1
f7 = function(x) (1 / (b - a))
answer7 = integrate(Vectorize(f7), 0, .5)
answer7
## -0.5 with absolute error < 5.6e-15
Question 8
f8 = antiD(x ^ {alpha + 1} / gamma * alpha * beta ^ {alpha} * e ^ {beta} ~ x)
## Warning in if (regexpr(rhsVar, deparse(lform[[2]], width.cutoff = 500))
## == : the condition has length > 1 and only the first element will be used
## Warning in if (regexpr(rhsVar, deparse(lform[[2]], width.cutoff = 500))
## == : the condition has length > 1 and only the first element will be used
## Warning in if (regexpr(rhsVar, deparse(lform[[2]], width.cutoff = 500))
## == : the condition has length > 1 and only the first element will be used
f8
## function (x, alpha, gamma, beta, e, C = 0)
## {
## numerical_integration(.newf, .wrt, as.list(match.call())[-1],
## formals(), from, ciName = intC, .tol)
## }
## <environment: 0x0000000016f5ba38>
library(matlib)
Question 9
m <- rbind(c(1, 2, 3), c(3, 3, 1), c(4, 6, 8))
m
## [,1] [,2] [,3]
## [1,] 1 2 3
## [2,] 3 3 1
## [3,] 4 6 8
gaussianElimination(m, diag(3))
## [,1] [,2] [,3] [,4] [,5] [,6]
## [1,] 1 0 0 -4.5 -0.5 1.75
## [2,] 0 1 0 5.0 1.0 -2.00
## [3,] 0 0 1 -1.5 -0.5 0.75
answer9 = inv(m)
answer9
## [,1] [,2] [,3]
## [1,] -4.5 -0.5 1.75
## [2,] 5.0 1.0 -2.00
## [3,] -1.5 -0.5 0.75
answer9a = solve(m)
answer9a
## [,1] [,2] [,3]
## [1,] -4.5 -0.5 1.75
## [2,] 5.0 1.0 -2.00
## [3,] -1.5 -0.5 0.75
Question 10
answer10 = det(m)
answer10
## [1] -4
library(pracma)
##
## Attaching package: 'pracma'
## The following objects are masked from 'package:matlib':
##
## angle, inv
## The following object is masked from 'package:mosaicCore':
##
## logit
Question 11
answer11 = lu(m)
answer11
## $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
Question 12
answer12 = answer9%*%answer9a
answer12
## [,1] [,2] [,3]
## [1,] 15.125 0.875 -5.5625
## [2,] -14.500 -0.500 5.2500
## [3,] 3.125 -0.125 -1.0625