### Multiple Choice problems with Mathobjects answers and extras

by David Gilliam -
I am trying to author multiple choice problems in which the answers and extras involve mathematical expressions containing random parameters and functions (e.g., sin($a t), e^{$b t}, $c t^{$d t}). I can do this using $mc = new_checkbox_multiple_choice(); $mc -> qa (" "," "); and $mc -> extra( ). But I cannot produce exercises that take advantage of the useful simplifications obtained from Mathobjects (using, for example, Compute or Formula). This means that the answers I can get to work still contain terms like 0 e^t and 1 t^2. My guess is that the allowed expressions in qa (" "," "); and $mc -> extra( ), for some reason, don't play well with Mathobjects. I have searched through the forum and all the examples I find either use simple text answers or very simply math like e^x, tan(x), etc. Could someone please shed some light on why I can't use Mathobjects in MC questions to get nicely formatted answer choices or explain how I can do this properly. Thanks in advance for your help.

In reply to David Gilliam
Monday, 27 August 2018, 1:54 PM

### Re: Multiple Choice problems with Mathobjects answers and extras

by Danny Glin -
The multiple choice objects in PGchoicemacros.pl predate MathObjects, so it's not overly surprising that they don't play nice with MathObjects.

In fact, these type of multiple choice questions have some other issues because of the way they interpolate variables, which is different from how it is handled in a BEGIN_TEXT/END_TEXT block. I don't know all the details, but I remember having similar problems to what you describe.

I believe to get what you are asking you will need to change to texStrings before you create the multiple choice object. I believe the following code snippet accomplishes what you want:

$f = Compute("(0*x^2+7*x-5)/(5*x+3)")->reduce();

Context()->texStrings;

$mc = new_checkbox_multiple_choice();

$mc -> qa ("Text here is \($f\)","Correct Ans \($f\)");

$mc -> extra("Wrong answer \($f\)");

BEGIN_TEXT

\{$mc->print_q()\}

\{$mc->print_a()\}

END_TEXT

Context()->normalStrings;

ANS( checkbox_cmp( $mc->correct_ans() ) );

In this case, I get the MathObjects reductions and the properly typeset formula in the multiple choice quesiton.

Note that there is a MathObjects version of the multiple choice object (see the second example at http://webwork.maa.org/wiki/MultipleChoiceProblems). It looks like this is limited to radio buttons (one correct answer), and I don't see a corresponding object for multi-select questions.

In reply to Danny Glin
Monday, 27 August 2018, 4:59 PM

### Re: Multiple Choice problems with Mathobjects answers and extras

by David Gilliam -
Thank you very much. Your suggestion of moving Context()->texStrings; before the $mc has made a great difference in how the exercises are visualized. Things are much better now thanks to you.

I am still curious if there is a better way to do the type of problem (like multiple choice) where there are several possible wrong answers and correct answer(s) for which the order is shuffled and the answers are all constructed with MathObjects.

In reply to David Gilliam
Monday, 27 August 2018, 6:15 PM

### Re: Multiple Choice problems with Mathobjects answers and extras

by Danny Glin -
Can you post a sample of the type of question you are asking. Perhaps someone will have ideas as to how to better implement it.

In reply to Danny Glin
Tuesday, 28 August 2018, 7:53 AM

### Re: Multiple Choice problems with Mathobjects answers and extras

by David Gilliam -
Danny

I fear that my main problem is a lack of understanding of basic things involving MathObjects. I was hoping to compute answers and wrong answers using things like $F><$G and $F.$G where $F and $G are Vector functions. But they don't seem to work for me. Using your suggestion to move Context()->texStrings; to before the $mc definition I am now okay but don't understand why I can't display things like $F><$G.

I'm reluctant to post an example due to making public my poor programming skills -- but I will go ahead and post an example that does not work for me and hopefully gain some insight into what is wrong with my thinking. I expect it has to do with executing and displaying things like $F><$G and $F.$G.

Also, concerning my thought of finding an alternative to using Multiple Choice, I wish I could have a little more control over the display of the multiple choice questions. For example, I would like to have more space between the rows and so on.

Thanks to all who have responded to my post.

David Gilliam

%%%%%%%%%%%%%%%%%%%%%%%%

DOCUMENT();

loadMacros(

"PGstandard.pl",

"PGML.pl",

"PGgraphmacros.pl",

"MathObjects.pl",

"PGcourse.pl",

"PGchoicemacros.pl",

"PGbasicmacros.pl",

);

TEXT(beginproblem());

$showPartialCorrectAnswers = 1;

######################################################################

Context("Vector");

$context = Context();

$context->flags->set(ijk=>1);

$context->variables->add( t=>'Real');

$a= random(2,5,1);

$b= random(2,4,1);

while ($a == $b)

{$b = non_zero_random(2,4,1); }

$a1 = non_zero_random(2,4,1);

$a2 = non_zero_random(-3,3,1);

$a3 = non_zero_random(-1,1,1);

do { $a3 = non_zero_random(-1,1,1); } until ($a3 != $a1 || $a3 != $a2);

$b1 = non_zero_random(-3,3,1);

$b2 = random(-1,1,1);

$b3 = non_zero_random(-5,5,1);

do { $b3 = non_zero_random(-5,5,1); } until ($a1 * $b1 + $a2 * $b2 + $a3 * $b3 != $a1*$b3 + $a2*$b2 + $a3*$b1);

$n= random(1,4,1);

$m= random(1,6,1);

$f1= Formula( "$a1 t^$n" )->reduce ;

$f2= Formula(" $a2 sin($a t) ")->reduce ;

$f3= Formula(" $a3 " )->reduce;

$F = Compute( "< $f1 , $f2, $f3>" ) ;

$g1= Formula(" $b1 cos($b t)")->reduce ;

$g2= Formula(" $b2 ")->reduce ;

$g3= Formula( "$b3 e^{$m t}")->reduce ;

$G = Compute("< $g1 , $g2, $g3>" );

# Rather than computing FxG by hand like this (which does work well)

$FxG = Compute(" <$a3 $b3 e^{$m t} - $a3 $b2 , -($a1 $b3 t^$n e^{$m t} - $a3 $b1 cos($b t)), $a1 $b2 t^{$n} - $a2 $b1 sin($a t) cos($b t)> ")->reduce;

# I had hoped to simply compute

$FprodG = Formula("$F >< $G")->reduce;

# and then compute extra wrong answers using things like

$GprodF = Compute("$G >< $F");

$FdotG = Compute("$F . $G");

Context()->texStrings;

$mc = new_checkbox_multiple_choice();

$mc -> qa (" "," \($FprodG\) ");

$mc -> extra( " \($GprodF \) ", "\($FdotG \) " );

$mc -> makeLast("None of the above");

BEGIN_PGML

Let [` \mathbf{F}(t) = \displaystyle [$F] `] and [` \mathbf{G}(t) = \displaystyle [$G] `] and find [` \mathbf{F}(t) \times \mathbf{G}(t) `].

[@ $mc -> print_q() @]***

[@ $mc -> print_a() @]***

END_PGML

Context()->normalStrings;

$showPartialCorrectAnswers = 1;

ANS( checkbox_cmp( $mc->correct_ans() ) );

COMMENT('PGML version');

######################################################################

ENDDOCUMENT(); # This should be the last executable line in the problem.

In reply to David Gilliam
Monday, 27 August 2018, 11:24 PM

### Re: Multiple Choice problems with Mathobjects answers and extras

by Ryan Maccombs -
This is what I would do

DOCUMENT();

loadMacros(

"PG.pl",

"PGbasicmacros.pl",

"PGchoicemacros.pl",

"PGanswermacros.pl",

"MathObjects.pl",

"PGML.pl",

);

$showPartialCorrectAnswers = 0;

$f1 = Formula("1*x+0")->reduce;

$f2 = Formula("2*x+0")->reduce;

$f3 = Formula("3*x+0")->reduce;

$f4 = Formula("4*x+0")->reduce;

$f5 = Formula("5*x+0")->reduce;

Context()->texStrings;

$mc = new_checkbox_multiple_choice();

$mc->qa("QUESTION", "\($f1\)", "\($f3\)" );

$mc->extra( "\($f2\)","\($f4\)", "\($f5\)");

$mc->makeLast("None of the above.");

#########################################

BEGIN_PGML

Which is my favorite?

[@ $mc->print_a() @]*

END_PGML

ANS( checkbox_cmp( $mc->correct_ans() ) );

ENDDOCUMENT();