WeBWorK Problems

Another Matrix Display Issue - Yes/No questions

Another Matrix Display Issue - Yes/No questions

by Murphy Waggoner -
Number of replies: 8
Hello, again, 

Code below.  Image attached.  The vectors (n x 1 matrices) display beautifully in the text before the Yes/No questions, but in the Yes/No questions they display horizontally.  I can get around this by listing the vectors in the questions before the questions, but I'd like to know what the issue is here.  

Thanks.

Murphy

## DESCRIPTION
## True or False problem concerning for elementary row operations and solving systems of linear equations
##
##
##  Note:  all questions and explanations are from David Lay's Linear Algebra and its Applications 4ed except where noted.  Other explanations were written by Martha Ellen Waggoner (MEW).
##
##
##  Warning:  There are specific references to the Lay Linear Algebra text in the explanations, and thus, would make these questions difficult to use as is for a different textbook.
##
## ENDDESCRIPTION


## DBsubject(Linear Algebra)

###########################
#  Initialization

DOCUMENT();

loadMacros(
"PGstandard.pl",
"MathObjects.pl",
"PGchoicemacros.pl",
"PGgraders.pl",
 "problemRandomize.pl"
);

TEXT(beginproblem());
ProblemRandomize(when=>"Always");                 # always can reseed (after due date)



###########################
#  Setup

 Context("Matrix");
$a = Matrix([[2],[-2],[4]]);
$b = Matrix([-3],[3],[-6]);
$c = Matrix([0],[4],[-3]);
$d = Matrix([2],[4],[6]);
$e = Matrix([-2],[6],[-7]);

# Create and use pop up lists 
$tf = new_select_list();
$tf->rf_print_q(~~&pop_up_list_print_q);

# Choices presented to students
$tf->ra_pop_up_list( [ 
"No answer" => "?", 
"Yes"  => "Yes", 
"No" => "No",
]);


# Questions and answers
$tf -> qa ( 
"Is \(\mathbf{d} = $d\) in \(\text{Span}\lbrace \mathbf{a}, \mathbf{b}, \mathbf{c}\rbrace\)?",
"No",
"Does \(\lbrace \mathbf{a}, \mathbf{b}, \mathbf{c}\rbrace\) span \(\mathbb{R}^3\).",
"No",
"Is \(\mathbf{e} = $e\) in the image of \(T(\mathbf{x}) = A\mathbf{x}\)? ",
"Yes",
"Is \(A\mathbf{x} = \mathbf{g}\) consistent for all possible \(\mathbf{g}\)?",
"No",
"Is \(A\mathbf{x} = \mathbf{0}\) consistent?",
"Yes",
);

# How many questions to use
# The grader and solution below assumes that this number is 5
$tf->choose(5);


###########################
#  Main text

Context()->texStrings;
BEGIN_TEXT

Consider the vectors \(\mathbf{a} = $a\), \(\mathbf{b} = $b\), \(\mathbf{c} = $c\), and the matrix  \(A = [\mathbf{a}\ \ \mathbf{b}\ \ \mathbf{c}]\).  Answer these questions.  


Mark the following statements True or False 
$BR
\{ $tf -> print_q() \}
END_TEXT
Context()->normalStrings;


############################
#  Answer evaluation

$showPartialCorrectAnswers = 1;

#
#  Incremental grader
#  Note that as originally written this grading statement assumes there will be 5 questions
#
install_problem_grader(~~&custom_problem_grader_fluid);
$ENV{'grader_numright'} = [3,5,7];
$ENV{'grader_scores'} = [0.3,0.6,1];
$ENV{'grader_message'} = "You can earn " .
"30% partial credit for 3 correct answers, and " .
"60% partial credit for 5 correct answers.";

#
#  All or nothing grader
#  
# install_problem_grader(~~&std_problem_grader);

ANS( str_cmp( $tf->ra_correct_ans() ) );

# the remainder of the code is included to
#    provide a sensible solution for the
#    student.

# the answers to the questions that were
#    asked, in order, are
@correctAns = @{$tf->ra_correct_ans};

# the following becomes necessary if we want
#    to figure out what questions were asked
#    so that we can give explanations for 
#    them.  
# it's useful to define an array of 
#    explanations that correspond to the
#    list of questions we might have asked
@explanations = (
"The system \(A\mathbf{x} = \mathbf{d}\) has no solution because the matrix reduction of \([ \mathbf{a\ \ b\ \ c\ |\ d}]\) has a pivot in the right-most column.",
"By Theorem 4 in Section 1.4, not(d) => not(c).",
"The system \(A\mathbf{x} = \mathbf{e}\) has infinitely many solutions because the matrix reduction of \([ \mathbf{a\ \ b\ \ c\ |\ e}]\) does not have a pivot in the right-most column and the matrix reduction of \([ \mathbf{a\ \ b\ \ c\}]\) has a pivotless column .",
"By Theorem 4 in Section 1.4, not(d) => not(a).",
"All homogeneous systems are consistent."
);

# then find the questions that were asked
@askedQuestions = ();
foreach $q ( @{$tf->selected_q} ) {
  $i = 0;
  foreach $mq ( @{$tf->questions} ) {
    if ( $q eq $mq ) {
      push(@askedQuestions, $i);
      last;
    }
    $i++;
  } 
}
# now we know which questions were asked,
#    and can print the corresponding 
#    explanations for the solution
#  
# MEW:  as written this assumes there were 5 questions asked
#
#SOLUTION(EV3(<<'END_SOLUTION'));
BEGIN_SOLUTION
$PAR SOLUTION $PAR
 
