|
Polynomial addition
PROBLEM
We wish to perform calculations such as (2 + 3*X + 6*X**2) + (2 - X**2) = (4 + 3*X + 5*X**2)
When polynomials are represented by the arrays, then following procedure is a straightforward implementation of polynomial addition:
IMPLEMENTATION
Unit:
nonrecursive internal subroutine
Global variables: an array A. of N+1 coefficients, an array B. of N+1 coefficients. Parameter: a positive integer N - a degree of the A. and B. polynomials. Result: The A. array includes coefficients of polynomial addition.
EXAMPLE
(12*X**54 + 65*X**80 + 3*X*10000) +
(3*X**12 - 13*X**54 + 13*X**98 + 7*X**10000) = 3*X**12 - X**54 + 65*X*80 + 13*X*98 + 10*X**10000
displays on the screen
SPARSE POLYNOMIALS
For processing "sparse" polynomials with many zero coefficients, we can have array nodes represent only the nonzero terms. A sparse polynomial A.N*X**N+...+A.J*X**J+...+A.1*X+A.0 can be represented by an ascending sequence of pairs J A.J only for nonzero coefficients A.J.
IMPLEMENTATION
Unit:
nonrecursive internal subroutine
Global variables: an ascending sequence A. of M couples coefficient power, an ascending sequence B. of N couples coefficient power, and an output array C. as result of polynomial addition Parameters: positive integers M, N - size of the A. and B. arrays. Result: Returns size of the C. array. The C. array includes couples represent of polynomial addition.
EXAMPLE
The following fragment of program
displays on the screen
CONNECTIONS
Evaluating the Polynomials
Evaluation of polynomial and its derivatives (simultaneously) Division of polynomials Merging
|
|
|
|
|
|
![]()