```{r data generation, echo = FALSE, results = "hide"}
library("exams")
library("exams.forge")
instruction <- NULL
#variables
t   <- 1:5
a   <- sample((40:80)/10, 1)
b   <- sample((-10:10)/10, 1)
xt  <- a+b*t+round(rnorm(length(t), sd=0.1), 2)
tab <- matrix(xt, ncol=1, dimnames = list(t, "Quote $x_t$"))
htab <- html_matrix_sk(tab, '$t$', fmt="%.2f")
#solution
sum_x <- sum(xt)
sum_t <- sum(t)
sum_tt <- sum(t^2)
sum_t_2 <- sum_t*sum_t
sum_x_t <- sum(xt*t)
a <- (sum_x*sum_tt - sum_t*sum_x_t)/(5*sum_tt - sum_t_2)
b <- (mean(xt)-mean(a))/mean(t)
ab <- runif(1)<0.5
sc <- num_result(if(ab) a else b, 4)
```

Question
========

```{r, error=TRUE, child=instruction}
```

Gegeben ist die Arbeitslosenquote von Berlin. Bestimmen Sie den Koeffizienten `r if(ab) "$a$" else "$b$"` der linearen Trendfunktion für die Arbeitslosenquote (in Prozentwerten).  `r round_de(sc$digits)`.

```{r, echo=FALSE, results='asis'}
cat(toHTMLorLatex(htab))
```

Solution
========

\begin{eqnarray*}
a &=& \frac{\sum_{t=1}^T x_t \cdot \sum_{t=1}^T t^2 - \sum_{t=1}^T t \cdot \sum_{t=1}^T x_t \cdot t}{T \cdot \sum_{t=1}^T t^2 - (\sum_{t=1}^T t)^2} \\
a &=& \frac{ `r sum_x` \times  `r sum_tt` -  `r sum_t` \times  `r sum_x_t`} {5 \times  `r sum_tt` -  `r sum_t_2` } \\
a &=&  `r a` \\
b &=& \frac{\bar{x}-a}{\bar{t}} \\
b &=& \frac{ `r mean(xt)`- `r a`}{ `r mean(t)`}  \\
b &=&  `r b`
\end{eqnarray*}

Meta-information
================
extype: num
exsolution: `r sc$fx[1]`
extol: `r sc$tolerance`
exname: zr-trend-1.Rmd
