Take the 2-minute tour ×
Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. It's 100% free, no registration required.

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?

share|improve this question

2 Answers 2

up vote 0 down vote accepted

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
share|improve this answer
    
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... –  Christian Ivicevic Oct 8 '11 at 23:52
    
@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. –  Zev Chonoles Oct 8 '11 at 23:56
    
Is there any way, like in programming languages, to define an "anonymous function" (a.k.a. lambda-expression) the way i tried? –  Christian Ivicevic Oct 8 '11 at 23:57
1  
You might be able to do it with the Function command, but I'm not familiar with it myself. –  Zev Chonoles Oct 9 '11 at 0:00
3  
eval[k_][f_]:=f[k] –  Gus Wiseman Oct 9 '11 at 0:08

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

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.