Forward difference: Difference between revisions

no edit summary
(Add Swift)
No edit summary
Line 1,522:
function dift(t) return {dif(unpack(t))} end
print(unpack(dift{1,3,6,10,15}))</lang>
 
=={{header|M2000 Interpreter}}==
<lang M2000 Interpreter>
Form 80, 40
Module Forward_difference {
Print $(0,6) ' 6 characters column
Dim a(), b()
a()=(90,47,58,29,22,32,55,5,55,73)
Function Diff(a()) {
dim b(len(a())-1)
for i=0 to len(b())-1: b(i)=a(i+1)-a(i):Next i
=b()
}
Print "Original:","",a()
b()=a() ' copy a() to b()
k=1
While len(b())>1 {
b()=Diff(b()) ' copy returned array to b()
Print "Difference ";k;":",b()
k++
}
}
Forward_difference
 
</lang>
{{out}}
<pre style="height:30ex;overflow:scroll">
Original: 90 47 58 29 22 32 55 5 55 73
Difference 1: -43 11 -29 -7 10 23 -50 50 18
Difference 2: 54 -40 22 17 13 -73 100 -32
Difference 3: -94 62 -5 -4 -86 173 -132
Difference 4: 156 -67 1 -82 259 -305
Difference 5: -223 68 -83 341 -564
Difference 6: 291 -151 424 -905
Difference 7: -442 575 -1329
Difference 8: 1017 -1904
Difference 9: -2921
</pre >
 
=={{header|Mathematica}} / {{header|Wolfram Language}}==
Anonymous user