I have a function defined by its slope in a continuous sequence of intervals, e.g.
intervals = {{0, 10}, {10, 15}, {15, 25}} slopes = {4, 5, 6} fun = Piecewise@MapThread[{#2*(b - #1[[1]]), #1[[1]] < b <= #1[[2]]} &, {intervals,slopes}] Plot[fun, {b, Min@Flatten@intervals, Max@Flatten@intervals}] 
I would like this function to be continuous. What I thought is to accumulate the constants one interval at a time and then go through and add them back to the function, which works fine but is in principle O(N) in the number of intervals:
constants = Prepend[Accumulate[fun /. ({b -> #} & /@ (intervals\[Transpose][[2]]))][[;; -2]], 0] funWithConstants = Piecewise@MapThread[{#1[[1]] + #2, #1[[2]]} &, {fun[[1]], constants}] Plot[funWithConstants, {b, Min@Flatten@intervals,Max@Flatten@intervals}] 
Then I noticed in the documentation for Piecewise that there seems to be a native way to compute the necessary constants for the integral of the function:
Integrate[fun, b] Plot[%, {b, Min@Flatten@intervals, Max@Flatten@intervals}] 
Is there a way to use this native algorithm find such constants for the function itself? I would guess it is probably faster then mine, and maybe faster than O(N).