David Apolinar

Question 1

\(F(x|x\ge 0)= 1- e^{-\lambda x}\)

Using the chain rule: \(\frac{d}{dx}(u^{n}) = nu^{n-1}\frac{du}{dx}\)

\(u = -\lambda x\)

the equation becomes \(1 - e^{u}\)

\(\frac{d}{dx}(1 - e^{u})\) becomes \(- e^{u}\)

\(\frac{d}{du}(-\lambda x)\) becomes \(-\lambda\)

The derivative is \((- e^{(-\lambda x)})(-\lambda)\) or \(\lambda(e^{-\lambda x})\)

q1<-function(x)
{
  
  1 - exp(1)^(2*x)
}
# Could not find out how to insert lambda, but lambda is similar to a constant. I used 2x as an example to show that the chain rule applies as expected.
library(Deriv)
Deriv(q1)
## function (x) 
## -(2 * 2.71828182845905^(2 * x))

Question 2

\(F(x \mid b > a) =\) \(\frac{x - a}{b - a}\)

Using the Power Rule

\(nx^{n - 1}\)

\(\frac{x - a}{b - a}\) becomes \(\frac{1}{b - a}\)

library(Deriv)
q2=function(x)
{
  (x-a)/(b-a)
}
# Check
Deriv(q2)
## function (x) 
## 1/(b - a)

Question 3

\(F(x|a< x \le c\le b)=\frac{(x-a)^2}{(b-a)(c-a)}\)

Using the Power Rule

Expand out the numerator \((x-a)^2\) becomes \(x^2 - 2ax -a^2\)

Use the Power Rule: \(nx^{n - 1}\)

\((b-a)(c-a\)) is a constant in the denominator so it is not affected by the Power Rule

The final output becomes \(\frac{2(x-a)}{(b-a)(c-a)}\)

q3<- function(x)
{
  (x-a)^2/((b-a)*(c-a))
}
# Check
Deriv(q3)
## function (x) 
## 2 * ((x - a)/((b - a) * (c - a)))

Question 4

\(F(x| a\le c<x<b)=1-\frac{(b-x)^2}{(b-a)(c-a)}\)

Expand out \((b-x)^2\) so it becomes \(1 - \frac{b^2 -2xb + x^2}{(b-a)(c-a)}\)

The numerator of the right expression becomes \(-1(b^2 -2xb + x^2)\) or \((-b^2 +2xb - x^2)\). The denominator is just a constant.

Using the Power Rule: \(nx^{n - 1}\)

\(\displaystyle \frac{d}{dx}\) of \(1+\frac{(-b^2 +2xb - x^2)}{(b-a)(c-a)}\) becomes \(\frac{2(b-x)}{(b-a)(c-a)}\)

q4 <- function(x)
{
  1 - ((b-x)^2 / ((b-a)*(c-a)))
}
library(Deriv)
#Check
Deriv(q4)
## function (x) 
## 2 * ((b - x)/((b - a) * (c - a)))

Question 5

\(\int_0^{10}3x^3dx\)

\(F(x)\) becomes \(\frac{3X^{3+1}}{3+1}\) –> \(\left. F(\frac{3x^4}{4}) \right|_{0}^{10}\)

\(\frac{3(10)^4}{4}\) - \(\frac{3(0)^4}{4} = 7500\)

fx <- function(x)
{
  3*x^3
}
# Check
integrate(fx,0,10)
## 7500 with absolute error < 8.3e-11

Question 6

Could not Solve this one. I know it requires u substition and integration by parts.

Question 7

\(\int_0^.5 \frac{1}{b-a}dx\) ### \(b-ac\) is just a constant so the integral of \(\int_0^.5 \frac{1}{b-a}dx\) becomes \(\left. F(\frac{x}{(b-a)}) \right|_{0}^{.5}\)

Using a constant for x in the R example below yields result of the definite integral

fx <- function(x)
{
  
  1/(.1)
}
integrate(Vectorize(fx),0,.5)
## 5 with absolute error < 5.6e-14

Question 8 - Could not solve

Question 9

\(\mathbf{X} = \left[\begin{array}{rrr}1 & 2 & 3\\3 & 3 & 1\\4 & 6 & 8\end{array}\right]\)

### Create the matrix
A=matrix(c(1,2,3,3,3,1,4,6,8),3,3,byrow=TRUE)

### Create the Identity Matrix
I<-diag(1,3)

### Create an augmented Matrix

AM<-cbind(A,I)

