# Difference between revisions of "Linear Algebra Wishlist"

(More info about Matrix methods given, a couple of items added to the "wish list" --- Christopher Heckman) |
|||

Line 1: | Line 1: | ||

− | 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. |
+ | 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. |

+ | <br /> |
||

+ | <br /> |
||

+ | <br /> |
||

+ | <span style="font-weight: bold;">1. Documentation of commands/parameters of the Vector and Matrix contexts. </span> |
||

+ | For example, |
||

+ | <br /> |
||

+ | <br /> |
||

+ | a. How to get the ith row of matrix A as a vector? (<b>$A->row(i)</b>) column j? (<b>$A->column(j)</b>) entry (i,j) |
||

+ | (<b>$A->element(i,j)</b>) |
||

+ | <br /> |
||

+ | <br /> |
||

+ | b. How to get the dimensions? (<b>$A->dimensions</b>) |
||

+ | <br /> |
||

+ | <br /> |
||

+ | c. Is anything special needed to use matrices with symbolic entries? (<b>Many things don't work, such as matrix multiplication. |
||

+ | This conclusion is the result of me spending a few hours on this topic.</b>) |
||

+ | <br /> |
||

+ | <br /> |
||

+ | d. Is there a det(A) command in MathObjects? (<b>Yes: $A->det</b>) Should there be one? |
||

+ | <br /> |
||

+ | <br /> |
||

+ | e. Do we have the following commands: |
||

+ | <br /> |
||

+ | (<b>Available commands are listed at the matrix page: http://webwork.maa.org/wiki/Matrix_(MathObject_Class)#Methods></b>) |
||

+ | <br /> |
||

<ul type="square"> |
<ul type="square"> |
||

− | <li>dim(A)<br /> </li> |
+ | <li>dim(A)<br /> (<b>Yes</b>)</li> |

− | <li>det(A)<br /> </li> |
+ | <li>det(A)<br /> (<b>Yes</b>)</li> |

<li>diag(A)<br /> </li> |
<li>diag(A)<br /> </li> |
||

<li>isdiag(A)<br /> </li> |
<li>isdiag(A)<br /> </li> |
||

<li>create elementary matrix<br /> </li> |
<li>create elementary matrix<br /> </li> |
||

+ | <li><b>Actually, better ways to construct and alter matrices would be nice as well.</b></li> |
||

<li>create upper triagonal<br /> </li> |
<li>create upper triagonal<br /> </li> |
||

− | <li>trace<br /> </li> |
+ | <li>trace<br /> (<b>Yes:</b>)</li> |

<li>calculate eigenvalues/vectors<br /> </li> |
<li>calculate eigenvalues/vectors<br /> </li> |
||

<li>row echelon<br /> </li> |
<li>row echelon<br /> </li> |
||

− | <li>test for symmetric<br /> </li> |
+ | <li>test for symmetric<br /> (<b>Yes</b>) </li> |

<li>performing row operations<br /> </li> |
<li>performing row operations<br /> </li> |
||

<li>exponentiation of matrices<br /> </li> |
<li>exponentiation of matrices<br /> </li> |
||

<li>canonical forms<br /> </li> |
<li>canonical forms<br /> </li> |
||

− | <li>inverse <br /> </li> |
+ | <li>inverse <br /> (<b>Yes</b>)</li> |

<li>rank<br /> </li> |
<li>rank<br /> </li> |
||

<li>powers of matrices<br /> </li> |
<li>powers of matrices<br /> </li> |
||

<li>LU decomp<br /> </li> |
<li>LU decomp<br /> </li> |
||

− | </ul> <br /> <br /> f. document the extraction of rows, columns, assign operations for MAtrix, vector objects.<br /> <br /> g. document how to create subclasses from classes of objects. i.e. Lists of Vectors would be a subclass of either Lists or vectors.<br /> <br /> 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.<br /> <br /> <br /> <span style="font-weight: bold;">2. Documentation and requests for answer evaluators that use MathObjects?</span> <br /> <br /> a. Can we have an explicit example of a problem that correctly evaluates a vector whose coefficients have variables in the coordinates?<br /> <br /> 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.<br /> <br /> c. Display of Mat2System with parameters (non-numerical) as entries<br /> <br /> d. conversion from n-dimensional vectors to deg (n-1) polynomials and back<br /> <br /> 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.<br /> <br /> 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.<br /> <br /> <br /> <span style="font-weight: bold;">3. Adaptation of existing macros for use for MathObjects.</span><br /> <br /> 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.<br /> <br /> 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?<br /> |
||

+ | </ul> |
||

− | <blockquote> Yes, MathObjects already has this. If <tt>$M</tt> is a Matrix, then <tt>$M->ans_array(5)</tt> would create an answer array rather than a single entry rule (as would be produced by <tt>$M->ans_rule(5)</tt>). See problem 72 in my talk slides. </blockquote> 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.<br /> <br /> d. How to adapt routines in MatrixMacros.pg and MoreMatrixMacros.pg to use MathObjects without rewriting the basic routines.<br /> <br /> <br /> 4. Other areas of need??<br /> <br /> |
||

+ | <br /> |
||

− | <h4><span style="font-weight: bold;">4. An example of a specific new MathObjects class that could be useful</span></h4> <br />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="http://aimwebwork.openwebwork.org/webwork2/byerly_course/sample/?login_practice_user=true">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.<br /><br />It would be nice to have a VectorList class invoked by something like:<br /> $L = VectorList($v1, $v2, ... );<br /> (and the obvious variants), where $v1, ... are vectors from the same euclidean space. Useful methods would include (feel free to add to this):<br /> <br /> |
||

+ | <br /> |
||

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

+ | <br /> |
||

+ | <br /> |
||

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

+ | <br /> |
||

+ | <br /> |
||

+ | 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. |
||

+ | <br /> |
||

+ | <br /> |
||

+ | <br /> |
||

+ | <span style="font-weight: bold;">2. Documentation and requests for answer evaluators that use MathObjects?</span> |
||

+ | <br /> |
||

+ | <br /> |
||

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

+ | <br /> |
||

+ | <br /> |
||

+ | 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. |
||

+ | <br /> |
||

+ | <br /> |
||

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

+ | <br /> |
||

+ | <br /> |
||

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

+ | <br /> |
||

+ | <br /> |
||

+ | 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. |
||

+ | <br /> |
||

+ | <br /> |
||

+ | 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. (<b>How about also the same thing for a list of vectors?</b>) |
||

+ | <br /> |
||

+ | <br /> |
||

+ | <br /> |
||

+ | <span style="font-weight: bold;">3. Adaptation of existing macros for use for MathObjects.</span> |
||

+ | <br /> |
||

+ | <br /> |
||

+ | 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. |
||

+ | <br /> |
||

+ | <br /> |
||

+ | 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? |
||

+ | <br /> |
||

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

+ | |||

+ | 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. |
||

+ | <br /> |
||

+ | <br /> |
||

+ | d. How to adapt routines in MatrixMacros.pg and MoreMatrixMacros.pg to use MathObjects without rewriting the basic routines. |
||

+ | <br /> |
||

+ | <br /> |
||

+ | <br /> |
||

+ | 4. Other areas of need?? |
||

+ | <br /> |
||

+ | <br /> |
||

+ | <h4><span style="font-weight: bold;">4. An example of a specific new MathObjects class that could be useful</span></h4> |
||

+ | <br /> |
||

+ | 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="http://aimwebwork.openwebwork.org/webwork2/byerly_course/sample/?login_practice_user=true">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. |
||

+ | <br /> |
||

+ | <br /> |
||

+ | It would be nice to have a VectorList class invoked by something like: |
||

+ | <br /> |
||

+ | $L = VectorList($v1, $v2, ... );<br /> (and the obvious variants), where $v1, ... are vectors from the same euclidean space. Useful methods would include (feel free to add to this):<br /> <br /> |
||

<ul type="circle"> |
<ul type="circle"> |
||

<li> $L->proj($v); # computes the vector projection of $v on the span of $L.<br /> </li> |
<li> $L->proj($v); # computes the vector projection of $v on the span of $L.<br /> </li> |
||

Line 26: | Line 87: | ||

<li> $L->inSpan($v); #is $v in the span of $L?<br /> </li> |
<li> $L->inSpan($v); #is $v in the span of $L?<br /> </li> |
||

<li> $L->eqSpan($L1); #does the VectorList $L1 have the same span as $L?<br /> </li> |
<li> $L->eqSpan($L1); #does the VectorList $L1 have the same span as $L?<br /> </li> |
||

− | </ul> <br /> 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.<br /> <br /> 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.<br /> <br /> 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.))<br /><br />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.<br /> |
||

