Showing posts with label Numeric CAS. Show all posts
Showing posts with label Numeric CAS. Show all posts

Sunday, May 21, 2023

Python: Square Root Simplification

 Python: Square Root Simplification



Introduction


The script SQFACTOR.py attempts to factor and simplify square root expressions in the form of either:


1.  √n

2.  √m + √n


The script was created using the TI-83 Plus Premium CE Python Edition, which is my first Python script using the French calculator.  




Python script:  sqfactor.py


from math import *

# basic code


def sqfactor(n):

  c=1

  k=2

  while k**2<n:

    while (n/k**2)-int(n/k**2)==0:

      n/=k**2

      c*=k

    k+=1

  return [c,n]


# 2 forms

print("Select: ")

print("1. sqrt(n)")

print("2. sqrt(m)+sqrt(n)")

ch=int(input())


if ch==1:

  n=float(input("n? "))

  l=sqfactor(n)

  print("sqrt("+str(n)+")=")

  print(str(l[0])+"*sqrt("+str(l[1])+")")


if ch==2:

  m=float(input("m? "))

  n=float(input("n? "))

  l0=sqfactor(m)

  l1=sqfactor(n)

  c=l0[0]

  d=l0[1]

  r=l1[0]

  s=l1[1]

  print("sqrt("+str(m)+") + sqrt("+str(n)+")")

  if d==s:

    print(str(c+r)+"*sqrt("+str(d)+")")

  else:

    print(str(c)+"*sqrt("+str(d)+")+")

    print(str(r)+"*sqrt("+str(s)+")")



Examples



Example 1:


√1640

Result:  2 * sqrt(410.0)


Example 2:


√56 + √78

Result:  2 * sqrt(14.0) + 1 * sqrt(78.0)


Example 3:


√75 + √27

Result:  8 * sqrt(3.0)



Eddie 


All original content copyright, © 2011-2023.  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. 

Wednesday, December 5, 2012

Numeric CAS - Part 11: Eigenvalues of 3 x 3 Matrices

Eigenvalues of 3 x 3 Matrices

Many graphing calculators that do not have CAS (computer algebraic systems) do not have eigenvalues and eigenvector functions.

The programs for the Casio Prizm and TI-84+ gives eigenvalues of 3 x 3 matrices.

For the HP 39gii has the functions EIGENVAL for eigenvalues.

Example:
A = [[2, -2, 3][-1, 0, 1][6, -3, 3]]

Eigenvalues:
≈ 0.2465, -1.8447, 6.5982


Casio Prizm:

EIGEN3
Eigenvalues of a 3 × 3 Matrix
Circa 2011 - 244 bytes

a+bi
"3 × 3 Matrix"? → Mat A
Mat A[1,1] + Mat A[2,2] + Mat A[3,3] → T
(Mat A)² → Mat B
Mat B[1,1] + Mat B[2,2] + Mat B[3,3] → U
Solve(-X^3 + X^2 × T + X × 1/2 × (U-T^2) + Det Mat A,0)→ R ◢
-R^2 + R × T - T^2 ÷ 2 + U ÷ 2 → A
-R + T → B
1/2 × (B - √(4A + B^2)) → E ◢
1/2 × (B + √(4A + B^2)) → F ◢
"STORED IN R, E, F"


TI-84+:

EIGEN3
Eigenvalues of a 3 × 3 matrix - 193 bytes
12/3/12

a+bi
Input "3 X 3 MATRIX:", [A]
[A](1,1) + [A](2,2) + [A](3,3) → T
[A]² → [B]
[B](1,1) + [B](2,2) + [B](3,3) → U
solve(-X³ + X² T + .5X(U-T²) + det([A]), X, 0) → R
Pause R
-R² + RT - T²/2 + U/2 → A
-R + T → B
.5(B - √(4A+B²)) → E
.5(B + √(4A+B²)) → F
Pause E
Pause F




This blog is property of Edward Shore. 2012

Numeric CAS Part 10 - Eigenvalues of 2 x 2 Matrices

Eigenvalues of 2 x 2 Matrices

Many graphing calculators that do not have CAS (computer algebraic systems) do not have eigenvalues and eigenvector functions.

The program for the Casio Prizm gives eigenvalues. The TI-84+ program gives both eigenvalues and eigenvectors.

For the HP 39gii has the functions EIGENVAL and EIGENVV for eigenvalues and eigenvectors, respectively.

Example:
A = [[2, 7][-3, 9]]

