1
$\begingroup$

The command

 ListCorrelate[{-1, 1}, {f1, f2, f3, f4, f5}]

yields

{-f1 + f2, -f2 + f3, -f3 + f4, -f4 + f5}

is there any simple way to get

{-f1 + f2, -f1 + f3, -f2 + f4, -f3 + f5, -f4 + f5}

using ListCorrelate or similar command? I need it to approximate derivative in numerical integration. Also interested in itself as list-manipulating technique.

Thanks in advance for any help.

$\endgroup$
  • 1
    $\begingroup$ Sorry, I cannot find a pattern in the desired output that you describe. Would you please add some detail? $\endgroup$ – Henrik Schumacher Dec 3 '18 at 21:43
5
$\begingroup$
ListCorrelate[{-1, 0, 1}, {f1, f2, f3, f4, f5}, {2, 2}, "Fixed"]

{-f1 + f2, -f1 + f3, -f2 + f4, -f3 + f5, -f4 + f5}

$\endgroup$
1
$\begingroup$

You can use ArrayPad to extend your list, and use the kernel {-1, 0, 1}:

list = {f1, f2, f3, f4, f5};

ListCorrelate[{-1, 0, 1}, ArrayPad[list, 1, "Fixed"]]

{-f1 + f2, -f1 + f3, -f2 + f4, -f3 + f5, -f4 + f5}

$\endgroup$
  • $\begingroup$ What is the functionality of {2, 2}, "Fixed"] ? $\endgroup$ – user61386 Dec 4 '18 at 7:36
  • $\begingroup$ Also: which is the right way of citing Mathematica output in a question? $\endgroup$ – user61386 Dec 4 '18 at 7:43

Your Answer

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