3
$\begingroup$

Say I have a list $E$ and want to build a list $F$ with the entries $F_j=E_j-2E_{j-1}+E_{j-2}$. I know that this happens to be achievable by iterating the function Differences , but is there a way how to generalize this to different linear combinations?

$\endgroup$
2
  • $\begingroup$ Related: (4061) $\endgroup$
    – Mr.Wizard
    Jan 23 '15 at 23:05
  • $\begingroup$ This looks like a finite difference stencil. See detailed docs for NDSolve for higher order schemes ...if that is what you mean by different linear combinations $\endgroup$ Jan 24 '15 at 0:08
7
$\begingroup$
ListConvolve[{1, -2, 1}, mylist]

Example

mylist = RandomInteger[10, {10}]

(* {5, 4, 10, 1, 7, 1, 7, 0, 8, 4} *)

ListConvolve[{1, -2, 1}, mylist]

(* {7, -15, 15, -12, 12, -13, 15, -12} *)

$\endgroup$
2
  • 1
    $\begingroup$ Perhaps an easier to follow example: mylist = f/@ Range@10; ListConvolve[{1, -2, 1}, mylist] $\endgroup$ Jan 23 '15 at 18:33
  • $\begingroup$ Yes. Quite clear. $\endgroup$ Jan 23 '15 at 18:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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