Eigenvalues: ≈ 5.5 ± 2.9580i


Casio Prizm:

Eigenvalues of a 2 × 2 Matrix
EIGEN2 - 136 Bytes

a+bi
"2 × 2 MATRIX:"? → Mat A
Mat A[1,1] + Mat A[2,2] → T
Det Mat A→ D
(T+√(T^2-4D))÷2 → R ◢
(T-√(T^2-4D))÷2 → S ◢
"λS STORED IN R,S"


TI-84+:

EIGEN2
Eigenvalues of 2 × 2 matrices - Approximately 280 bytes
Bonus! A pair of eigenvectors are given
5/15/2011

a+bi
Input "2 X 2 MATRIX:", [J]
[J](1,1) + [J](2,2) → T
det([J]) → D
(T + √(T^2 - 4D))/2 → U
(T - √(T^2 - 4D))/2 → V
Disp "EIGENVAL. U"
Pause U
(U - [J](1,1)) / [J](1,2) → A
√(1 + A^2)⁻¹ * [[1][A]] → [H]
Disp "EIGENVEC. [H]"
Pause [H]
(V - [J](1,1)) / [J](1,2) → B
√(1 + B^2)⁻¹ * [[1][B]] → [I]
Disp "EIGENVAL. V"
Pause V
Disp "EIGENVECT. [I]"
Pause [I]




This blog is property of Edward Shore. 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

Numeric CAS - Part 8: Polynomial Derivative

Derivative of a Polynomial

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

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

and

d/dX p(X) = a_n * n * x^(n-1) + a_(n-1) * (n-1) * x^(n-2) + ... + a1

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:

d/dx -2x^2 + 4x - 6 = -4x + 4
Input List: {-2, 4, -6}
Output List: {-4, 4}

d/dx x^4 + 3x^2 - x = 4x^3 + 6x - 1
Input List: {1, 0, 3, -1, 0}
Output List: {4, 0, 6, -1}

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


Casio Prizm:

POLYDX
Polynomial Derivative - 132 bytes

"d/dX P(X)"
"{AnX^n,...,A0}"
"LIST:"? → List 1
Dim List 1-1 → Dim List 2
For 1→K To Dim List 2
(Dim List 1-K) × List 1[K] → List 2[K]
Next
List 2


TI-84+:

POLYDX
Polynomial Derivative - 118 bytes

: Disp "D/DX P(X)", "{AnX^n,...,A0}"
: Input "LIST:",L1
: L1->L2
: dim(L2)-1->dim(L2)
: For(K,1,dim(L2))
: (dim(L2)-(K-1))*L2(K)->L2(K)
: End
: Pause L2


HP 39gii:

Polynomial Derivative
11/23/2012 - edited 12/2/2012

POLYDX()

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




This blog is property of Edward Shore. 2012

Monday, December 3, 2012

Numeric CAS - Part 7: Quadratic Equation

Quadratic Formula

Ax² + Bx + C = 0

Where x = (-B ± √(B² - 4AC)) / (2A)

This is just the popular quadratic formula, except this set of programs allow for complex A, B, and C. (Unlike the Solver applications).

Example:
A = 2 - i
B = -6
C = 14i

x1 ≈ -0.9873 + 1.551i
x2 ≈ 3.3873 - 0.3509i


Casio Prizm:

QUADSLV
Quadratic Equation - Complex Coefficients Allowed
11/23/2012 - 124 bytes

a+bi
"AX²+BX+C=0"
"A"? → A
"B?"→ B
"C?"→ C
√(B²-4AC) → X
(-B - X) ÷ (2A)→ R
(-B + X) ÷ (2A) → S
"X=R Or X=S"
R ◢
S


TI-84+:

QUADSLV
Quadratic Formula - Allows for Complex Coefficients
Ax^2 + Bx + C = 0

a+bi
Disp "AX²+BX+C"
Prompt A,B,C
√(B²-4AC) → X
(-B - X)/(2A) → R
(-B + X)/(2A) → S
Disp "X=R or X=S"
Pause R
Pause S


HP 39gii:

Use the POLYROOT command. POLYROOT([A,B,C])

The vector can represent any polynomial.




This blog is property of Edward Shore. 2012





Numeric CAS Part 6: Euclid Algorithm to find GCD (Greatest Common Divisor)

Euclid Algorithm

Goal: To find the greatest common divisor of two integers U and V.

The Algorithm in Brief:

