The error you’re getting basically means that Boost wasn’t able to do the integral and gave up.

The final error estimate it got was not less than `tolerance * norm_of_integral`

(see: https://www.boost.org/doc/libs/1_73_0/libs/math/doc/html/math_toolkit/double_exponential/de_tol.html).

I think what is happening is there are discontinuities in some of these integrals and that is blowing up the quadrature (which assumes some number of derivatives – I’m not sure how many, but dig around in the Boost docs).

I added a print statement to `U_total_integrand`

to see what values of `age`

for which this is failing:

```
real U_total_integrand(real age, real ac, real[] parms, real[] rdata, int[] idata){
real time = rdata[1];
real value;
print(age);
value = U_total_age(age, time, parms);
return value;
}
```

The output looked like:

```
> U_total_time(50, param_vec)
25
48.7842
1.2158
Error in U_total_time(50, param_vec) :
```

And then I made a plot of `U_total_kat`

:

```
x = 0.5
time = 50
age = 1.215850
xs = seq(1 / exp(1.0), 1.0, length = 1000)
ys = sapply(xs, function(x) {
U_total_kat(x, 1 - x, c(param_vec, time, age), c(0.0), c(1))
})
plot(xs, ys, type = "l")
```

And got this plot:

You’ll need to do integrals of functions with discontinuities in parts.

Also, and in some of these functions there are things being passed in `x_r`

that I think need appended to `parms`

and passed like that.

Like in the `U_total_kat`

function, unless you can guarantee that time and age are always not-parameters, you might want to add them to parms and do something like:

```
real U_total_kat(real ki, real ac, real[] parms, real[] x_r, int[] x_i){
int t0 = 5;
real time = parms[5];
real age = parms[6];
real value;
if (age < time - t0){
value = U_theta_akt(age, ki, time, parms);
} else if (age >= time - t0){
value = 0;
}
return value;
}
```

Edit: There were some out of date comments at the bottom here that I wrote a few days ago and didn’t post. Just editing them out since they aren’t so relevant now!