STACK DocumentationDocumentation home | Category index | Parent | Site map
Matrices and vectors in STACK.
Note that in Maxima, the operator
. represents noncommutative multiplication and scalar product.
A*B gives element-wise multiplication.
The paper Setting Linear Algebra Problems is rather interesting.
The following functions are part of Maxima, but are very useful for us.
m[i]: m[i] + k * m[j].
m[i]: k * m[i].
And a function to compute reduced row echelon form
Assigning individual elements
To assign values to individual elements, use the simple syntax such as the following.
Note also Maxima's
setelmx (<x>, <i>, <j>, <M>)
<x> to the
(<i>, <j>)'th element of the matrix
<M>, and returns the altered matrix.
<M> [<i>, <j>]: <x> has the same effect, but returns
<x> instead of
It is quite common to want to show part of a matrix calculation "un-evaluated". For example, the following is typical.
This is achieved, by having a question in which simplification is off, and we define the question variables as follows.
A:matrix([1,2],[4,5]); B:matrix([1,-1],[1,2]); C:apply(matrix,zip_with(lambda([l1,l2],zip_with("+",l1,l2)),args(A),args(B))); D:ev(C,simp);
Notice the use of
zip_with which is not a core Maxima function, but is defined by STACK.
The above equation is then generated by the CASText
A similar procedure is needed for showing working when multiplying matrices. Here we need to loop over the matrices, for square matrices we use the following.
A:ev(rand(matrix([5,5],[5,5]))+matrix([2,2],[2,2]),simp); B:ev(rand(matrix([5,5],[5,5]))+matrix([2,2],[2,2]),simp); BT:transpose(B); C:zeromatrix (first(matrix_size(A)), second(matrix_size(A))); S:for a:1 thru first(matrix_size(A)) do for b:1 thru second(matrix_size(A)) do C[ev(a,simp),ev(b,simp)]:apply("+",zip_with("*",A[ev(a,simp)],BT[ev(b,simp)])); D:ev(C,simp);
Notice we need to simplify the arguments before we take indices of expressions. This is one problem with
For non-square matrices we can use this.
A:ev(rand(matrix([5,5,5],[5,5,5]))+matrix([2,2,2],[2,2,2]),simp); B:transpose(ev(rand(matrix([5,5,5],[5,5,5]))+matrix([2,2,2],[2,2,2]),simp)); TA:ev(A.B,simp); BT:transpose(B); C:zeromatrix (first(matrix_size(A)), second(matrix_size(B))); S:for a:1 thru first(matrix_size(A)) do for b:1 thru second(matrix_size(B)) do C[ev(a,simp),ev(b,simp)]:apply("+",zip_with("*",A[ev(a,simp)],BT[ev(b,simp)])); D:ev(C,simp);
Now it makes no sense to include the point wise multiplication of elements as a possible wrong answer.
There must be a more elegant way to do this!
Display of matrices
You can set the type of parentheses used to surround matrices in a number of ways. Firstly, the admin user should set the site default in the qtype_stack options page.
For an individual question, the teacher can set the variable
in any of the usual places, e.g. in the question variables.
To set the display of an individual matrix,
m say, in CASText you can use
lxmchar is a global setting in Maxima, you will have to set it back when you next display a matrix. Not ideal, but there we are.
Note, STACK only displays matrices with matching parentheses. If you want something likethen you will have to display the matrix without parentheses and sort out the mismatching parentheses in the CASText at the level of display.
If you are trying to use the vector notation such as Numbers.you will probably want to redefine to be an abstract symbol, not a complex number. More information on this is given under
Another way to do this is to create matrices as follows:
ordergreat(i,j,k); p:matrix([-7],,[-3]); q:matrix([i],[j],[k]);
Now we can use the dot product to create the vector. The STACK function
texboldatoms prints all atomic variable names in bold.
If you turn the option "Multiplication sign" to none, this should display as
ordergreat. This can only be used once at the beginning of the question.
Students do find typing in matrices very tedious. Some teachers have asked for a convenient notation such as
for column vectors and
For row vectors. This is not a core part of STACK currently, but in individual questions you can convert such notation easily into mainstream Maxima using code such as the following.
ta1:c(1,2,3); ta2:v(1,2,3); vec_convert(sa) := if op(sa)=c then transpose(matrix(args(sa))) elseif op(sa)=v then matrix(args(sa)); vec_convert(ta1); vec_convert(ta2);
Once converted into Matrices, the student's answer will be evaluated by PRTs as matrices. Of course, this will not be reflected in the valuation. If there is sufficient demand for this contact the developers.
Documentation home | Category index | Parent | Site map