Here’s the program I came up with.
http://www.glowscript.org/#/user/heafnerj/folder/Joe'sStuff/program/matrices
Note that there are actually two functions defined, matxvec() and matxmat(). To use matxvec(), the matrix is a two-dimensional entity that must be initialized prior to being passed to the function and similarly, the vector is a one-dimensional entity that must also be initialized and defined beforehand. The first block of test code at the bottom illustrates this. I wanted matxmat() to be flexible enough to recognize whether the second argument passed to it is a vector or a matrix. If I want that second argument to be a vector, I can’t define it as, for example, vector(2,1,2) as in VPython. Instead, I must define it as [[2],[1],[2]], which wouldn’t be intuitive to students.
So my question now is, is there a way to go between the two notations b=vector(2,1,2) and b=[[2],[1],[2]] for a vector without using an explicit assignment ( e.g. vector(b[0][0],b[1][0],b[2][0]) )? For what I have in mind, the vector in question is the axis property of an arrow object. I want to operate on that axis vector with a transformation (matrix) and update it accordingly. I’m not familiar with numpy so there may be a way to do it therein.
In passing, I learned that you must initialize a two-dimensional matrix as a[[]] because the a[][] syntax doesn’t work in Python. This makes sense once I stopped thinking in C/C++ and started thinking in Python.
Joe Heafner
Sent from one of my Macs