library(Deriv)
library(mosaic)
library(mosaicCalc)
library(rSymPy)

Find the derivatives with the respect to x of the following.

  1. F(x|x≥0)=\(1−e^{(−\lambda x)}\)
myf1=function(x){1-exp(-lambda*x)}
print(Deriv(myf1))
function (x) 
lambda * exp(-(lambda * x))

  1. \(F(x|b>a)=\frac{(x−a)}{(b−a)}\)
myf2 = function(x){(x-a)/(b-a)}
print(Deriv(myf2))
function (x) 
1/(b - a)

  1. \(F(x|a<x≤c≤b)=\frac{(x−a)^2}{(b−a)(c−a)}\)
myf3 = function(x){(x-a)^2/((b-a)(c-a))}
print(Deriv(myf3))
function (x) 
2 * ((x - a)/(b - a)(c - a))

  1. \(F(x|a≤c<x<b)=1−\frac{(b−x)^2}{(b−a)(c−a)}\)
myf4 = function(x)1-(b-x)^2/((b-a)(c-a))
print(Deriv(myf4))
function (x) 
2 * ((b - x)/(b - a)(c - a))

Solve the following definite and indefinite integrals

  1. \(\int_0^{10} 3x^3dx\)
myf5=function(x)3*x^3
integrate(Vectorize(myf5),0,10)
7500 with absolute error < 8.3e-11

  1. \(\int_0^x x\lambda e^{−\lambda x}dx\)

Solution:

Substitution \(u=-\lambda x\); \(du=-\lambda dx\); \(dx=\frac{du}{-\lambda}\);

\(\int -u e^u \frac{du}{-\lambda}\);

\(\frac{1}{\lambda}\int u e^u du\)

solve \(\int u e^u du\) by Parts: \(s=u; ds=du\); \(dv=e^udu; v=e^u+C\);

formula: \(sv-\int vds\)

\(=u e^u - \int e^u du\)

\(=u e^u - e^u\)

\(= (u-1)e^u\)

plugging back in: \(\frac{1}{\lambda}(u-1)e^u\)

replacing \(u=-\lambda x\) back in: \(\frac{1}{\lambda}\int u e^u du\)

\(=\frac{1}{\lambda}(-\lambda x - 1)e^{-\lambda x}\)

\(= -\frac{(\lambda x + 1) e^{-\lambda x}}{\lambda}\)

lastly we need to integrate over \(0\to x\):

\(-\frac{(\lambda x + 1) e^{-\lambda x}}{\lambda} ]_0^x\) \(=-\frac{(\lambda x + 1) e^{-\lambda x}}{\lambda} - \frac{1}{\lambda}\) \(=-\frac{(\lambda x + 1) e^{-\lambda x}+1}{\lambda}\)

library(rSymPy)
sympy("x = Symbol('x')")
sympy("l = Symbol('lambda')")

sympy("integrate(x*l*exp(-l*x),(x,0,x))")

Answer from sympy: \(\frac{-\lambda e^{-\lambda x}}{\lambda^2}-\frac{x e^{-\lambda x}}{\lambda}+\frac{1}{\lambda}\)

I’m not sure how to get r to calculate this or it was intended that we to this by hand. I made my best stab at doing by hand and code in latex for the notebook.


  1. \(\int_0^{0.5} \frac{1}{b−a}dx\)

Solution: \(\frac{1}{b-a} x ]_0^x = \frac{x}{b-a} - 0 = \frac{x}{b-a}\)

library(rSymPy)
sympy("x = Symbol('x')")
sympy("a = Symbol('alpha')")
sympy("B = Symbol('beta')")

sympy("integrate(1/(B-a),(x,0,x))")

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

I’m not sure how to get r to calculate this or it was intended that we to this by hand. I’m a python guy so brought over sympy to help. I made my best stab at doing by hand and code in latex for the notebook.


  1. \(\int_0^x x \frac{1}{\Gamma(\alpha)\beta^\alpha} x^{\alpha -1} e^{-\beta x} dx\)

Solution:

library(rSymPy)
sympy("x = Symbol('x')")
sympy("a = Symbol('alpha')")
sympy("B = Symbol('beta')")
sympy("G = Symbol('Gamma')")

sympy("integrate(x * (G*a*B**a)**(-1) * x**(a) * exp(-B*x), (x,0,x))")

sympy solution: \(\frac{x \beta^{-\alpha}x^{\alpha-1}e^{-\beta x}}{\Gamma \alpha}]_0^x\)

I really have no idea how to tackle this or was was hinted by the gamma function. I’m hoping we can cover this at some point so I can understand exactly how to approach the problem. Did you want us to hand solve this, use r or some combination? I had assumed this was a r task since we were using R to solve the early problems. Anyways, for problem 7 & 8, I could certainly use some insights. Thanks! Donny

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.


With the following matrix, \(X = \begin{bmatrix}1 & 2 & 3 \\ 3 & 3 & 1 \\ 4 & 6 & 8\end{bmatrix}\)

myMatrix <- matrix(c(1,3,4,2,3,6,3,1,8),3,3)
myMatrix
     [,1] [,2] [,3]
[1,]    1    2    3
[2,]    3    3    1
[3,]    4    6    8

  1. Invert it using Gaussian row reduction.
library(matlib)
gaussianElimination(myMatrix, numeric(3))
     [,1] [,2] [,3] [,4]
[1,]    1    0    0    0
[2,]    0    1    0    0
[3,]    0    0    1    0
gaussianElimination(myMatrix, 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
inv(myMatrix)
     [,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.
det(myMatrix)

  1. Conduct LU decomposition
lum <- lu(myMatrix)
elu <- expand(lum)

(L <- elu$L)
3 x 3 Matrix of class "dtrMatrix" (unitriangular)
     [,1]       [,2]       [,3]      
[1,]  1.0000000          .          .
[2,]  0.7500000  1.0000000          .
[3,]  0.2500000 -0.3333333  1.0000000
(U <- elu$U)
3 x 3 Matrix of class "dtrMatrix"
     [,1]       [,2]       [,3]      
[1,]  4.0000000  6.0000000  8.0000000
[2,]          . -1.5000000 -5.0000000
[3,]          .          . -0.6666667
(P <- elu$P)
3 x 3 sparse Matrix of class "pMatrix"
          
[1,] . . |
[2,] . | .
[3,] | . .
L %*% U
3 x 3 Matrix of class "dgeMatrix"
     [,1] [,2] [,3]
[1,]    4    6    8
[2,]    3    3    1
[3,]    1    2    3

  1. Multiply the matrix by it’s inverse.
inv <- round(solve(myMatrix),2)
myMatrix%*%inv
     [,1] [,2] [,3]
[1,]    1    0    0
[2,]    0    1    0
[3,]    0    0    1
LS0tCnRpdGxlOiAiV2VlayAxIC0gRG9ubnkgTG9mbGFuZCIKb3V0cHV0OiBodG1sX25vdGVib29rCi0tLQpgYGB7cn0KbGlicmFyeShE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