First, I'll break down the function you're convolving. It's a real mess:
(-E^(-2*x) + E^(-x))*(7 - 3*Piecewise[{{1, -E^(-2*x) + E^(-x) >= 0}}, 0]) +
(-E^(-2*x) + 2/E^x)*(2 - 2*Piecewise[{{1, -E^(-2*x) + 2/E^x >= 0}}, 0]) +
(1/(4*E^(2*x)) - 2/E^x + (7 - 6*x + 2*x^2)/4)*
(3 - 2*Piecewise[{{1, 1/(4*E^(2*x)) - 2/E^x + (7 - 6*x + 2*x^2)/4 >= 0}},
0]) +
(150 - 100*Piecewise[{{1, 2/(5*E^(2*x)) - 1/(2*E^x) + (10*Cos[x] + 30*Sin[x])/
100 >= 0}}, 0])*(2/(5*E^(2*x)) - 1/(2*E^x) +
(10*Cos[x] + 30*Sin[x])/100)
Looking at the definition a little more closely, I can see that each of your auxiliary functions takes the form:
Piecewise[{{1, expr >= 0}, {0, expr <= 0}}]
(The desired behavior when expr == 0
is not clear; Mathematica will use the first matching condition, but we will see later that it doesn't matter.) This form can be simplified much further:
Piecewise[{{1, expr >= 0}}, 0] (* using a default value *)
Piecewise[{{1, expr >= 0}}] (* using the default default value *)
UnitStep[expr] (* using a built-in function *)
Now going back to the full expression, I notice that it is a sum of four components. Each component consists of one of the auxiliary functions, scaled and shifted, then multiplied by the function in the auxiliary function's comparison. That is, each term is equivalent to this form:
term[{a_, b_}, expr_] := (a + b UnitStep[expr]) expr
So effectively, each term is scaled differently when it is positive and when it is negative (the particular values in this problem are chosen so that Sign[term[_, expr]] == Sign[expr]
, i.e. a > 0
and a + b > 0
). When expr == 0
the value of the term is just 0
.
Now, let's see what these terms actually are:
Exp[-x] - Exp[-2x]
2Exp[-x] - Exp[-2x]
Exp[-2x]/4 - 2Exp[-x] + (2x^2 - 6x + 7)/4
2/5Exp[-2x]-Exp[-x]/2 + Cos[x]/10 + 3/10Sin[x]
Using Reduce
we can find the region in which the first three are nonnegative:
x >= 0
x >= -Log[2]
True
I'll define a helper function to convolve each term separately:
smooth[{a_, b_}, expr_] :=
FullSimplify[
Convolve[(a +
b PiecewiseExpand[Boole@Reduce[expr >= 0, x, Reals]]) expr,
Exp[-x^2/2]/Sqrt[2 Pi], x, y], y \[Element] Reals]
For example, the first term after smoothing results in:
1/2 E^(-2 y) (E^2 (-11 + 3 Erf[(-2 + y)/Sqrt[2]]) +
E^(1/2 + y) (8 + 3 Erfc[(-1 + y)/Sqrt[2]]))
Not too simple, but at least we got it. Let's take a look to see how it did:
Hm, it seems as if our smoothing kernel has had an additional side effect of muliplying our function by a factor of around 100. When we convolve a gaussian with an exponential:
FullSimplify[
Convolve[Exp[λ x], Exp[-(x/σ)^2/2]/Sqrt[2 Pi]/σ, x, y],
σ > 0]
the result is the exponential shifted by λ σ^2/2
:
E^(y λ + (λ^2 σ^2)/2)
Unfortunately I don't know of a smoothing filter that can avoid this.
And there is another problem: the fourth term actually cannot be Reduce
d because its roots are non-analytic. Look what I mean:
The purely sinusoidal part of the term has roots at 2 ArcTan[3 + Sqrt[10]] + Pi C[1]
, but the exponential part perturbs each root by a small amount. Each of the new roots has no closed-form solution, and each one is shifted by a different amount! Plus, smoothing the sinusoidal part changes the magnitude by a factor of 1/Sqrt[E]
, probably not what you want. (Again, most smoothing filters will have this type of effect.)
If smoothing the discontinuities is all that you want to achieve, I suggest a different method: modify the term[{a, b}, expr]
function to remove the discontinuity at the source!
smoothTerm[{a_, b_}, expr_, scale_: 1] :=
(a + b (Erf[expr/scale] + 1)/2) expr
You can replace (Erf[#] + 1)/2 &
with whatever smoothing function you want. Here is a comparison of term[{5, -4}, x]
and smoothTerm[{5, -4}, x, 3/2]
:
I hope you find this useful!
Exp[-x]
when looking at its roots when combined withCos
andSin
, and can we use a piecewise approximation instead of a Gaussian kernel? Basically the problem as stated is difficult to work, but if we can go 'back up the chain' a little, we might find a simplification to make things easier. $\endgroup$