Linear Algebra Wishlist

From WeBWorK_wiki
Revision as of 12:46, 13 June 2008 by Gage (talk | contribs) (New page: <div class="indent" style="margin-left: 15px;"> <div class="indent" style="margin-left: 15px;"></div> </div> <div class="indent" style="margin-left: 15px;"> <div class="indent" style=...)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

There are a number of areas where we can improve the ability of Webwork and MathObjects to work with Linear Algebra problems. Having a good toolkit for dealing with Matrix and Vector objects is important, since there are many types of problems one may wish to ask students.

1. Documentation of commands/parameters of the Vector and Matrix contexts. For example,

a. How to get the ith row of matrix A as a vector? column j? entry (i,j)

b. How to get the dimensions?

c. Is anything special needed to use matrices with symbolic entries?

d. Is there a det(A) command in MathObjects? Should there be one?

e. Do we have the following commands:

  • dim(A)
  • det(A)
  • diag(A)
  • isdiag(A)
  • create elementary matrix
  • create upper triagonal
  • trace
  • calculate eigenvalues/vectors
  • row echelon
  • test for symmetric
  • performing row operations
  • exponentiation of matrices
  • canonical forms
  • inverse
  • rank
  • powers of matrices
  • LU decomp

f. document the extraction of rows, columns, assign operations for MAtrix, vector objects.

g. document how to create subclasses from classes of objects. i.e. Lists of Vectors would be a subclass of either Lists or vectors.

h. within the subclass or within Matrix class, have operations like projection(v) onto a set S of vectors, or calculation dim(S) (which = rank(M)). Other ones, would be 1) comparison of two bases 2) checking if something is in the span, ... Bob has routines like this which are both post Math-Objects and pre Math-Objects. Can we update these to be cleaner routines using MathObjects and sub-classess.

2. Documentation and requests for answer evaluators that use MathObjects?

a. Can we have an explicit example of a problem that correctly evaluates a vector whose coefficients have variables in the coordinates?

b. Can we have an example of an open-ended custom answer evaluator that takes evaluates a given student entered vector (matrix) and evaluates it. In particular, can we have documentation of how the error messages are created, how the partial credit would work, and how to ensure a "correct" answer is displayed to students after the due date. Also, how to have a hint displayed to students if needed.

c. Display of Mat2System with parameters (non-numerical) as entries

d. conversion from n-dimensional vectors to deg (n-1) polynomials and back

e. Conversion routine from MathObject Matrix (vector) to matrix (vector) that can be inputted into CPAN routines. and vice-versa from CPAN object to MathObject.

f. Can a a student enter a matrix directly into WW without having to give the size of the matrix beforehand? One idea would be to use a multi-part problem, where the first step is to enter the size of the matrix.

3. Adaptation of existing macros for use for MathObjects.

a. Mat2System(A,variables, b) (a user-contributed function, not part of the WeBWorK distribution) displays a system of equations corresponding to the system Ax=b in a pretty manner.

b. There is currently a macro that creates a matrix in which each entry is an answer box. Is this compatible with MathObjects? How do we create a compatible MathOjects answer evaluator for this?

Yes, MathObjects already has this. If $M is a Matrix, then $M->ans_array(5) would create an answer array rather than a single entry rule (as would be produced by $M->ans_rule(5)). See problem 72 in my talk slides.

c. Here's a related request. Can we give students a partially completed matrix and ask the student to fill in the remaining entries, and then have both the display of the original matrix and the answer evaluator be handled within MathObjects mode.

d. How to adapt routines in and to use MathObjects without rewriting the basic routines.

4. Other areas of need??

4. An example of a specific new MathObjects class that could be useful

Many of us want to write more conceptual problems for Linear Algebra and will need to supply our own answer checkers. (E.g., ask questions such as: find a member of a certain subspace satisfying certain properties.) It is also desirable to adapt some old answer evaluators (e.g., checking whether a list of vectors is a basis for a particular subspace) for use with MathObjects. After some experience with fighting with this, here are some specific suggestions for a new MathObjects class that could be useful. It is partly based on an existing VectorList class (<a href="">here are some examples</a>) that one of us has found useful for dealing with these issues, but which is not a real MathObjects class as yet, although it does use MathObjects.

It would be nice to have a VectorList class invoked by something like:
$L = VectorList($v1, $v2, ... );
(and the obvious variants), where $v1, ... are vectors from the same euclidean space. Useful methods would include (feel free to add to this):

  • $L->proj($v); # computes the vector projection of $v on the span of $L.
  • $L->dim; #computes the dimension the span of $L
  • $L->inSpan($v); #is $v in the span of $L?
  • $L->eqSpan($L1); #does the VectorList $L1 have the same span as $L?

What cmp method should the class have? Probably its behavior should depend on flags passed. For example, "ANS($L->cmp(eqBases=>1))" might check whether the student entered a basis for the space spanned by $L. Another useful behavior might be simply to check whether the student's answer has the same span as the professor's answer.

