I ran into problems integrating a function which contains both an If condition and a Wavelet which is an InterpolatingFunction knowing that the values of Phi are very small

ϕ:= WaveletPhi[DaubechiesWavelet[8],x]:
derPhi[x_?NumericQ]:=If[x>= 0 && x<= 15,Dϕ[x],0];
  • $\begingroup$ Ayoub, please check that my translation still faithfully represents your original question. $\endgroup$
    – MarcoB
    Dec 14 '19 at 15:58
  • 1
    $\begingroup$ I'd replace If with Piecewise since the latter is better suited for numeric functions while the former is intended more for programmatic use. $\endgroup$ Dec 15 '19 at 0:55

You introduce an unnecessary dummy variable x. This is my version

ϕ := WaveletPhi[DaubechiesWavelet[8]];
Dϕ := Derivative[1][ϕ];
derPhi[x_?NumericQ] := If[x >= 0 && x <= 15, Dϕ[x], 0];
NIntegrate[derPhi[x], {x, 0.25, 0.5}]

(* 0.00972165 *)

The numerical integration warns about slow convergence, presumably this is because of its many small discontinuities.

Is there a reason why you are differentiating and then integrating? Can't you just work with the original function?

ϕ[0.5] - ϕ[0.25]
(* 0.00972164 *)
  • 1
    $\begingroup$ Basically the integration is multiplication of many functions That i didn't montion. so the error shown is related to derPhi $\endgroup$
    – Ayoub
    Dec 14 '19 at 15:10

The approach taken in this answer is also applicable to this problem.

Construct the function to be integrated:

derPhi = Head[Simplify[D[WaveletPhi[DaubechiesWavelet[8], x], x], 0 < x < 15]]

Verify that we have a piecewise linear interpolant:


This means, we can use a low-order quadrature rule to evaluate (sub-)integrals between the interpolation points.

Verify how many interpolation points are used in the integration interval of interest:

Count[Flatten[derPhi["Grid"]], x_ /; 1/4 < x < 1/2]

We can then use the "InterpolationPointsSubdivision" method of NIntegrate[]. The count above is well within the default setting of "MaxSubregions", so that doesn't need to be adjusted:

NIntegrate[derPhi[x], {x, 1/4, 1/2}, 
           Method -> {"InterpolationPointsSubdivision", 
                      Method -> {"GaussKronrodRule", "Points" -> 2}, 
                      "SymbolicProcessing" -> 0}]

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.