Question 1: $correctAns[0].  
$explanations[$askedQuestions[0]]

$PAR
 
Question 2: $correctAns[1].  
$explanations[$askedQuestions[1]]

$PAR
 
Question 3:  $correctAns[2].  
$explanations[$askedQuestions[2]]

$PAR
 
Question 4:
$correctAns[3].  
$explanations[$askedQuestions[3]]

$PAR
 
Question 5:
$correctAns[4]. 
$explanations[$askedQuestions[4]]

END_SOLUTION



COMMENT("MathObject version.");

ENDDOCUMENT();
Attachment New_Picture.jpg
In reply to Murphy Waggoner

Re: Another Matrix Display Issue - Yes/No questions

by Davide Cervone -
The problem is that in
# Questions and answers
$tf -> qa ( 
"Is \(\mathbf{d} = $d\) in \(\text{Span}\lbrace \mathbf{a}, \mathbf{b}, \mathbf{c}\rbrace\)?",
"No",
"Does \(\lbrace \mathbf{a}, \mathbf{b}, \mathbf{c}\rbrace\) span \(\mathbb{R}^3\).",
"No",
"Is \(\mathbf{e} = $e\) in the image of \(T(\mathbf{x}) = A\mathbf{x}\)? ",
"Yes",
"Is \(A\mathbf{x} = \mathbf{g}\) consistent for all possible \(\mathbf{g}\)?",
"No",
"Is \(A\mathbf{x} = \mathbf{0}\) consistent?",
"Yes",
);
the values of $d and the other variables are inserted into the strings at this point. Because the Context()->texStrings call is below this, the results of inserting those variables will be algebra strings rather than TeX strings. If you move the Context()->texStrings to before the $tf->qa() call, I think you will get the result you want.
In reply to Murphy Waggoner

Re: Another Matrix Display Issue - Yes/No questions

by Jeremy Sylvestre -
You can also use a MathObject's TeX method to display the TeX representation of the object outside of Context()->texStrings.

I think something like

"Is \(\mathbf{d} = \{$d->TeX\}\) in \(\text{Span}\lbrace \mathbf{a}, \mathbf{b}, \mathbf{c}\rbrace\)?",

should work.

Also, instead of \text{Span} you might use \operatorname{Span}.

In reply to Jeremy Sylvestre

Re: Another Matrix Display Issue - Yes/No questions

by Davide Cervone -
This would work inside BEGIN_TEXT/END_TEXT but not within a string in general, since the string version of $d will be interested into the string at the point the string is created. So the string will become
  "Is \(\mathbf{d} = \{[[1,2],[3,4]]->TeX\}\) in ..."
The processing of the \(...\) and \{...\} are not done at string creation time, but rather when this string is used inside BEGIN_TEXT/END_TEXT, and that is long after the value of $d has been substituted into the string. So the result would not be the TeX version of the MathObject, unfortunately.
In reply to Davide Cervone

Re: Another Matrix Display Issue - Yes/No questions

by Jeremy Sylvestre -
Oops, right. I should have tested it before posting. I'm in the middle of converting a bunch of my problems to MathObjects, and I was sure I had done things that way in some problem. But looking back I see I saved the TeX method output to a string first. As in:

$d_TeX = $d->TeX;

$tf -> qa ( 
"Is \(\mathbf{d} = $d_TeX\) in \(\text{Span}\lbrace \mathbf{a}, \mathbf{b}, \mathbf{c}\rbrace\)?",
"No",
);

Probably easier just to wrap Context()->texStrings / Context()->normalStrings around the qa() call as you suggested. :)
In reply to Jeremy Sylvestre

Re: Another Matrix Display Issue - Yes/No questions

by Davide Cervone -
Well, another option is to use
$tf -> qa ( 
"Is \(\mathbf{d} = ".$d->TeX."\) in \(\text{Span}\lbrace \mathbf{a}, \mathbf{b}, \mathbf{c}\rbrace\)?",
"No",
);
rather than using a separate variable. A period is the string concatenation operator in perl.
In reply to Davide Cervone

Re: Another Matrix Display Issue - Yes/No questions

by Murphy Waggoner -
Thanks, all.  I understand now.

About the \text v. \operatorname issue - operatorname has 8 additional characters and requires two-handed typing.  I was conserving keystrokes and reducing the chances for typographical errors by choosing a shorter command.  Is there an advantage to the latter over the former?
In reply to Murphy Waggoner

Re: Another Matrix Display Issue - Yes/No questions

by Davide Cervone -
There are several advantages: first, \operatorname will produce the proper spacing before and after for an operator, which is slightly different from that for \text in some situations. Second, \operatorname will allow the use of \limits and \nolimits for handling the placement of superscript and subscripts to that they act like \sum. For example, \operatorname{sup}_{x\in X} would put the subscript underneath the "sup" when used in displaystyle. Third, and perhaps most important, \operatorname gives the proper semantics for the usage (where \text gives the wrong semantics), and that can help things like screen readers to better voice the meaning of your expression. So while it is a little longer to type, it is good to get in the habit of using it.