2016 Update
This commit is contained in:
parent
948b86eafa
commit
dcf5d15da3
7965 changed files with 139854 additions and 31002 deletions
|
|
@ -1,6 +1,14 @@
|
|||
Provide code that produces a list of numbers which is the n-th order forward difference, given a non-negative integer (specifying the order) and a list of numbers.
|
||||
The first-order forward difference of a list of numbers (A) is a new list (B) where B<sub>n</sub> = A<sub>n+1</sub> - A<sub>n</sub>. List B should have one fewer element as a result.
|
||||
The second-order forward difference of A will be tdefmodule Diff do
|
||||
;Task:
|
||||
Provide code that produces a list of numbers which is the <big>n<sup>th</sup></big> order forward difference, given a non-negative integer (specifying the order) and a list of numbers.
|
||||
|
||||
|
||||
The first-order forward difference of a list of numbers <big>'''A'''</big> is a new list <big>'''B'''</big>, where <big><b>B</b><sub>n</sub> = <b>A</b><sub>n+1</sub> - <b>A</b><sub>n</sub></big>.
|
||||
|
||||
List <big>'''B'''</big> should have one fewer element as a result.
|
||||
|
||||
The second-order forward difference of <big>'''A'''</big> will be:
|
||||
<pre>
|
||||
tdefmodule Diff do
|
||||
def forward(arr,i\\1) do
|
||||
forward(arr,[],i)
|
||||
end
|
||||
|
|
@ -16,14 +24,22 @@ The second-order forward difference of A will be tdefmodule Diff do
|
|||
def forward([val1|[val2|vals]],diffs,i) do
|
||||
forward([val2|vals],diffs++[val2-val1],i)
|
||||
end
|
||||
endhe same as the first-order forward difference of B.
|
||||
That new list will have two fewer elements than A and one less than B.
|
||||
end
|
||||
</pre>
|
||||
The same as the first-order forward difference of <big>'''B'''</big>.
|
||||
|
||||
That new list will have two fewer elements than <big>'''A'''</big> and one less than <big>'''B'''</big>.
|
||||
|
||||
The goal of this task is to repeat this process up to the desired order.
|
||||
|
||||
For a more formal description, see the related [http://mathworld.wolfram.com/ForwardDifference.html Mathworld article].
|
||||
For a more formal description, see the related [http://mathworld.wolfram.com/ForwardDifference.html Mathworld article].
|
||||
|
||||
Algorithmic options:
|
||||
*Iterate through all previous forward differences and re-calculate a new array each time.
|
||||
*Use this formula (from [[wp:Forward difference|Wikipedia]]):
|
||||
:<math>\Delta^n [f](x)= \sum_{k=0}^n {n \choose k} (-1)^{n-k} f(x+k)</math>
|
||||
:([[Pascal's Triangle]] may be useful for this option)
|
||||
|
||||
;Algorithmic options:
|
||||
* Iterate through all previous forward differences and re-calculate a new array each time.
|
||||
* Use this formula (from [[wp:Forward difference|Wikipedia]]):
|
||||
<big><big>
|
||||
::: <math>\Delta^n [f](x)= \sum_{k=0}^n {n \choose k} (-1)^{n-k} f(x+k)</math>
|
||||
</big></big>
|
||||
::: ([[Pascal's Triangle]] may be useful for this option.)
|
||||
<br><br>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue