2
$\begingroup$

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]:
Dϕ:=Dt[ϕ[t],{t,1}];
derPhi[x_?NumericQ]:=If[x>= 0 && x<= 15,Dϕ[x],0];
NIntegrate[derPhi[x],{x,0.25,0.5}];
$\endgroup$
2
  • $\begingroup$ Ayoub, please check that my translation still faithfully represents your original question. $\endgroup$
    – MarcoB
    Commented Dec 14, 2019 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$ Commented Dec 15, 2019 at 0:55

2 Answers 2

3
$\begingroup$

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 *)
$\endgroup$
1
  • 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
    Commented Dec 14, 2019 at 15:10
3
$\begingroup$

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:

derPhi["InterpolationOrder"]
   {1}

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]
   63

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}]
   0.009721637451048174
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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