From WeBWorK

Jump to: navigation


This method returns a random nxn diagonal matrix.


Compares a list of vectors by finding the change of coordinate matrix from the Prof's vectors to the students, and then taking the determinant of that to determine the existence of the change of coordinate matrix going the other way.

ANS( basis_cmp( vectors_as_array_ref_in_array_ref, options_hash ) );

    1. a reference to an array of correct vectors
    2. a hash with the following keys (all optional):
        mode            --  'basis' (default) (only a basis allowed)
                            'orthogonal' (only an orthogonal basis is allowed)
                            'unit' (only unit vectors in the basis allowed)
                            'orthonormal' (only orthogonal unit vectors in basis allowed)
        zeroLevelTol    --  absolute tolerance to allow when answer is close
                                 to zero
        debug           --  if set to 1, provides verbose listing of
                                hash entries throughout fliters.
        help        --  'none' (default) (is quiet on all errors)
                    'dim' (Tells student if wrong number of vectors are entered)
                    'length' (Tells student if there is a vector of the wrong length)
                    'orthogonal' (Tells student if their vectors are not orthogonal)
                            (This is only in orthogonal mode)
                    'unit' (Tells student if there is a vector not of unit length)
                            (This is only in unit mode)
                    'orthonormal' (Gives errors from orthogonal and orthonormal)
                            (This is only in orthonormal mode)
                    'verbose' (Gives all the above answer messages)
    Returns an answer evaluator.


                                    --  correct answer is any basis for R^3.
    basis_cmp([1,0,2,0],[0,1,0,0], 'mode'=>orthonormal )
                                    --  correct answer is any orthonormal basis
                                        for this space such as:


Made to keep the same format as num_cmp and fun_cmp.


    compare_basis( $ans_hash, 
        ra_student_ans     # a reference to the array of students answer vectors
        rm_correct_ans,    # a reference to the correct answer matrix


This is a check_syntax type method (in fact I borrowed some of that method's code) for vector input. The student needs to enter vectors like: [1,0,0],[1,2,3],[0,9/sqrt(10),1/sqrt(10)] Each entry can contain functions and operations and the usual math constants (pi and e). The vectors, however can not be added or multiplied or scalar multiplied by the student. Most errors are handled well. Any error in an entry is caught by the PG_answer_eval like it is in num_cmp or fun_cmp. Right now the method basically ignores every thing outside the vectors. Also, an unmatched open parenthesis is caught, but a unmatched close parenthesis ends the vector, and since everything outside is ignored, no error is sent (other than the later when the length of the vectors is checked. In the end, the method returns an array of Matrix objects.

    This filter was created to get, format, and evaluate each entry of the ans_array and ans_array_extension
    answer entry methods. Running this filter is necessary to get all the entries out of the answer
    hash. Each entry is evaluated and the resulting number is put in the display for student answer
    as a string. For evaluation purposes an array of arrays of arrays is created called ra_student_ans
    and placed in the hash. The entries are [array_number][row_number][column_number]. The latex strings
    for each entry are taken from the parser and put, as a matrix, into the previewer. The preview text
    string is also created, but this display method becomes confusing when large matrices are used.