Saturday, October 21, 2023

HP 15C: Vector Operations

HP 15C:   Vector Operations


Calculators covered:


* HP 15C

* HP 15C Limited Edition

* HP 15C Collector's Edition

* Apps, Swiss Micros DM 15



HP 15C:   Dot Product, Tensor Product, and Angle Between Vectors



Set vectors A and B as 3 x 1 vectors (3 rows, 1 column)


3 ENTER 1 dim A

3 ENTER 1 dim B


Dot Product  (LBL D)  


Dot product:  A ⋅ B = A^T B 

The result is a single number.


Code: 

001 : 42,21,14 : LBL D

002 : 45,16,11 : RCL MATRIX A

003 : 42,16, 4 : MATRIX 4

004 : 45, 16, 12 : RCL MATRIX B

005 : 42, 26, 13 : RESULT C

006 : 20 : ×

007 : 45,16,11 : RCL MATRIX A

008 : 42,16, 4 : MATRIX 4

009 : 45,13 : RCL C

010 : 43,32 : RTN


Tensor Product (LBL E)


Tensor product:  A ⊗ B = A B^T

The result is a 3 x 3 matrix


Code: 

011 : 42,21,15 : LBL E

012 : 45,16,11 : RCL MATRIX A

013 : 45,16,12 : RCL MATRIX B

014 : 42,16, 4 : MATRIX 4

015 : 42,26,13 : RESULT C

016 : 20 : ×

017 : 45,16,12 : RCL MATRIX B

018 : 41,16, 4 : MATRIX 4

019 : 42,16, 1 : MATRIX 1

020 : 45,16,13 : RCL MATRIX C

021 : 43, 32 : RTN


Angle Between Vectors (LBL 0)


θ = arccos( (A ⋅ B) ÷ (||A|| ||B||) )


Code:

022 : 42,21, 0 : LBL 0

023 : 32,14 : GSB D

024 : 45,16,11 : RCL MATRIX A

025 : 42,16, 8 : MATRIX 8

026 : 45,16,12 : RCL MATRIX B

027 : 42,16, 8 : MATRIX 8

028 : 20 : ×

029 : 10 : ÷

030 : 43,24 : COS^-1

031 : 43,32 : RTN


Notes:  


MATRIX 4:  Transposes a matrix, which it is stored in the original matrix slot.  


MATRIX 8:  The 2-norm of a matrix.   It is calculated by taking a square root of the sum of the square of each element.  √(Σ( A_r,c ^ 2,  r = 1 to n and c = 1 to m))


For the dot and tensor products, I transpose the appropriate matrix back to the 3 x 1 form after the calculation.



Example


A = [ [ 4 ], [ 5 ], [ -2 ] ]

B = [ [ -3 ], [ 9 ], [ 8 ] ]


Dot Product:  GTO D R/S

Result:  17


Tensor Product:   GTO E R/S

Result:

[ [ -12, 36, 32 ], [ -15, 45, 40 ], [ 6, -18, -16 ] ]


Angle Between Vectors:  GTO 0 R/S

Result:  78.2166°



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.