How to resolve the algorithm Forward difference step by step in the BBC BASIC programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Forward difference step by step in the BBC BASIC programming language
Table of Contents
Problem Statement
Provide code that produces a list of numbers which is the nth 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 Bn = An+1 - An. List B should have one fewer element as a result. The second-order forward difference of A will be: The same as the first-order forward difference of B. That new list will have two fewer elements than A and one less than B. The goal of this task is to repeat this process up to the desired order. For a more formal description, see the related Mathworld article.
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Forward difference step by step in the BBC BASIC programming language
Source code in the bbc programming language
DIM A(9)
A() = 90.0, 47.0, 58.0, 29.0, 22.0, 32.0, 55.0, 5.0, 55.0, 73.0
PRINT "Original array: " FNshowarray(A())
PROCforward_difference(1, A(), B())
PRINT "Forward diff 1: " FNshowarray(B())
PROCforward_difference(2, A(), C())
PRINT "Forward diff 2: " FNshowarray(C())
PROCforward_difference(9, A(), D())
PRINT "Forward diff 9: " FNshowarray(D())
END
DEF PROCforward_difference(n%, a(), RETURN b())
LOCAL c%, i%, j%
DIM b(DIM(a(),1) - n%)
FOR i% = 0 TO DIM(b(),1)
b(i%) = a(i% + n%)
c% = 1
FOR j% = 1 TO n%
c% = -INT(c% * (n% - j% + 1) / j% + 0.5)
b(i%) += c% * a(i% + n% - j%)
NEXT
NEXT
ENDPROC
DEF FNshowarray(a())
LOCAL i%, a$
FOR i% = 0 TO DIM(a(),1)
a$ += STR$(a(i%)) + ", "
NEXT
= LEFT$(LEFT$(a$))
You may also check:How to resolve the algorithm Quaternion type step by step in the Oforth programming language
You may also check:How to resolve the algorithm Empty string step by step in the Stata programming language
You may also check:How to resolve the algorithm Multiplication tables step by step in the 8080 Assembly programming language
You may also check:How to resolve the algorithm Walk a directory/Non-recursively step by step in the Rust programming language
You may also check:How to resolve the algorithm DNS query step by step in the Racket programming language