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))
\(\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)
q3<- function(x)
{
(x-a)^2/((b-a)*(c-a))
}
# Check
Deriv(q3)
## function (x)
## 2 * ((x - a)/((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)))
fx <- function(x)
{
3*x^3
}
# Check
integrate(fx,0,10)
## 7500 with absolute error < 8.3e-11
\(\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}\)
fx <- function(x)
{
1/(.1)
}
integrate(Vectorize(fx),0,.5)
## 5 with absolute error < 5.6e-14
\(\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
\(\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
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
\(\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