MathGroup Archive 2001

[Date Index] [Thread Index] [Author Index]

Search the Archive

RE: RE: Fast Integration of a product of 2 interpolating function s


Earlier I wrote:
---------------------
> Sebastien de Menten de Horne  wanted to efficiently Integrate the product
> of two IntegratingFunctions.  I think the following will work.
> 
>  f=FunctionInterpolation[ Cos[x + y] + y^2, {x, -1., 1}, {y, -1., 1}];
>  g=FunctionInterpolation[ Exp[y] + z/(y + 2), {y, -1., 1}, {z, -1., 1}];
>  h=FunctionInterpolation[ f[x,y] g[y,z], {x,-1.,1.}, {y,-1.,1.},
> {z,-1.,1.}];
>  int[x_,z_]:=Integrate[ h[x,y,z], {y, -1, 1} ]
> 
> 
> The following standard package might also be helpful.
>      NumericalMath`NIntegrateInterpolatingFunct`
> 
	-----------------------
	We can do much better because the code above performs the
integration every time (int[x,z]) is used.  Instead the following should be
used to allow faster evaluation of  int[x,z].

	f=FunctionInterpolation[ Cos[x + y] + y^2, {x, -1., 1}, {y, -1.,
1}];
	g=FunctionInterpolation[ Exp[y] + z/(y + 2), {y, -1., 1}, {z, -1.,
1}];
	h=FunctionInterpolation[ f[x,y] g[y,z], 
	   {x,-1.,1.}, {y,-1.,1.}, {z,-1.,1.}
	];
	Clear[x,z]
	int[x_,z_]=Integrate[ h[x,y,z], {y, -1, 1} ]

	---------------
	Notice I use    int[x_,z_] =
	rather than     int[x_,z_] :=   
	to ensure the integration is only done when (int) is defined. 

	Use of   Clear[x,z]   is recommended since this would not work right

	if (x), or (z) have global values when (int) is defined.

> --------------------
> Regards,
> Ted Ersek
> 


  • Prev by Date: Name of a list
  • Next by Date: Re: How to get the slope of a Interpolation[] function at a specified point?
  • Previous by thread: Re: Name of a list
  • Next by thread: Summary: Random Sampling Without Replacement