-
-
Notifications
You must be signed in to change notification settings - Fork 76
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add elementary, permutation, and zero matrix constructors #1012
Conversation
I have some updates to Matrix objects as well. I started a discussion at #991 but no one weighed in. I think this is a good idea--there was some discussion about moving more into the MathObjects directly instead of using some of the macros. |
I did not know about this macro: https://webwork.pcc.edu/webwork2/pod/macros/math/MatrixReduce.pl It has some of the same functionality here that I'm adding to lib. |
I've got a few things started on this as well. Let's talk so we're not duplicating things. |
I opted for consistency with the macro that was already here for making an identity matrix. Should I change that one too? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think these are good additions. I added a few code suggestions.
One problem with adding to this file (and a problem with MathObjects to begin with) is that there is no POD. As such we have to rely on adding documentation to the wiki (or elsewhere). A big project that is needed is to add (good) POD documentation to these files so that it is available in the POD that can be accessed from the PG problem editor.
I started doing this for this file when I added another method to this module. After we get this in, I can add another PR to do this. And clearly, we should do more with the other MathObjects. |
Some of what you see might just be that I tried to keep the new methods consistent with the existing identity matrix method. But I'm going to go in now and make changes throughout. |
I see. I didn't look around elsewhere in the file. |
32be156
to
f25258f
Compare
I just made updates as suggested by @pstaabp and @drgrice1. I made one additional change that mostly removes the need for One question I have (because now is the time) is if this format for the elementary matrix syntax can be improved upon. One of the existing macro libraries can make these matrices too, but it uses different methods to produce a row-scale matrix, a row-swap matrix, and the other kind. I wanted something where they all fall under the same method name ( |
Are you referring to the methods in the One thing I noticed is that some of these methods allow calling them with a $matrix = Matrix([[1, 2, 3], [4, 5, 6], [7, 8, 9]]);
$I = $matrix->I; However, the new $matrix1 = Matrix([[1, 2, 3], [4, 5, 6], [7, 8, 9]]);
$matrix2 = $matrix1->P(undef, [2, 3]); |
Now you can do all of these:
The zero matrix is the only one allowed to be nonsquare, so if generated from For the others, they must be square. Since these matrices (I, E, P) are most often used to multiply on the left, I made it so that if |
I have not touched POD, because I do not know what the greater POD scheme should be for files like this. |
Awesome. You read my mind on allowing The POD can be left for later. |
Got around to testing again. I think the basic API for these functions is good. It would be nice to not have to do the |
Note that you can do things like:
to avoid doing:
|
The Matrix class already has an identity matrix constructor. For example:
Value:Matrix->I(4)
. Or if$A
is already a 4x4 matrix, then$A->I
will do the same.This PR adds a few more constructors for special matrices, so you can just ask for them rather than have to build them element by element in a problem. I would like feedback on whether or not it is OK to put these directly into the Matrix class, instead of into some linear algebra macro file.
Value:Matrix->E(4, [2], 3)
makes a 4x4 matrix such that left multiplication with a 4xn matrix scales the 2nd row by 3.Value:Matrix->E(4, [2,3])
makes a 4x4 matrix such that left multiplication with a 4xn matrix swaps the 2nd and third rows.Value:Matrix->E(4, [2,3], 5)
makes a 4x4 matrix such that left multiplication with a 4xn matrix replaces the 2nd row with the 2nd row added to 5 times the 3rd row.Value:Matrix->P(4, [1,2,3])
makes a 4x4 matrix corresponding to the cycle (123).Value:Matrix->P(4, [1,2,3], [1,4], ...)
makes a 4x4 matrix corresponding to the product of the given cycles.Value:Matrix->Zero(4, 5)
makes a 4x5 matrix of all zeros.Value:Matrix->Zero(4)
makes a 4x4 matrix of all zeros.All of the constructors can be called as a method from an existing matrix like
$A
. However in most cases you still must supply all the arguments. The exception is with a zero matrix, where$A->Zero
will give you a zero matrix with the same dimensions as$A
.