3
$\begingroup$

I want to define some basic functions known from "discrete analysis":

$$I(f)(x):=f(x)$$ $$E(f)(x):=f(x+1)$$ $$\Delta(f)(x) := (E-I)(f)(x) = f(x+1)-f(x)$$ $$\nabla(f)(x) := (I-E^{-1})(f)(x) = f(x)-f(x-1)$$

And I know that I can define a function f[x_] := x^2 like that, but how can I take a function and evaluate it at the given position like E[fn_] := evaluate fn at x+1?

2 Answers 2

0

You can use the Apply command to make a definition such as Eval[f_,x_]:= Apply[f,{x}] (you can't use E as the name of your function, though - this is reserved by Mathematica for the number $e=2.71828\ldots$).

For example:

F[x_]:=x^2+1
Eval[f_,x_]:= Apply[f,{x}]

Eval[F,5]=26
Eval[F,x+1]=1+(1+x)^2
Eval[F,x]=1+x^2

Then you can define

Delta[g_]:=FullSimplify[Eval[g,x+1]-Eval[g,x]]
Delta[F]=1+2x
  • 0
    It does not work like expected! E.g. $E(f)(x)$ is now called `TranslateEx`. `TranslateEx[fn_] := Apply[fn, {x + 1}]` and then `TranslateEx[x]` leads to the result `x[1 + x]`. What does this mean? I expected `x + 1` as the result. **EDIT** It seems i cannot enter a function directly and i need to specify it explicitly...2011-10-08
  • 0
    @Christian: `x` by itself *is not a function*. You need to define a function `g[x_]:=x`, and *then* you can do `TranslateEx[g]=1+x`.2011-10-08
  • 0
    Is there any way, like in programming languages, to define an "anonymous function" (a.k.a. lambda-expression) the way i tried?2011-10-08
  • 1
    You might be able to do it [with the `Function` command](http://reference.wolfram.com/mathematica/ref/Function.html), but I'm not familiar with it myself.2011-10-09
  • 3
    eval[k_][f_]:=f[k]2011-10-09
6

Actually, for Mathematica 7 and later versions, you have the functions Identity[], DiscreteShift[], and DifferenceDelta[]:

Identity[f[x]]
f[x]

DiscreteShift[f[x], x]
f[1 + x]

DifferenceDelta[f[x], x]
-f[x] + f[1 + x]

The backward difference needs a bit more work:

DifferenceDelta[DiscreteShift[f[x], {x, 1, -1}], x]
-f[-1 + x] + f[x]

Otherwise:

bdf[f_, x_] := f - (f /. x -> x - 1)

bdf[f[x], x]
-f[-1 + x] + f[x]

In fact, Mathematica supports more traditional notation (see the manual for details):

shifts and differences