Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Function-type arguments in function definition

1 view
Skip to first unread message

Carsten Reckord

unread,
Nov 4, 2003, 3:30:44 AM11/4/03
to
Hi,

I'm pretty new to Mathematica so please excuse me if this is kind of a silly
question (though I couldn't find any answer after a full day of searching).
I'm trying to define functions that take other functions as arguments and
need those functions' arguments in their own definition. An example would be
the definition of convolution:

h(x)=f(x)*g(x) is defined as Integral over f(y)g(x-y) with respect to y.

As you can see it is important in the definition of convolution to treat the
arguments f and g as functions because the definition makes use of their
arguments.
I've seen this done in Mathematica as

convolute[f_,g_,x_]:=Integrate[f[y]*g[x-y],{y,-inf,inf}]

but that's not exactly what I'm looking for because I can only use function
names as arguments to convolute[...], not arbitrary expressions in x. So I
can't for example use it for the convolution f(s(x))*g(t(x)) without
defining intermediate functions for f(s(x)) and g(t(x))...

So, my question is if there is any way to define such a function that can
make use of its arguments being functions and yet supports arbitrary
expressions as its arguments?

Thanks,
Carsten


Jens-Peer Kuska

unread,
Nov 5, 2003, 10:31:28 AM11/5/03
to
Hi,


and

conv[f_, g_][x_] := Module[{y}, Integrate[f[y]*g[x - y], {y, a, b}]]


conv[#^2 &, Exp[-#] &][x]

does not what you whant ?

Regards
Jens

Paul Abbott

unread,
Nov 5, 2003, 11:22:32 AM11/5/03
to
In article <bo7o3k$aep$1...@smc.vnet.net>,
"Carsten Reckord" <ne...@reckord.de> wrote:

I would do this as follows. Define your convolution operation for pure
functions f and g with variable x as

Star[f_Function, g_Function][x_] :=
Integrate[f[y] g[x - y], {y, -Infinity, Infinity}]

If you now add a rule that converts f and g to pure functions (assumed
to be functions of x),

Star[f_,g_][x_] := Star[Function[x,f], Function[x,g]][x]

then you can compute convolutions of the type you require as

Star[f[s[x]], g[t[x]]][x]

(An aside: Mathematica already has an infix notation suitable for
convolution -- the Star operator. Above I've used the InputForm, Star,
which adds rules to Star, so that you can enter input expressions as

(f[s[x]] \[Star] g[t[x]])[x]

where \[Star] is converted to the appropriate special character on
input.)

Cheers,
Paul

--
Paul Abbott Phone: +61 8 9380 2734
School of Physics, M013 Fax: +61 8 9380 1014
The University of Western Australia (CRICOS Provider No 00126G)
35 Stirling Highway
Crawley WA 6009 mailto:pa...@physics.uwa.edu.au
AUSTRALIA http://physics.uwa.edu.au/~paul

Jean-Claude Poujade

unread,
Nov 5, 2003, 11:27:38 AM11/5/03
to
"Carsten Reckord" <ne...@reckord.de> wrote in message news:<bo7o3k$aep$1...@smc.vnet.net>...
If f and g are expressions, instead of functions,
one needs an extra argument telling the name
of the variable used in f and g (it's not necessarily 'x').
Example :
In[1]:=ClearAll[convolute];

convolute[f_,g_,x_]:=
Integrate[f[y]*g[x-y],{y,-Infinity,Infinity}];

(* 'u' is the variable used in expressions f and g *)
convolute[f_,g_,u_,x_]:=
Integrate[(f /. u -> y)*(g /. u ->(x-y)),{y,-Infinity,Infinity}];

In[2]:=f1[x_]:=E^(-x^2);
f2[x_]:=E^(-x^2);
convolute[f1,f2,x]
Out[2]=Sqrt[Pi/2]/E^(x^2/2)

In[3]:=exp1=E^(-u^2);
exp2=E^(-u^2);
convolute[exp1,exp2,u,x]
Out[3]=Sqrt[Pi/2]/E^(x^2/2)

---
jcp

0 new messages