Wednesday, December 5, 2012

Numeric CAS - Part 9: Indefinite Integrals of Polynomial

Indefinite Integral of a Polynomial

Goal: Determine the coefficients of the indefinite integral of the polynomial p(X) where

p(X) = a_n * x^n + a_(n-1) * x^(n-1) + ... + a1 * x + a0

and

∫ p(X) dX = a_n * x^(n+1) ÷ (n+1) + a_(n-1) * x^n ÷ n + ... + a0 * x + c

Where c is a constant. This constant is determined by the initial condition (x_0, p_0). The programs assume that c = 0, which is common in computer algebraic systems.

Where a_n, a_(n-1), ... , a1, a0 are stored in lists. The coefficients are listed in order of descending powers of x. Use zeros as placeholders.

Example:

∫ -2x^2 + 4x - 6 dx = -2/3 * x^3 + 2x^2 - 6x
Input List: {-2, 4, -6}
Output List: {-2/3, 2, -6, 0} or
{-0.666666667, 2, -6, 0}

∫ x^4 + 3x^2 - x dx = 1/5 * x^5 + x^3 - 1/2 * x^2
Input List: {1, 0, 3, -1, 0}
Output List: {1/5, 0, 1, -1/2, 0, 0} or
{0.2, 0, 1, -0.5, 0, 0}

For all three programs, the input is List 1, the output is List 2.


Casio Prizm:

POLYINT
Indefinite Polynomial Integral - 140 bytes

"∫ (P(X)) dX"
"{AnX^n,...,A0}"
"LIST="?→List 1
List 1 → List 2
For 1→K To Dim List 1
List 2[K] ÷ (Dim List 2 + 1 - K) → List 2[K]
Next
Augment(List 2,{0}) → List 2
List 2


TI-84+:

POLYINT
Polynomial Indefinite Integral - 117 bytes

: Disp "fnInt(P(X)) DX", "{AnX^n,...,A0}"
: Input "LIST:", L1
: L1 → L2
: For(K,1,dim(L2))
: L2(K)/(dim(L2)-K+1) → L2(K)
: End
: augment(L2,{0}) → L2
: Pause L2


HP 39gii:

Polynomial Integral
POLYINT()
Same input as above

EXPORT POLYINT()
BEGIN
LOCAL K,S;
EDITLIST(L1);
SIZE(L1)→S;
{ } → L2;
FOR K FROM 1 TO S DO
CONCAT(L2, {(S-K+1)⁻¹ * L1(K)}) → L2;
END;
CONCAT(L2,{0})→ L2;
RETURN L2;
END;




This blog is property of Edward Shore. 2012

No comments:

Post a Comment

Adventures in Python: Plotting Sine and Cosine, The numpy Module

Adventures in Python:  Plotting Sine and Cosine, The numpy Module This program will require that you have both numpy and matplotlib.  ...