Advertisement
Guest User

Untitled

a guest
Mar 27th, 2015
190
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.17 KB | None | 0 0
  1. f[x_] := Exp[2/(Abs[x - 1] + 1)]*Exp[-(x/2)^6]; (* artificially produced cusped function; in actual case this will produced numerically *)
  2.  
  3. xi = -4; (* initial point on the grid *)
  4. xf = +4; (* final point on the grid *)
  5. nPts = 1000; (* nr of points on the grid *)
  6. d = (xf - xi)/(nPts - 1); (* distance between two points on the (uniform) grid *)
  7. data = Table[N[{xi + i*d, f[a + i*d]}], {i, 0, nPts - 1}]; (* grid points *)
  8. splFunct = Interpolation[data, Method -> {"Spline"}]; (* interpolating spline from the numerically produced data points *)
  9. g[x_] := Piecewise[{{splFunct[x], xi <= x <= xf}}, 0]; (* a function which is equivalent to the spline function on the interval [xi , xf], and vanishes outside *)
  10.  
  11. intg[x_, c1_, c2_] := g[x]*g[x - c1]*g[x - 2 c2]; (* integrand made from a product of functions with different offsets in the argument, c1 and c2 *)
  12.  
  13. (* integration for each point on the grid; the result is stored in 'intgResult': *)
  14. Timing[
  15. intgResult = Table[{data[[i, 1]],
  16. NIntegrate[intg[x, data[[i, 1]], data[[i, 1]]], {x, xi, xf},
  17. Method -> {Automatic, "SymbolicProcessing" -> 0},
  18. AccuracyGoal -> 10, MaxPoints -> 2000]},
  19. {i, 1, Length[data]}];
  20. ]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement