Showing posts with label binomial expansion. Show all posts
Showing posts with label binomial expansion. Show all posts

Saturday, January 29, 2022

Binomial Expansion in Two Methods

Binomial Expansion in Two Methods


Expanding the Binomial by Two Methods


There are two ways to obtain the coefficients of expanding the binomial in the form (a ∙ x + b)^n:


1.  Binomial Theorem:


(a ∙ x + b)^n = Σ(comb(n, k) ∙ (a ∙ x)^k ∙ b^(n -k), k=0, n)

where comb(n,k) = n! ÷ (k! × (n - k)!)



2.  Maclaurin Series (Taylor series at point x=0):


f(x) = (a ∙ x + b)^n

f(x) =  f(0) + f'(0) ∙ x + f''(0)÷2! ∙ x^2 + f'''(0)÷3! ∙ x^3 + ... + f^n(0)÷n! ∙ x^n


Let's illustrate this through several examples.


Example 1:   (2∙x+3)^2


Binomial Theorem:

(2∙x+3)^2 

= comb(2,0)∙(2∙x)^2 + comb(2,1)∙(2∙x)∙3 + comb(2,2)∙3^2

= 4∙x^2 + 12∙x + 3


Maclaurin Series:

f(x) = (2∙x+3)^2,  f(0)=9

f'(x) = 4∙(2∙x+3), f'(0)=12

f''(x) = 8,  f''(0)=8

(2∙x+3)^2 = 9 + 12÷1! ∙ x + 8÷2! ∙ x^2 = 9 + 12∙x + 4∙x^2


Example 2:   (x + 5)^3


Binomial Theorem:

(x+5)^3

= comb(3,0)∙x^3 + comb(3,1)∙x^2∙5 + comb(3,2)∙x∙5^2 + comb(3,3)∙5^3

= x^3 + 15∙x^2 + 75∙x + 125


Maclaurin Series:

f(x) = (x+5)^3, f(0) = 125

f'(x) = 3∙(x+5)^2, f'(0) = 75

f''(x) = 6∙(x+5), f''(0) = 30

f'''(x) = 6, f'''(0) = 6

(x + 5)^3 = 125 + 75÷1! ∙ x + 30÷2! ∙x^2 + 6÷3! ∙ x^3 

= 125 + 75∙x + 15∙x^2 + x^3


Example 3:  A general binomial:  (a∙x+b)^2


Binomial Theorem:

(a∙x+b)^2

= comb(2,0)∙(a∙x)^2 + comb(2,1)∙(a∙x)∙b + comb(2,2)∙b^2

= a^2∙x^2 + 2∙a∙b∙x + b^2


Maclaurin Series:

f(x) =  (a∙x+b)^2, f(0) = b^2

f'(x) = 2∙(a∙x+b)∙a, f'(0) = 2∙a∙b

f''(x) = 2∙a^2, f''(0) = 2∙a^2

(a∙x+b)^2 = b^2 + (2∙a∙b)÷1! ∙x + (2∙a^2)÷2! ∙x^2 = b^2 + 2∙a∙b∙x + a^2∙x^2

 


Two ways of obtaining the expansion of the binomial.   


Eddie 


Friday, March 20, 2020

Casio fx-9860g and fx-CG 50: Binomial Series

Casio fx-9860g and fx-CG 50: Binomial Series

Generating The Binomial Series

The binomial series (1 + b*x)^a can be generated by the series:

(1 + b*x)^a = 1 + a*b*x +  a*(a-1) / 2! * (b*x)^2 + a*(a-1)*(a-2) / 3! * (b*x)^3 + ....

= ∑ ( a NCR k) * (b * x)^k for k = 0 from ∞

where:

(a NCR k) = (a * (a - 1) * (a - 2) * ... * (a - k + 1) ) / k!

The values a and b can be complex and do not have to be integers.

If a is not a positive integer, the series continues on indefinitely. 

Output:  List 5 has the coefficients.  The program BINOMSRS calculates the coefficients and any approximation of that series (f(x)).

Casio fx-9860GII and fx-CG 50 Program BINOMSRS

Lbl 2
"2020-02-24 EWS"
"BINOMIAL SERIES"
"EXPAND (1+BX)^A"
"B"? → B
"A"? → A
Lbl 0
"TERMS (≥3)"? → T
Int T → T
T < 3 ⇒ Goto 0
T → Dim List 5
1 → List 5[1]
1 → N
For 2 → K To T
N (A - (K - 2)) → N
N ÷ (K - 1)! * B^(K - 1) → List 5[K]
Next
Lbl 1
Menu "MENU","LIST COEFS",C,"APPROX F(X)",E,"NEW SERIES",2,"EXIT",X
Lbl C
"COEFS IN List 5"
List 5 ◢
Goto 1
Lbl E
"X"? → X
Sum( List 5 * X^Seq(I, I, 0, T-1, 1) ) → Y
"F(X) IS ABOUT:"
Y ◢
Goto 1
Lbl X 
"DONE"

The program allows the user to evaluate the series for given values and create new series for different problems. 

Download the fx-9860gII and fx-9750gII version: 
https://drive.google.com/open?id=1fgxjwf4UkyxhY7XIWqx7HRQHJf-PKnbi

Download the fx-CG 50 and fx-CG 10/20 version:
https://drive.google.com/open?id=1H0Sq2-h6NcWFIw7_pM25PAHHQ2QKtKEy

Example

Expand (1 - x)^(1/2) to six terms.   Approximate f(0.35).

Hint:  Use the fraction key  ( [ a b/c ] or [ []/[] ] ) to get results in fractions (whenever possible). 

b = -1
a = 1/2
t = 6

Coefficients (List 5):
{1, -1/2, -1/8, -1/16, -5/128, -7/256}

(1 - x)^(1/2) ≈ 1 - 1/2 * x - 1/8 * x^2 - 1/16 * x^3 - 5/128 * x^4 - 7/256 * x^5

Approx F(X):  X = 0.35
Result:  0.8062780164


Eddie

All original content copyright, © 2011-2020.  Edward Shore.   Unauthorized use and/or unauthorized distribution for commercial purposes without express and written permission from the author is strictly prohibited.  This blog entry may be distributed for noncommercial purposes, provided that full credit is given to the author.

Monday, January 16, 2017

Fun with the Sharp EL-5500 III

Fun with the Sharp EL-5500 III


Even though the EL-5500 III has one programming space, we can fit many programs in it.  One of the great features is that how programs take relatively little space.  Obviously you can change the line numbers, the sequence of lines are most important.

Euclid Algorithm – RUN 10

10 PAUSE “GCD: A>B”
18 INPUT “A: “; A, “B: “; B
20 C = A – INT(A/B)*B
30 IF C = 0 THEN 40
32 A = B
34 B = C
36 GOTO 20
40 PRINT “GCD = “; B
46 END

My first program on the EL-5500 III.  We can probably make the coding more efficient.  PRINT with a proceeding WAIT pauses execution until [ ENTER ] is pressed.

The command END ends the program execution and allows the space to have more than one routines.

Examples:
A: 100, B: 20.  Result:  GCD = 20
A: 63, B: 60.  Result:  GCD = 3

Binomial Expansion – RUN 50

50 PAUSE “(Ax + B)^n”
55 INPUT “A: “;A, “B: “;B, “N: “,N
60 FOR I=0 TO N
65 C = FACT(N) / (FACT(I) * FACT(N-I))
70 T = C * A^(N-I) * B^I
75 PRINT T; “*x^”; N-I
80 NEXT I
85 END

The command PAUSE shows the text for about 0.85 seconds.

This program displays each coefficient one at time.

Example:  A = 3, B = -2, N = 3.  Expand (3 – 2x)^3.
Result:  27, -54, 36, -8  (27x^3 – 54x^2 + 36x – 8)

Days Between Dates – RUN 100

100 PAUSE “Days between Dates”
112 INPUT “M1:”; M1, “D1:”; D1, “Y1:”; Y1
113 INPUT “M2:”; M2, “D2:”; D2, “Y2:”; Y2
115 M = M1: D = D1: Y = Y1
117 GOSUB 140
119 F1 = F
121 M = M2: D = D2: Y = Y2
123 GOSUB 140
125 F2 = F
127 N = F2 – F1
129 PRINT “# DAYS: “; N
131 END
140 IF M > 2 THEN 150
142 X = 0: Z = Y – 1
144 GOTO 160
150 X = INT(.4 * M + 2.3): Z = Y
160 F = 365 * Y + 31* (M – 1) + D + INT(Z/4) – X
165 RETURN

If I had it my way, every calculator that isn’t a basic 4-function calculator will have a Days Between Dates function.

Example:  November 4, 1986 to January 12, 2017
M1:  11, D1: 4, Y1: 1986 
M2: 1, D2: 12, Y2: 2017
Result:  11,027

Power of a Complex Number – RUN 200

This calculates (a + bi)^n

200 PAUSE “(A + Bi)^n”
203 INPUT “A: “;A, “B: “;B, “n: “;N
205 IF A<>0 THEN 210
207 A = A^N: GOTO 220
210 R = √(A^2 + B^2)^N
212 T = ATN(B/A)*N
214 A = R * COS T
216 B = R * SIN T
220 PRINT A; “+”; B; “i”
225 END

The command <> means not equals (≠) and ATN is the arctangent function.

Examples:
(2 + 3i)^3:  A = 2, Bi = 3.  Result: -46 + 9i
(-5 + i)^2:  A = -5, Bi = 1.  Result: 24 – 10i

Error Function Approximation – RUN 250

250 PAUSE “APPROX ERF(X)”
252 CLEAR
254 DIM A(3)
256 E = 0
260 INPUT “X > 0 : “; X
262 T = RCP(1 + .47047 * X)
270 FOR I = 1 TO 3
272 READ A(I)
274 E = E + A(I) * T^I
276 NEXT I
280 DATA .3480242, -.0958798, .7478556
290 E = 1 – E * EXP(-(X^2))
292 PRINT “ERF : “, F
294 CLEAR
296 END

Use the command CLEAR to clear all the variables.  At this point, I will use this command both at the beginning and end of calculations.  The command RCP is the reciprocal.  Finally, EXP is from e^x function, not the [EXP] key.

Example:
x = 0.53, erf ≈ 0.546455764
x = 0.88, erf ≈ 7.86708E-01 = 0.786708

Keep in mind this approximation is accurate 2.5 parts in 10^-5.

Source:  Smith, Jon M.  Scientific Analysis on the Pocket Calculator  John Wiley & Sons: New York. 1975.  ISBN 0-471-79997-1

Simpson’s Rule – RUN 300

Calculates the numeric integral ∫ f(x) dx from x = L to x = U.

You can edit the function at line 342.  In BASIC-PRO mode, call up line 342 by LIST 342.  Edit as desired.

300 PAUSE “Simpsons Rule”
302 CLEAR
304 INPUT “LOWER: “; L, “UPPER: “; U, “PARTS (even): “; N
306 RADIAN
308 X = L: GOSUB 340: T = F
310 X = U: GOSUB 340: T = T + F
314 H = (U – L)/N
320 FOR I = 1 TO N-1
322 X = L + I * H: GOSUB 340
324 R = I/2 – INT(I/2)
326 IF R = 0 THEN LET T = T + 2*F
328 IF R <> 0 THEN LET T = T + 4*F
330 NEXT I
332 T = T * H/3
334 PRINT “Integral: “, T
336 CLEAR
338 END
340 REM f(x)
342 F = [insert f(X) here]
344 RETURN

Note:  I finally learn why LET is included in BASIC.  In an IF-THEN statement, if you want to assign a value or calculation to a variable, you will need a LET command.

I use a REM (remark) command on line 340.  REM is for comments and nothing said after REM is executed.

Examples:

342 F = X^2 – 1
L = -2, U = 2, N = 14.  Result:  1.333333334 (Actual: 4/3 ≈ 1.333333333)

342 F = √(X – 1)
L = 2, U = 3, N = 14.  Result: 1.218951372 (Actual:  ≈ 1.2158951416)

Dancing Star Demo – RUN 400

400 PAUSE “Dancing Star Demo”
405 CLEAR
410 S$ = “         “  (9 spaces)
415 FOR I = 1 TO 48
420 N = RND 7 + 1
425 T$ = MID$(S$, 1, N-1) + “*” + MID$(S$, N+1, 9-(N+1))
430 WAIT 15: PRINT T$
440 NEXT I
445 BEEP 3: CLEAR: END

This is just show a dancing asterisk (*) on the screen.

WAIT 15: PRINT T$:   This causes the string T$ after a quarter of a second.  WAIT operates in 1/60 seconds.

RND n:  This is the random command.  If n = 1, the result is between 0 and 1. 

BEEP n:  This makes the EL-5500 III beep n times. 

Eddie

This blog is property of Edward Shore, 2017.



Thursday, November 24, 2016

Casio fx-7400g Plus: Program Library

Casio fx-7400g Plus: Program Library


Contents:
* Polar Graphing (POLAR)
* Summation and Integration (FX, SUMFX, INTFX)
* Binomial Expansion (BINOMEXP)
* Forward Triangle Intersection (FORDINT)
* Coordinates of a Traverse (TRAVEZ)
* Quadratic Equation (QUAD)


The classic fx-7400g (we’re talking about the early 2000s) lacked numerical integration, summation, and polar graphing.  Let’s remedy that through programming.

Fortunately any of the programs created on the fx-7400g Plus can be translated literally to later Casio graphing calculators. 


Casio fx-7400g Plus Program POLAR
  
Program POLAR
ClrGraph
Rad
“THETA MIN”? → A
“THETA MAX”? → B
“THETA STEP”? → S
For A → I To B Step S
sin (2I) →  R       (see note below)
PlotOn R cos I, R sin I
Next
DrawGraph

Notes:
*  This is best used when the function list is clear.
*  Set up graph screen parameters (Xmin, Xmax, Ymin, Ymax) before hand.
*  Insert polar functions by editing the 7th line (in italics), using I for θ.  The result must be stored to R  (by → R).

Casio fx-7400g Plus Programs FX, SUMFX, INTFX

The programs SUMFX and INTFX will require the subroutine program FX.  FX is where you insert the function f(x).   The result is stored to Y. 

Program FX
X^2+1 → Y
Return

Program SUMFX
“LOWER”? → L
“UPPER”? → U
0 → T
For L → X To U
Prog “FX”
T + Y → T
Next
“SUM=”
T

Example:  FX contains X^2 +1, with L = 1, U = 15.  Result:  1255
Program INTFX
“LOWER”? → L
“UPPER”? → U
“NO. PARTS”? → N
Rad
L → X
Prog “FX”
Y → T
U → X
Prog “FX”
T + Y → T
(U – L) ÷ N → H
For 1 → I To N-1
L + I * H → X
Prog “FX”
If I Rmdr 2 = 0
Then T + 2*Y → T
Else T + 4*Y → T
IfEnd
Next
T * H ÷ 3 → T
“INTEGRAL=”
T

Example:  FX contains X^2 +1, with L = 1, U = 15, N = 24.  Result:  1138.666667

Casio fx-7400g Plus Program BINOMEXP

The program BINOMEXP shows the coefficients of the binomial expansion (Ax + B)^N.

Program BINOMEXP
“(AX+B)^N”
“A”? → A
“B”? → B
“N”? → N
For 0 → I To N
N nCr I * A^(N-I) * B^I → T
“{COEF, POWER}”
{T, N-I}
Next

Example:  (2x – 3)^2
Results:  {4, 2}, {-12, 1}, {9, 0}   (4x^2 – 12x + 9)


 Casio fx-7400g Plus Program FORDINT

The program FORDINT calculates the third point on a triangle where the coordinates of points A  (xa, xb) and B (xb, yb) are known.  Also, a line towards P point is aimed from point A at angle α° and from point B at angle β°. 

Variable
Casio fx-7400g Plus
Variable
Casio fx-7400g Plus
Variable
Casio fx-7400g Plus
xa
N
ya
S
α
A
xb
O
yb
T
β
B
xp
P
yc
U
γ
C


Source: Casio.   Casio fx-FD10 Pro User’s Guide Tokyo. 2014

Program FORDINT
Deg
“XA”? → N
“YA”? → S
“ANGLE A”? → A
“XB”? → O
“YB”? → T
“ANGLE B”? → B
1 ÷ tan A + 1 ÷ tan B → C
(N ÷ tan B + O ÷ tan A + (T – S)) → P
(S ÷ tan B + T ÷ tan A + (N – O)) → U
180 – A – B → C
“{XP, YP, C}”
P
U
C

Example:
Point A:  (1000, 950), angle towards point P:  30°
Point B:  (1012, 997), angle towards point P:  44°

Result:
Point P:  (approximately) (1024.49237, 975.078358)
Angle γ: 106°

Casio fx-7400g Plus Program TRAVEZ

TRAVEZ calculates the new point knowing the original coordinates, direction, and angle of travel.  The angle 0° comes from due east and rotates counterclockwise.

Program TRAVEZ
Deg
“1ST EAST”? → E
“1ST NORTH”? → N
0 → D
Lbl 1
“DISTANCE”? → I
“ANGLE”? → A
I * cos A + E → E
I * sin A + N → N
D + I → D
“POINT”
{E, N}
“DONE? Y=1”
? → Y
Y ≠ 1 Goto 1
“DISTANCE =”
D

Example:  Initial point (1000,1000)
Distance: 750, Angle:  276; Point {1078.396347, 254.1085785}
Distance: 600, Angle:  35; Point {1569.887574, 598.2544403}
Distance: 700, Angle:  118; Point {1241.25748, 1216.317755}
Total Distance:  2050

Casio fx-7400g Plus Program QUAD

The program QUAD is the quadratic equation which finds the roots of

Ax^2 + Bx + C = 0

Yes, I just can’t resist.

Program QUAD
“A”? → A
“B”? → B
“C”? → C
B^2 – 4AC → D
If D≥0
Then “REAL ROOTS”
(-B + √D) ÷ (2A) → S
(-B - √D) ÷ (2A) → T
Else “ROOTS S+TI”
-B ÷ (2A) → S
√(Abs D) ÷ (2A) → T
IfEnd
{S, T}


Example:
A = 2.5, B = -3, C = -1.1
Roots:  “REAL ROOTS”, 1.494427191, -0.294427191


A = 2.5, B = -3, C = -1.1
Roots:  “ROOTS S+TI”,  -0.375 ± .3665719575i   (T:  -3.665719575)

Happy Thanksgiving!  Eddie


This blog is property of Edward Shore, 2016.





Sunday, June 26, 2016

Fun with the HP 71B II

Fun with the HP 71B II

Four years ago, I had fun with the HP 71B programming:



That has been too long ago.  Time to pull out the 71B again.



Digital Root of an Integers

Add all the numbers of an integer and repeat until you have a single digit (1-9).

Program DROOT (52 bytes)

10 DESTROY N
20 INPUT “INTEGER:”;N
22 N=IP(N)
30 D=1+MOD(N-1,9)
40 DISP D

Easy Traverse Calculation

Calculates the new point knowing the original coordinates, direction, and angle of travel.  The angle 0° comes from due east and rotates counterclockwise (see diagram below). 



Program TRAVEZ (216 bytes)


15 DEGREES
20 INPUT “INIT. EASTING:”;E
25 INPUT “INIT. NORHTING:”;N
30 D=0
40 INPUT “DISTANCE:”;I
45 INPUT “ANGLE:”;A
50 E=I*COS(A)+E
55 N=I*SIN(A)+N
57 D=D+I
60 DISP N;’,’;E
65 PAUSE
70 INPUT “DONE? (Y=1,N=0)”;X
75 IF X=0 THEN 40
90 DISP “TOTAL DIST:”;D

Integral Using Simpson’s Rule

∫ FNF(X) dX from X = a to X = b

Line 10 is where you have to define your function (of X). 

Program SIMPSON  (200+ bytes)

10 DEF FNF(X)=insert function of X here
30 INPUT “LOWER:”;A
32 INPUT “UPPER:”;B
34 INPUT “# PART’NS (EVEN):”;N
36 RADIANS
38 T=FNF(A)+FNF(B)
40 H=(B-A)/N
50 FOR I=1 TO N-1
52 IF FP(I/2)=0 THEN 54 ELSE 56
54 T=2*FNF(A+I*H)+T @ GOTO 58
56 T=4*FNF(A+I*H)+T
58 NEXT I
60 T=T*H/3
62 DISP “INTEGRAL:”;T

Expanding the Binomial (ax+b)^n

BINOMEXP gives the coefficients of the expansion of (ax+b)^n. 

Program BINOMEXP (about 189 bytes)

10 DESTROY A,B,N,L,I,C
12 OPTION BASE 0
14 DISP ‘exapand(Ax+B)^N’ @ WAIT 1
16 INPUT “A,B,N”;A,B,N
18 DIM L(N)
20 FOR I=0 TO N
22 C=FACT(N)/(FACT(I)*FACT(N-I))  \\ FACT is the factorial function
24 L(I)=C*A^(N-I)*B^I
26 DISP “L(“; I; ”):”; L(I); “x^”; N-I  @ PAUSE
28 NEXT I
40 DISP “DONE, CHECK L.”

Synthetic Division

Divide the polynomial p(x) by (x-R).  P is the array of p(x), Q is the array representing the quotient q(x), and E is the remainder.  Hence:  P(x)/(x-R) = Q(x) + E/(x-R)

Program SYNTH (304 bytes)

10 DESTROY P,I,Q,R,E
12 OPTION BASE 0
14 DIPS “P(X)/(X-R)” @ WAIT 1
16 INPUT “DEGREE OF P(X):”;N
18 DIM P(N),Q(N)
20 FOR I=0 TO N
22 DISP “COEF OF x^”;N-1 @ PAUSE
24 INPUT P(I) @ P(I)=Q(I)
26 NEXT I
30 INPUT “R:’;R
40 FOR I=0 TO N-1
42 Q(I+1)=R*Q(I)+P(I+1)
44 NEXT I
50 E=Q(N)
60 DIM Q(N-1)
70 DISP “COEF OF Q(X)”
72 FOR I=0 TO N-1
74 DISP Q(I); “x^”; N-I-1 @ PAUSE
76 NEXT I
80 DISP “REMAIN:”; E; “/(x-“; R; “)”

Dew Point Measurement (in °F)


Program DEWPOINT (159 bytes)

10 DESTROY T,H,V,W,C,D
20 INPUT “TEMP °F”;T
22 C=(T-32)*5/9
26 INPUT “REL HUMIDITY (%):”;H
30 V=(LOG(H%1)+17.27*C/(237.3+C))/17.27
32 W=237.3*V/(1-V)
40 D=9/5*W+32
42 DISP “DEW POINT °F:”;D

// Degree symbol:  [ g ] [RUN] (CTRL) [ A ]

 This blog is property of Edward Shore, 2016


Saturday, December 1, 2012

Numeric CAS Part 2: Binomial Expansion

Binomial Expansion

Goal: To find the coefficients of when (ax + by)^n is expanded. The variables a and b are numeric.

(ax + by)^n = Σ (n nCr k *(ax)^(n-k) * (by)^k for k = 0 to n).

Example: (3x - 2y)^3 = 27 x^3 - 54 x^2 y + 36 x y^2 - 8 y^3

For the Casio Prizm and TI-84+, each coefficient is given in order. They are also stored in List 6. For the HP 39gii, a string is built representing the expanded binomial.

The list in the above example is {27, -54, 36, -8}


Casio Prizm:

POLYBINE
Binary Expansion
216 bytes

Lbl 6
"(AX+BY)^N"
"A"?→ A
"B"?→ B
"N"?→ N
If N≤0 Or Frac N≠0
Then
"N NOT AN INTEGER > 0" ◢
Goto 6
IfEnd
For 0 → K To N
ClrText
N nCr K × A ^ (N - K) × B ^ K → C
Locate 1,2,C
Locate 1,3,"×X^"
Locate 4,3,N-K
Locate 7,3,"×Y^"
Locate 10,3,K ◢
C→ List 1[K+1]
Next






Thanks to Ryan Maziarz for pointing out an extra quotation mark I had on line 3  (originally "A"?"A).  2/6/2013

Note:  The program will show the coefficients of the expansion one at a time.  You can view the entire list of the coefficients in List 1. 


TI-84+:

POLYBINE
Binomial Expansion
177 bytes

: Lbl 1
: Disp "(AX+BY)^N"
: Prompt A,B,N
: If N≤0 or fPart(N)≠0
: Then
: Disp "NEED INTEGER>0"
: Pause
: Goto 1
: End
: N+1->dim(L6)
: For(K,0,N)
: N nCr K*A^(N-K)*B^K->C
: ClrHome
: Output(2,1,C)
: Output(3,1,"*X^")
: Output(3,4,N-K)
: Output(3,7,"*Y^")
: Output(3,10,K)
: Pause
: C->L6(K+1)
: End



Note:  The program will show the coefficients of the expansion one at a time.  You can view the entire list of the coefficients in L6. 

HP 39gii:

POLYBINE
11/23/2012
Polynomial Binomial Expansion
Expand (ax + by)^n

The results are returned in a string. Note, if N is not a positive integer, it is converted into one.

Input: POLYBINE(A,B,C)

EXPORT POLYBINE(A,B,C)
BEGIN
LOCAL S1,S2,K;
ABS(INT(N)) → N;
"" → S1;
FOR K FROM 0 TO N DO
string(COMB(N,K)*A^(N-K)*B^K) → S2;
S1 + "+" + S2 + "*X^" + string(N-K) + "*Y^" + string(K) → S1;
END;
dim(S1) → K;
right(S1,K-1) → S1;
RETURN S1;
END;



This blog is property of Edward Shore. 2012


HP 48G Collection

 HP 48G Collection  Contents:  Intensity of Spherical Light Source  Speed of Light in Dry Air  Pressure of Air  Earth's Gravity a...