Homework 1
Derivatives
Find the derivatives with the respect to x of the following.
library(mosaic)
## Loading required package: dplyr
## 
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union
## Loading required package: lattice
## Loading required package: ggformula
## Loading required package: ggplot2
## Loading required package: ggstance
## 
## Attaching package: 'ggstance'
## The following objects are masked from 'package:ggplot2':
## 
##     geom_errorbarh, GeomErrorbarh
## 
## New to ggformula?  Try the tutorials: 
##  learnr::run_tutorial("introduction", package = "ggformula")
##  learnr::run_tutorial("refining", package = "ggformula")
## Loading required package: mosaicData
## Loading required package: Matrix
## 
## The 'mosaic' package masks several functions from core packages in order to add 
## additional features.  The original behavior of these functions should not be affected by this.
## 
## Note: If you use the Matrix package, be sure to load it BEFORE loading mosaic.
## 
## Attaching package: 'mosaic'
## The following object is masked from 'package:Matrix':
## 
##     mean
## The following object is masked from 'package:ggplot2':
## 
##     stat
## The following objects are masked from 'package:dplyr':
## 
##     count, do, tally
## The following objects are masked from 'package:stats':
## 
##     binom.test, cor, cor.test, cov, fivenum, IQR, median,
##     prop.test, quantile, sd, t.test, var
## The following objects are masked from 'package:base':
## 
##     max, mean, min, prod, range, sample, sum
library(matrixcalc)
  1. F(x|x≥0)=1−e−λx = -e^
f = expression(1-log(x)^(-λx))
D(f,'x')
## -(log(x)^((-λx) - 1) * ((-λx) * (1/x)))
  1. F(x|b>a)=x−a/b−a
Ans2 = expression(x-a/b-a)
D(Ans2,'x')
## [1] 1
  1. F(x|a<x≤c≤b)=(x−a)^2/(b−a)(c−a)
Ans3 = expression((x-a)^2/(b-a)*(c-a))
D(Ans3,'x')
## 2 * (x - a)/(b - a) * (c - a)
  1. F(x|a≤c<x<b)=1−(b−x)2(b−a)(c−a) = 1-bb-x * 2b-2a *
Ans4 = expression(1-((b-x)^2/(b-a)*(c-a)))
D(Ans4,'x')
## 2 * (b - x)/(b - a) * (c - a)

Integrals Solve the following definite and indefinite integrals

  1. ∫ 3x^3dx l= 0 u = 10
Ans5 <- function(x) {3*x^3}
integrate(Ans5, lower = 0, upper = 10000)
## 7.5e+15 with absolute error < 83
  1. ∫ xλe^−λx lower limit 0 and upper limit x
# lambda replaced by constant for any rate of change
#Greek symbol of sigma and others seemed to be in library but can't find #lambda
Ans6 <- function(x) {x*.05*log(x)^-.05*x}
integrate(Ans6, lower = 0, upper = 10000)
## 14943504082 with absolute error < 27
  1. ∫1/b−a dx lower limit = 0 and upper limit = 5
#Ans7 <- function(x) {1 / (b-a) dx}
#Ans7
Ans7 <- function(x) {2*x}
Ans7
## function(x) {2*x}
integrate(Ans7, lower = 0, upper = 5)
## 25 with absolute error < 2.8e-13
  1. ∫x(1/(RhoalphaBeta^alpha)(x ^ alpha -1)*e ^−βx dx up lower = 0, upper = x
#Ans8 <- function(x) {x*(1/ r * alpha * B^alpha * (x^alpha-1) #ln(x)^beta*x }
AnsB <- function(x) {2*x}
AnsB
## function(x) {2*x}
integrate(AnsB, lower = 0, upper = 5)
## 25 with absolute error < 2.8e-13

Hint: the last part of the equation is beginning with the gamma function is a Gamma probability distribution function. Try rearranging the terms to integrate another Gamma distribution out of the integral, as pdfs must integrate to 1.

Linear Algebra With the following matrix, X=⎡⎣⎢134236318⎤⎦⎥

A <- matrix(c(1,3,4,2,3,6,3,1,8), ncol= 3)
A
##      [,1] [,2] [,3]
## [1,]    1    2    3
## [2,]    3    3    1
## [3,]    4    6    8
I <- matrix(c(1,0,0,0,1,0,0,0,1), ncol=3)
I
##      [,1] [,2] [,3]
## [1,]    1    0    0
## [2,]    0    1    0
## [3,]    0    0    1
  1. Invert it using Gaussian row reduction.
A <- matrix(c(1,3,4,2,3,6,3,1,8), ncol= 3)
A
##      [,1] [,2] [,3]
## [1,]    1    2    3
## [2,]    3    3    1
## [3,]    4    6    8
solve(A)
##      [,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.
A <- matrix(c(1,3,4,2,3,6,3,1,8), ncol= 3)
A
##      [,1] [,2] [,3]
## [1,]    1    2    3
## [2,]    3    3    1
## [3,]    4    6    8
det(A)
## [1] -4
  1. Conduct LU decomposition
A <- matrix(c(1,3,4,2,3,6,3,1,8), ncol= 3)
A
##      [,1] [,2] [,3]
## [1,]    1    2    3
## [2,]    3    3    1
## [3,]    4    6    8
Ans11 <- lu.decomposition(A)
Ans11
## $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
  1. Multiply the matrix by it’s inverse.
A <- matrix(c(1,3,4,2,3,6,3,1,8), ncol= 3)
A
##      [,1] [,2] [,3]
## [1,]    1    2    3
## [2,]    3    3    1
## [3,]    4    6    8
B <-solve(A)
B
##      [,1] [,2]  [,3]
## [1,] -4.5 -0.5  1.75
## [2,]  5.0  1.0 -2.00
## [3,] -1.5 -0.5  0.75
A %*% B
##               [,1]          [,2]         [,3]
## [1,]  1.000000e+00 -1.110223e-16 2.220446e-16
## [2,] -1.332268e-15  1.000000e+00 6.661338e-16
## [3,] -1.776357e-15 -8.881784e-16 1.000000e+00
#Answer of 12
##
##

Ans12 <- matrix(c(1,0,0,0,1,0,0,0,1), ncol =3)
Ans12
##      [,1] [,2] [,3]
## [1,]    1    0    0
## [2,]    0    1    0
## [3,]    0    0    1

is the answer to the matrix by it’s inverse