Let U ≥ V. Then U = A * V + R where A is the quotient and R is the remainder. If R≠0, then V becomes the new U, and R becomes the new V. The process repeats until you R=0. When that happens, V_last = GCD(U,V).

The program allows for you two enter integers in any order. Each program uses the home screen to display the steps, but the HP 39gii displays all the steps on one screen.

Example: gcd(166, 78)

166 = 2 * 78 + 10
78 = 7 * 10 + 8
10 = 1 * 8 + 2
8 = 4 * 2 + 0
GCD = 2

gcd(169,39)

169 = 4 * 39 + 13
39 = 3 * 13 + 0
GCD = 13


Casio Prizm:

EUCLID
GCD Program - 12/3/12
212 bytes

"X"?→ X
"Y"?→ Y
If X ≥ Y
Then X → M
Y → N
Else X → N
Y → M
IfEnd
Lbl 1
Int(M ÷ N) → A
M - A × N → R
ClrText
Locate 1,2,M
Locate 1,3,"="
Locate 2,3,A
Locate 13,3,"×"
Locate 14,3,N
Locate 1,4,"+"
Locate 2,4,R ◢
If R=0
Then Goto 2
Else N → M
R → N
Goto 1
IfEnd
Lbl 2
Locate 1,6,"GCD="
Locate 6,6,N


TI-84+:

GCD by Euclidian Algorithm
11/25/2012 - 160 bytes

Program EUCLID

Prompt X,Y
min(X,Y) → N
max(X,Y) → M
Lbl 1
iPart(M/N) → A
M - A * N → R
ClrHome
Output(2,1,M)
Output(3,1,"=")
Output(3,2,A)
Output(3,8,"*")
Output(3,9,N)
Output(4,1,"+")
Output(4,2,R)
Pause
If R=0
Then
Goto 2
Else
N → M
R → N
Goto 1
End
Lbl 2
ClrHome
Disp "GCD=", N


HP 39gii:

Program EUCLID
Finding the GCD by the Euclid algorithm
10/16/2012

Input: EUCLID(X,Y)

EXPORT EUCLID(X,Y)
BEGIN
LOCAL M,N,R,A;
MAX(X,Y)→ N;
MIN(X,Y)→M;
PRINT();
REPEAT
INT(N/M)→ A;
N - A*M→ R;
PRINT(A + "*" + M + "+" + R);
WAIT(1);
M→ N;
R→ M;
UNTIL R==0;
RETURN N;
END;




This blog is property of Edward Shore. 2012





Sunday, December 2, 2012

Numeric CAS - Part 5: Polynomial Evaluation

Polynomial Evaluation


Goal: Evaluation of the polynomial p(x) at x = a. This gives an alternative to typing out the polynomial itself.

Enter the coefficients of the polynomial as a list, in descending order from highest power to constant. Use zeros as place-holders.

Example:
Let p(x) = 2x^4 + 2x^2 - 4x + 1 at x = -1.5

List Input: {2, 0, 2, -4, 1}
Enter -1.5 when the program asks for X.

Result: p(-1.5) = 21.625


Casio Prizm:

POLYEVAL
Poly Evaluation
11/23/2012
(140 bytes)

Example: p(x) = x^3 + 2x^2 + 5x + 9, p(-2) = -1

Program:
"{AnX^n,...,A0}"
"P(X)"? → List 1
"X"? → X
X = 0 ⇒ Goto 1
0 → S
For 1 → K To Dim List 1
S + List 1[K] × X^(Dim List 1 - K) → S
Next
S
Stop
Lbl 1
List 1[Dim List 1]→ S

Sum is stored in S, 0^0 is not allowed.


TI-84+:

POLYEVAL
Polynomial Evaluation
11/23/2012 - 124 bytes

Example: p(x) = 1.425x^3 - 2.89x^2 + 0.23x + 4.4546
p(1.002) = 3.217055551

For the character n: VARS, 5, 1

Disp "{AnX^n,...,A0}"
Input "P(X):", L1
Input "X:", X
If X=0
Goto 1
0→ S
For(K,1,dim(L1))
S + L1(K) * X^(dim(L1) - K) → S
End
Pause S
Stop
Lbl 1
L1(dim(L1)) → S
Pause S


HP 39gii:

There is no program. Instead, use the POLYEVAL command.

POLYEVAL(vector, value)

The vector contains the coefficients of the polynomial.




This blog is property of Edward Shore. 2012



Numeric CAS - Part 4: Polynomial Multiplication

