Showing posts with label angle between vectors. Show all posts
Showing posts with label angle between vectors. Show all posts

Monday, May 15, 2023

TI-84 Plus CE and TI-83 Premium CE: Vectors Program

TI-84 Plus CE and TI-83 Premium CE:  Vectors Program










The program VECTORS is made for the TI-84 Plus CE and TI-83 Premium CE.  


Introduction


The program VECTORS calculates the following of the three dimensional vectors [A] and [B]:


* Dot product of [A] and [B]

* Euclidean norm of vectors [A] and [B]

* Angle between vectors [A] and [B] in degrees

* Cross product of [A] × [B]

* Tensor product of [A] ⊗ [B]


The program uses the system matrices [A] and [B] and formats them as 3 rows, 1 column matrices.   The program changes the angle mode to Degrees.


After entering each vector, the program gives you an option to normalize the vectors.  Since the cross and tensor products do not follow the commutative property, there is an option to switch the elements of both vectors.  


Depending on the calculator used, results will be shown in either exact format (TI-83 Premium CE) or approximate format (TI-84 CE).  



Calculations Used 


In this section, each of the vectors will be followed by the program code used.  


Let [A] and [B] be the column vectors:

[A] = [[a1][a2][a3]]

[B] = [[b1][b2][b3]]


Dot Product: 

[A] • [B] = a1 * b1 + a2 * b2 + a3 * b3 = [A]ᵀ [B]




Euclidean Norm:

||[A]||₂ = √(a1² + a2² + a3²) = √([A]ᵀ [A])

||[B]||₂ = √(b1² + b2² + b3²) = √([B]ᵀ [B])





Angle Between Two Vectors:

θ = arccos(([A] • [B]) ÷ (||[A]||₂ * ||[B]||₂))




Cross Product:

[A] × [B] = [C] where:

c1 = a2 * b3 – a3 * b2

c2 = -a1 * b3 + a3 * b1

c3 = a1 * b2 – a2 * b1

The result is a 3 x 1 matrix. 




Tensor Product:

[A] ⊗ [B] = [A] [B]ᵀ

The result is a 3 x 3 matrix. 





Download 



You can download the program and the user guide here:

https://drive.google.com/file/d/1R1sHGfr8dKQDkH87QDE0HgMDWxeLNHPN/view?usp=share_link



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. 


Thursday, February 14, 2019

TI-86: Angle Between Vectors, Vandermonde Matrix, Least Squares Algorithm, Chebyshev Polynomials (1st Kind)


TI-86: Angle Between Vectors, Vandermonde Matrix, Least Squares Algorithm, Chebyshev Polynomials (1st Kind)

The TI-86 has one of the best interfaces for a graphing calculator I ever had the joy to work with. The TI-86 is an update of the TI-85. Here are some programs for the TI-86.

Angle Between Vectors

The program vangle calculates the angle between two angles. The angle is calculated in degrees.



TI-86 Program vangle
(75 bytes)

Prompt V1
Prompt V2
Disp cos⁻¹ (dot(V1,V2)/(norm V1*V2))

Example: [2, -3, 4] and [8, 1, -2]
Angle: 83.5823268926°

Vandermonde Matrix

The program vander creates a matrix based on a list of coefficients.

Example: {x, y, z} produces the matrix

[ [x^0, x^1, x^2], [y^0, y^1, y^2], [z^0, z^1, z^2] ]



TI-86 Program vander
(125 bytes)

Input “List: “, L1
dimL L1 → N
{N, N} → dimL MA
For(R, 1, N)
For(C, 1, N)
L1(R)^(C-1) → MA(R,C)
End
End
Disp “MA=”
Pause MA

Example: {2, 4, 7}
Result: [ [1, 2, 4], [1, 4, 16], [1, 7, 49] ]

Least Square Algorithm

The program LSQ taxes the matrices X and Y (Y is a one-column matrix), and calculates
(X^T X)^-1 (X^T Y).

LSQ is used to fit statistical fits with least squares.



TI-86 Program LSQ
(118 bytes)

Disp “Least Squares”
Input “Matrix X: “,MX
Input “Matrix Y: “,MY
(MX^T * MX)^-1 * (MX^T * MY) → ML
Disp “ML= “
Pause ML

Example:
MX = [ [1, 3, 2.0], [1, 4, 2.3], [1, 5, 2.6], [1, 8, 2.9] ]
MY = [ [1.6], [1.8], [2.1], [2.3] ]

Results:
ML = [ [-0.14444444449], [-1.666666667E-2], [0.88888888889] ]

Chebyshev Polynomials (1st Kind)

The program tcheby calculates the numerical value of the Chebyshev polynomials of the 1st Kind given its point, X, and the order, N.

TI-86 Program tcheby
(127 bytes)

Prompt X,N
If X>1 : Goto A
If X<-1 :="" b="" goto="" span="">
cos(N * cos⁻¹ X) → A
Goto C
Lbl A
cosh(N * cosh⁻¹ X) → A
Goto C
Lbl B
(-1)^N * cosh(N * cosh⁻¹ X) → A
Lbl C
Disp A

Example:
X = -2.5, N = 4, Result: 263.5
X = 0.5, N = 4, Result: -0.5
X = 2.5, N = 4, Result: 263.5

Eddie

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

Friday, May 11, 2018

Fun with the Sharp EL-5500 III (May 2018 Edition)


