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 
  • 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