Polynomial Multiplication

Goal: Multiply two polynomials: p1(x) * p2(x) = p3(x)

Inputs: Coefficients of p1(x) and p2(x) as List 1 and List 2, respectively

Output: Coefficients of p3(x) as List 3.

The lists are in order from highest order to constant. Zeros are used as place holders.

Example: (x^3 + 2x - 1) * (-2x^2 + x - 4) = -2x^5 + x^4 - 8x^3 + 4x^2 - 9x + 4

Input:
List 1: {1, 0, 2, -1}
List 2: {-2, 1, -4}

Output:
List 3: {-2, 1, -8, 4, -9, 4}


Casio Prizm:

POLYMULT
Multiplication of Two Polynomials
11/21/2012 - 176 bytes

"{AnX^n,...,A0}"
"P1(X)"? → List 1
"P2(X)"? → List 2
Dim List 1 + Dim List 2 - 1 → Dim List 3
For 1 → K To Dim List 1
List 1[K] × List 2 → List 4
For 1 → J To Dim List 4
List 3[J + K - 1] + List 4[J] → List 3[J + K - 1]
Next
Next
List 3


Example:
(x^2 + 3x - 1)(x^2 - 4) = x^4 + 3x^3 - 5x^2 - 12x + 4
List 1: {1,3,-1}
List 2: {1,0,-4}
Result List 3: {1,3,-5,-12,4}


TI-84+:

POLYMULT
Multiplication of two Polynomials
{AnX^n,...,A0}
11/21/2012 - 154 bytes

To get the lower case "n" character: VARS, 5, 1

Disp "{AnX^n,...,A0}"
Input "P1(X)=", L1
Input "P2(X)=", L2
dim(L1) + dim(L2) - 1 → dim(L3)
Fill(0,L3)
For(K, 1, dim(L1))
L1(K) * L2 → L4
For(J, 1, dim(L4))
L3(J + K - 1) + L4(J) → L3(J + K - 1)
End
End
Pause L3


HP 39gii:

Polynomial Multiplication (FULL)
12/2/2012

EXPORT POLYMULT()
BEGIN
LOCAL S,K,J;
EDITLIST(L1);
EDITLIST(L2);
SIZE(L1)+SIZE(L2)-1 → S;
MAKELIST(0,X,1,S,1) → L3;
FOR K FROM 1 TO SIZE(L1) DO
L1(K)*L2 → L4;
FOR J FROM 1 TO SIZE(L4) DO
L3(J+K-1) + L4(J) → L3(J+K-1);
END;
END;
RETURN L3;
END;





This blog is property of Edward Shore. 2012





Numeric CAS - Part 3: Synthetic Division

Synthetic Division

Goal: Divide the polynomial p(x) = a_n x^n + a_(n-1) x^(n-1) + ... + a_0 by (x - r).

p(x) ÷ (x - r) = q_n x^n + q_(n-1) x^(n-1) + ... + q_0 with remainder E

Input: A list of coefficients {a_n, a_(n-1), a_(n-2), ... , a_0} (List 1)

Output: Resulting coefficients {q_n, q_(n-1), ... , q_0, E} (List 2)

Example: (2x^3 + x - 3) ÷ (x - 3) = 2x^2 + 6x + 19 + 54 ÷ (x - 3)

List 1: {2, 0, 1, -3}, R = 3
List 2: {2, 6, 19, 54}


Casio Prizm

POLYSYN
Synthetic Division - 160 bytes

"P(X) ÷ (X-R)"
"{AnX^n,...,A0}"
"LIST:"?→List 1
"R"?→R
List 1 → List 2
For 1→K To Dim List 1 - 1
R × List 2[K] + List 1[K+1] → List 2[K+1]
Next
"LAST TERM = REMAINDER" ◢
List 2


TI-84+

POLYSYN
Synthetic Division - 143 bytes

: Disp "P(X)/(X-R)"
: Disp "{AnX^n,...,A0}"
: Input "LIST:", L1
: Input "R:", R
: L1->L2
: For(K,1,dim(L1)-1)
: R*L2(K)+L1(K+1)->L2(K+1)
: End
: Disp "LAST TERM=", "REMAINDER"
: Pause L2


HP 39gii

POLYSYN
Synthetic Division
11/23/2012

L1 and A are prompted. The resulting is a list of coefficients, with the last term the remainder

Example: (21x^2 + 42x + 144)/(x - 12) = 21x + 294 + 3672/(x-12)
Output List: {21, 294, 3672}

