This is my r code to calculate beta values for each case which is pretty simple
data =data.frame(
  "t" = seq(0, 1, 0.001)
)
B3t <- function(t){
  t**3 - 1.6*t**2 +0.76*t+1
}
B2t <- function(t){
  ifelse(t >= 0 & t < 0.342,
         ((t-0.5)^2-0.025),
         ifelse( data$t >=  0.342 & data$t <= 0.658, 
                 0,
                 ifelse(t >  0.658 & t <= 1, 
                        (-(t-0.5)^2+0.025),
                        0
                 )))
}
B1t <- function(t){
  0
}
X1t <- function(t){
  a0 = rnorm(1)
  a1 = rnorm(1)
  a2 = rnorm(1)
  a3 = rnorm(1)
  return(a0 + a1*t + a2*(t^2) + a3*(t^3))
}
X2t <- function(t){
  a0 = rnorm(1)
  a1 = rnorm(1)
  a2 = rnorm(1)
  a3 = rnorm(1)
  a4 = rnorm(1)
  return(a0 + a1 * sin(2*pi*t) + a2 * cos(2*pi*t) + a3 * sin(4*pi*t) + a4 * cos(4*pi*t))
}
Now I want to calculate the error term.
I have one issue: Can anyone help me with this question?
- How do I solve the double integration in order to calculate the error term.
 
I know there are functions in r to do integrate but I am not sure how do I implement it here.
I am trying to do functional data analysis problem mentioned below:
What I don't know is how to find the variance in order to find the error term which follows normal distribution N(0, variance)