+ | </ul> |
||

+ | <br /> |
||

+ | 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. |
||

+ | <br /> |
||

+ | <br /> |
||

+ | 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. |
||

+ | <br /> |
||

+ | <br /> |
||

+ | 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.)) |
||

+ | <br /> |
||

+ | <br /> |
||

+ | 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. |
||

+ | <br /> |
||

<h4>5. An example of a macro converted to a Math Object macro. <br /></h4> |
<h4>5. An example of a macro converted to a Math Object macro. <br /></h4> |
||

− | <p>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. </p |
+ | <p>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. </p> |

+ | <br /><pre># This routine display Ax=b in a pretty form, <ol> |
||

<li> where A is a numerical matrix, b is a </li> |
<li> where A is a numerical matrix, b is a </li> |
||

<li> numerical row vector, and x is a </li> |
<li> numerical row vector, and x is a </li> |

## Revision as of 23:07, 23 December 2013

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? (**$A->row(i)**) column j? (**$A->column(j)**) entry (i,j)
(**$A->element(i,j)**)

b. How to get the dimensions? (**$A->dimensions**)

c. Is anything special needed to use matrices with symbolic entries? (**Many things don't work, such as matrix multiplication.
This conclusion is the result of me spending a few hours on this topic.**)

d. Is there a det(A) command in MathObjects? (**Yes: $A->det**) Should there be one?

e. Do we have the following commands:

(**Available commands are listed at the matrix page: http://webwork.maa.org/wiki/Matrix_(MathObject_Class)#Methods>**)

- dim(A)

(**Yes**) - det(A)

(**Yes**) - diag(A)

- isdiag(A)

- create elementary matrix

**Actually, better ways to construct and alter matrices would be nice as well.**- create upper triagonal

- trace

(**Yes:**) - calculate eigenvalues/vectors

- row echelon

- test for symmetric

(**Yes**) - performing row operations

- exponentiation of matrices

- canonical forms

- inverse

(**Yes**) - 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. (**How about also the same thing for a list of vectors?**)

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

$Mis 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 MatrixMacros.pg and MoreMatrixMacros.pg 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="http://aimwebwork.openwebwork.org/webwork2/byerly_course/sample/?login_practice_user=true">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> <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> <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;