Fun with the Sharp EL-5500 III   (May 2018 Edition)

The EL-5500 III is one of my favorite pocket programming device, small, portable, and has my favorite programming language: BASIC. 

Let’s get started.

Note:  Substitute line numbers with labels that you find fit.  Add defined labels to the first line if you would like.  Labels can come from the bottom two rows of the QWERTY keyboard (A row and Z row).

Comments are followed by double slashes (//), they are not typed.

Sharp EL-5500 III Program:  Net Present Value

2  PAUSE “NET PRESEN VALUE”
4  CLEAR    // clears all the variables
6  INPUT “CF0:”; N, “RATE:”; I
8  J = 1
10 INPUT “FLOW:”; F, “FREQ:”; K
12 FOR L=1 TO K: N = N + F/(1 + I/100)^J: J = J+1
14 NEXT L
16 INPUT “MORE=1: “; L   // enter 1 to enter more cash flows, anything else to end entry
18 PRINT USING “#############.##”; “NPV: “; N
20 END

Example:

CF0:  -7,000,  Interest Rate:  8%
Flow 1:  2,000, Freq 1: 1  (enter 1 for MORE)
Flow 2:  1,500, Freq 2: 2  (enter 1 for MORE)
Flow 3:  2,500, Freq 3: 2  (we are at the end, enter anything other than 1 at MORE)

Result:
NPV:  2443.06

Sharp EL-5500 III Program: Synthetic Division

2 PAUSE “Synthetic Division”: CLEAR
4 PRINT “P(X)/(X – R)”: WAIT 59   // WAIT 59 is about 1 second
6 INPUT “DEGREE:”; N
8 DIM P(N): DIM Q(N)
10 FOR I=1 TO N
12 PRINT “COEF OF X^”; N-I
14 INPUT P(I): Q(I) = P(I)
16 NEXT I   // there is no line 18
20 INPUT “R:”; R
22 FOR I=0 TO N-1
24 Q(I+1) = R*Q(I) + P(I+1)
26 NEXT I
28 E = Q(N)
30 PRINT “Q(X) = “
32 FOR I=0 TO N-1
34 PRINT Q(I); “X^”; N-I-1
36 WAIT 150  // about 2.5 seconds
38 NEXT I
40 PRINT “+”; E; “/(X-“; R; “)”: END

Example:  (x^4 – 2*x^3 + 1) / (x – 1)
Degree: 4
Coefficients:  1, -2, 0, 0, 1
R: 1

Result: 1, -1, -1, -1, no remainder
x^3 – x^2 – x – x

Sharp EL-5500 III Program: Vector Basics

Cross product, dot product, norm of two vectors, angle between two vectors

2 PAUSE “Vector Basics”
4 INPUT “X1:”; X1, “Y1:”; Y1, “Z1:”; Z1  \\ vector 1
6 INPUT “X2:’; X2, “Y2:”; Y2, “Z2:”, Z2  \\ vector 2
8 C1 = Y1*Z2 – Y2*Z1: C2 = -X1*Z2 + X2*Z1: C3 = X1*Y2 – X2*Y1  // cross product
10 D = X1*X2 + Y1*Y2 + Z1*Z2  \\ dot product
12 N1 = √(SQU X1 + SQU Y1 + SQU Z1): N2 = √(SQU X2 + SQU Y2 + SQU Z2)  // norm, SQU is the x^2 key
14 DEGREE
16 A = ACS( D/(N1*N2))  // angle between vectors, ACS is ACOS
18 PRINT “CROSS X: ”; C1
20 PRINT “CROSS Y: ”; C2
22 PRINT “CROSS Z: ”; C3
24 PRINT “DOT: ”; D
26 PRINT “NORM V1: “; N1
28 PRINT “NORM V2: “; N2
30 PRINT “ANGLE: “; A
32 END


Example:  V1 = [-2, 3, 0] and V2 = [ 4, 2, -11]
Cross: [-33, -22, -16]
Dot: -2
Norm V1: 3.605551275
Norm V2: 11.87434209
Angle: 92.67749998°

Sharp EL-5500 III: Atwood Machine

M1:  mass hanging on the left side of the machine
M2:  mass hanging on the right side of the machine

The program asks to choose a unit system.  Enter 1 for US units (feet, pounds, seconds, g = 32.174 ft/s^2), anything else for SI units (meters, kilograms, seconds, g = 9.80665 m/s^2).

2 PAUSE “Atwood Machine”
4 INPUT “1: US, ELSE: SI “; I
6 IF I=1 THEN LET G=32.174
8 IF I<>1 THEN LET G=9.80665
10 INPUT “M1: “; M1, “M2: “; M2
12 A = (M1 – M2)*G / (M1 + M2)
14 T = M1 * (G-A)
16 PRINT “Accel.: “; A
18 PRINT “Tension: “: T
20 END

Example:  M1 = 11.82 kg, M2 = 9.38 kg, use SI units (enter anything other than 1 at the 1:US, ELSE:SI prompt)

Results:
Accel.: 1.128689906 m/s^2
Tension: 102.5734883 N


Eddie

All original content copyright, © 2011-2018.  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.  Please contact the author if you have questions.

DM42 and HP 42S: Quadratic Equation, Characteristic Polynomial, and Eigenvalues

DM42 and HP 42S: Quadratic Equation, Characteristic Polynomial, and Eigenvalues The programs are listed for the Swiss Micros DM42 an...