A class like this could form the basis for a toolkit a problem writer could use to design a variety of other answer evaluators useful for linear algebra.

The user-written VectorList class referred to above works by converting a list of MathObject Vectors to a MatrixReal1 matrix (macros for dealing with these are found in the WeBWork pg directory). An LU-decomposition is performed and used to get the needed information about the list of vectors. One of the things computed is a matrix representation for the projection into the space generated by the list of vectors. This matrix is converted to a MathObjects matrix. A basis comparison answer-evaluator can be based on this which, unlike the older basis_cmp answer evaluator, uses fuzzy comparison. (The algorithm is: check the student's answer to make sure it has the same dimension as the professor's. Then check that each vector of the student's answer is in the space generated by the professor's answer by projecting each vector of the student's answer into that space. If $L is the professor's answer, $v is in span($L) if $L->proj($v) == $v. Since this comparison is fuzzy, the student does not have to be as precise as when the older basis_cmp was used. (This older evaluator required very high precision on the student's part when a vector such as (1, sqrt(2)) was in the professor's answer.))

The behind-the-scenes calculations can be performed by any good matrix package. Robert Molzon has suggested looking at PDL for this rather than the older MatrixReal1.

5. An example of a macro converted to a Math Object macro.

This macro prints a system of linear equations nicely on the screen. The only conversion needed involved deleting a dim() method which had been applied to A, x, and b and inserting the appropriate MathObject/Perl command to get the dimensions.

# This routine display Ax=b in a pretty form, <ol>
  <li> where A is a numerical matrix, b is a </li>
  <li> numerical row vector, and x is a </li>
  <li> Perl list of variables. </li>
</ol> sub Mat2System{ my $coeffs= shift(); my $vec = shift(); my $vname= shift(); my ($srow,$scol) = $coeffs->dimensions; my ($vrow) = $vec->dimensions; my ($vnamecol) = scalar(@{$vname}); die "Wrong number of rows or columns" if $vrow != $srow; my $outstr="\\begin{array}"; my $s; $outstr = $outstr . '{r'; for(my $j=0; $j<$scol; $j++){ $outstr = $outstr . 'rr'; } $outstr = $outstr . 'r}'; for(my $j=0;$j<$srow;$j++){ $s=0; for(my $i=0,my $vn=1;$i<$scol;$i++,$vn++){ my $varname=$vname->[$vn-1]; my $a=$coeffs->element($j+1,$i+1); if($a==0){ <ol>
      <li> if coefficient is 0 then goto the next column by putting 2 &&'s </li>
    </ol> </li>
</ol> $outstr = $outstr . '&&'; }elsif($a>0){ if($a<tt>1){$a="";} if($s</tt>0){$outstr = $outstr . "& $a \\,$varname";$s=1; } else{$outstr=$outstr . "&+& $a \\, $varname";} }else{ if($s <tt> 1){ $a=-$a; if($a</tt>1){$a="";} $outstr= $outstr . "&- &$a \\,$varname"; }else{ if($a==-1){$a="-";} $outstr = $outstr . "& $a \\, $varname";$s=1;} } } $outstr = $outstr . "&=&" . $vec->element($j+1). "\\\\"; } $outstr= $outstr . ' \\end{array}'; return $outstr; } <ol>
  <li> This routine display Ax=b in a pretty form, when b has a symbolic variable </li>
</ol> sub Mat2System2{ my $coeffs= shift(); my $vec = shift(); my $vname= shift(); my ($srow,$scol) = $coeffs->dimensions; my ($vrow) = scalar(@{$vec}); my ($vnamecol) = scalar(@{$vname}); die "Wrong number of rows or columns, $vrow, $srow " if $vrow != $srow; my $outstr="\\begin{array}"; my $s; $outstr = $outstr . '{r'; for(my $j=0; $j<$scol; $j++){ $outstr = $outstr . 'rr'; } $outstr = $outstr . 'r}'; for(my $j=0;$j<$srow;$j++){ $s=0; for(my $i=0,my $vn=1;$i<$scol;$i++,$vn++){ my $varname=$vname->[$vn-1]; my $a=$coeffs->element($j+1,$i+1); if($a==0){ <ol>
      <li> if coefficient is 0 then goto the next column by putting 2 &&'s </li>
    </ol> </li>
</ol> $outstr = $outstr . '&&'; }elsif($a>0){ if($a<tt>1){$a="";} if($s</tt>0){$outstr = $outstr . "& $a \\,$varname";$s=1; } else{$outstr=$outstr . "&+& $a \\, $varname";} }else{ if($s <tt> 1){ $a=-$a; if($a</tt>1){$a="";} $outstr= $outstr . "&- &$a \\,$varname"; }else{ if($a==-1){$a="-";} $outstr = $outstr . "& $a \\, $varname";$s=1;} } } $outstr = $outstr . "&=&" . $vec->[$j]. "\\\\"; } $outstr= $outstr . ' \\end{array}'; return $outstr; } 1;