AM
##      [,1] [,2] [,3] [,4] [,5] [,6]
## [1,]    1    2    3    1    0    0
## [2,]    3    3    1    0    1    0
## [3,]    4    6    8    0    0    1
### Divide by row 3 by 2 and replace row 3

AM[3,]<-AM[3,] / 2


### Subtract 3*Row 1 from Row 2 and replace row 2

AM[2,]<-AM[2,]-3*AM[1,]

#### subtract - 2 * row 1 from row 3 and replace row 3

AM[3,] <- AM[3,]-2*AM[1,]

### add 2 * row 2 + row 1 and replace row 1

AM[1,]<-2*AM[3,]+AM[1,]

### add row 2 plus 3 times the negative of row 3 and replace row 2

AM[2,]<- 3 * -AM[3,] + AM[2,]

### Swap row 2 and row 3

TEMP <- AM[2,]
AM[2,]<-AM[3,]
AM[3,]<-TEMP

### divide row 3 by -2 and replace row 3

AM[3,] <- AM[3,]/-2

### Add row 3 to row 1 and replace row 1

AM[1,]<-AM[1,] + AM[3,]

### Add 2 * row 3 to row 2 and replace row 2

AM[2,]<-AM[2,] + AM[3,] * 2

### Multiply row 2 by -1 and replace row 2

AM[2,] <- AM[2,] * -1

## show value of Augmented matrix AM
AM
##      [,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
### Check vs built-in computation
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

Question 10 - Find the determinant of the Matrix

\(\mathbf{X} = \left[\begin{array}{rrr}1 & 2 & 3\\3 & 3 & 1\\4 & 6 & 8\end{array}\right]\) #### The determinant of the matrix will be the following:

\(\mathbf{X} = 1 * det \left[\begin{array}{rr}3 & 1\\6 & 8\end{array}\right] - 2 * det \left[\begin{array}{rr}3 & 1\\4 & 8\end{array}\right] + 3 * det \left[\begin{array}{rr}3 & 3\\4 & 6\end{array}\right]\)

\(\mathbf{Determint} = 1*(3*8-6*1)-2*(3*8-4*1)+3*(3*6-4*3)\)

D=1*(3*8-6*1)-2*(3*8-4*1)+3*(3*6-4*3)
D
## [1] -4
## Check built-in value
det(A)
## [1] -4

Question 11 - Conduct LU decomposition

Find U, where the bottom corner 3rd are all zeros

A=matrix(c(1,2,3,3,3,1,4,6,8),3,3,byrow=TRUE)

## Starting Matrix U
A
##      [,1] [,2] [,3]
## [1,]    1    2    3
## [2,]    3    3    1
## [3,]    4    6    8
## subtract 3 times row 1 from row 2 and store into row 2
## k value is -3

A[2,] <- A[2,] - 3 * A[1,]

A
##      [,1] [,2] [,3]
## [1,]    1    2    3
## [2,]    0   -3   -8
## [3,]    4    6    8
## subtract 4 times row 1 from row 3 and store into row 3
## k value -4
A[3,] <- A[3,] - 4 * A[1,]
A
##      [,1] [,2] [,3]
## [1,]    1    2    3
## [2,]    0   -3   -8
## [3,]    0   -2   -4
## add negative row (2 / 3) of row 2 to row 3 and store it in row 3
## K value = -(2/3)
A[3,] <- A[3,] + -A[2,]*(2/3)
U<-A
## This is U
U
##      [,1] [,2]      [,3]
## [1,]    1    2  3.000000
## [2,]    0   -3 -8.000000
## [3,]    0    0  1.333333
### Find L where the upper triangle corner are all zeros


##3 Using the multiplers from U, we will use the short-cut method by starting with a diag matrix with all zeros above and 1's across

L = diag(1,3)
## Using the inverse of the k values to find U, build L
L[2,1] <- 3
L[3,1] <- 4
L[3,2] <- (2/3)

### This is L

L
##      [,1]      [,2] [,3]
## [1,]    1 0.0000000    0
## [2,]    3 1.0000000    0
## [3,]    4 0.6666667    1
### L multiplied by U
L%*%U
##      [,1] [,2] [,3]
## [1,]    1    2    3
## [2,]    3    3    1
## [3,]    4    6    8

Question 12 - Multiply A by the inverse

\(\mathbf{A} = \left[\begin{array}{rrr}1 & 2 & 3\\3 & 3 & 1\\4 & 6 & 8\end{array}\right]\)

A=matrix(c(1,2,3,3,3,1,4,6,8),3,3,byrow=TRUE)
## Using inverse function to store inverse of A in AI
AI<-solve(A)
## This gives us the identiy matrix is close approximation 
A%*%AI
##               [,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