EXPORT POLYSYN()
BEGIN
LOCAL K,S,T;
EDITLIST(L1);
INPUT(R,"P(X)/(X-R)");
L1 → L2;
SIZE(L1)→ S;
S-1 → T;
FOR K FROM 1 TO T DO
R * L2(K) + L1(K+1) → L2(K+1);
END;
MSGBOX("LAST TERM=REMAINDER");
RETURN L2;
END;




This blog is property of Edward Shore. 2012




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


Numeric CAS Part 1: Simplifying Square Roots

Simplifying Square Roots

Goal: Simplify square roots of integers. For example, √180 = 6 √5, √80 = 4 √5

General Algorithm: Start with integer N and C=1. Starting with k=2, divide N by k². If N divides k² evenly, N is adjusted, C is multiplied by k, and the division is test is repeated. If N does not not divide k², k increases by 1 and the division test repeats. The division tests repeat until k² > N.

The program for the Casio Prizm, TI-84+, and HP 39gii are presented below:


Casio Prizm:

SQFACTOR
11/19/2012
Simplifies √N where N is an integer (i.e. √180 = 6 √5, √364 = 2 √91)
156 bytes

"√N="? → N
N → M
1 → C
2 → K
Do
Lbl 1
If Frac(N ÷ K²)=0
Then
N ÷ K² → N
C × K → C
Goto 1
IfEnd
K + 1 → K
LpWhile K²
ClrText
Locate 1,1,"√"
Locate 2,1,M
Locate 1,3,C
Locate 10,3,"×√"
Locate 12,3,N


TI-84+:

SQFACTOR
Square Root Simplification
(I.E. √180 = 6 √5 , √364 = 2 √91)
11/19/2012
133 bytes

Input "√(", N
N → M
1 → C
2 → K
Lbl 0
If fPart(N/K²)=0
Goto 1
1 + K → K
If K² < N
Goto 0
ClrHome
Output(1,1,"√(")
Output(1,3,M)
Output(3,1,C)
Output(3,7,"√(")
Output(3,9,N)
Stop
Lbl 1
N/K² → N
C*K → C
Goto 0


HP 39gii:

SQFACTOR
11/23/2012
Simplifies √N where N is an integer (i.e. √180 = 6 √5, √364 = 2 √91)

Input: SQFACTOR(N)

EXPORT SQFACTOR(N)
BEGIN
LOCAL C,K;
1 → C;
2 → K;
WHILE K² < N DO
WHILE FRAC(N/K²) == 0 DO
N/K² → N;
C*K→ C;
END;
K+1→K;
END;
RETURN string(C)+"√"+string(N);
END;




This blog is property of Edward Shore. 2012

Numeric CAS Project - an Introduction

It's coming! The Numeric CAS project is a set of programs designed to give common graphing calculators a set of some common computer algebraic system functions and advanced graphing calculators.

The calculators that I will be working with in this series are:

* Texas Instruments TI-84 Plus
* Casio Prizm fx-CG 10 (should work on most Casio graphing calculators)
* Hewlett Packard 39gii

Everything is this series is done by using the calculator's native languages. No hacking is required. The programs use the numeric features of the calculator.

Often, lists will be used to represent coefficients of polynomials. The power of coefficients are in descending order. For example, to represent the polynomial x^3 + 2x - 1, the list would be {1, 0, 2, -1}. Zeroes are necessary in these lists.

There will be twelve parts in the Numerical CAS Project:

1. Simplifying Square Roots of Integers
2. Expanding Binomials
3. Synthetic Division
4. General Multiplication of Polynomials
5. Polynomial Evaluation
6. Euclid Algorithm to find GCD
7. Quadratic Formula
8. Derivative of a Polynomial
9. Indefinite Integral of a Polynomial
10. Eigenvalues of a 2 x 2 Matrix
11. Eigenvalues of a 3 x 3 Matrix
12. Complex Roots of a Complex Number

I aim to post all twelve parts throughout December 2012. What is awesome about programming a calculator is that you extend its functionality beyond the already extensive list of given functions, and you don't have to be an expert in assembly or complex language.

Eddie


This blog is property of Edward Shore. 2012

Python (TI-84 Evo) and HP 32S: Shannon-Wiener Diversity Index

Python (TI-84 Evo) and HP 32S: Shannon-Wiener Diversity Index Introduction The Shannon-Wiener Diversity Index measures a leve...