DOCUMENT(); loadMacros( "PGstandard.pl", "MathObjects.pl", # Used to provide contextual help for how to type answers. "AnswerFormatHelp.pl", # Provides greater control over the layout of the problem. "PGML.pl", # Used for course-specific initializations. "PGcourse.pl", ); TEXT(beginproblem()); ############################# # Setup # Used for handling matrix problems. Context("Matrix"); #-ULETH-# # ans : the random value of the determinant for the question. # M : A solution matrix used to verify a student answer or act as a solution set. $ans = non_zero_random(-10,10,1); $M = Matrix([ [$ans,6,1,9], [0,1,3,4], [0,0,1,6], [0,0,0,1], ]); #-ENDULETH-# ############################# # Main text #-ULETH-# BEGIN_PGML ###Enter a non-diagonal 4x4 matrix with a determinant of [$ans]. [`A =`] [@ $M->ans_array(5) @]* [@ AnswerFormatHelp("matrices") @]* END_PGML #-ENDULETH-# #-ULETH-# $showPartialCorrectAnswers = 0; ANS( $M->cmp( checker => sub { my ($M,$student,$ansHash) = @_; my ($sdet)=$student->det(); if ( $sdet != $ans ) { $ansHash->{ans_message} = "The determinant of your matrix is not so does not satisfy the conditions." unless $ansHash->{isPreview}; return 0; } # Check if diagonal my $isDiag = 1; my $zz = Real(0); for ( my $ii = 1; $ii <= 3 ; $ii++ ) { for ( my $jj = 1 + $ii; $jj <= 3 ; $jj++ ) { if ( ( $student->element($ii,$jj) != $zz ) || ( $student->element($jj,$ii) != $zz ) ) { $isDiag = 0; last; } last if ( $isDiag == 0 ); } } if ( $isDiag == 1 ) { $ansHash->{ans_message} = "Your matrix is a diagonal matrix so does not satisfy the conditions." unless $ansHash->{isPreview}; return 0; } else { return 1; } # should not get here $ansHash->{ans_message} = "Error in the grading code. Please report this." unless $ansHash->{isPreview}; return 0; } )); #-ENDULETH-# ############################# # Solution #-ULETH-# BEGIN_PGML_SOLUTION SOLUTION: One possible solution is [`A = [$M]`]. We know that the determinant of any upper triangular matrix is the product of the element along the diagonal. So by placing [`[$ans]`] anywhere on the diagonal and filling the upper half of the matrix with any numbers (since they do not effect the determinant). END_PGML_SOLUTION COMMENT(' Randomization provides 19 different possible versions of this question.
Includes a solution set.
Recommended Settings:
- Weight: 2
- Max attempts: Unlimited
- Show me another: -2
- Rerandomize after: Default
Made from a ULETH template.
'); #-ENDULETH-# ENDDOCUMENT();