WeBWorK Problems

Drawing number lines in problems?

by Paul Seeburger -
Number of replies: 2

Is it possible to draw a number line of algorithmically determined length in a problem?  Perhaps to generate a multiple choice question to go along with an absolute value inequality question?  (This is what I would like to do with it.)

This is something I can do in a MyMathLab problem, but have not yet figured out how to do in WebWork.

Thanks!

Paul

Re: Drawing number lines in problems?

by Paul Pearson -
Hi Paul,

Below is some code for drawing number lines that you may be able to modify to meet your needs (I omitted the problem text and only inserted one of the three graphs).

Best regards,

Paul Pearson

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

DOCUMENT();
"PGstandard.pl",
"MathObjects.pl",
"PGgraphmacros.pl",
);

TEXT(beginproblem());
$refreshCachedImages = 1; #################################### # Setup Context("Numeric")->variables->are(x=>"Real"); foreach my$i (0..2) {
$gr[$i] = init_graph(-6,-1,6,1, size=>[408,68]);
# x-axis
$gr[$i] -> moveTo(-6,0);
$gr[$i] -> lineTo(6,0,'black','1');
# x-axis ticks entered as y-value, color, list of x-values
$gr[$i] -> h_ticks(0,"black",-5,-4,-3,-2,-1,0,1,2,3,4,5);
# labels for tickmarks
foreach my $j (0..5) {$gr[$i]->lb( new Label($j,-0.5,$j, 'black','center','middle'));$gr[$i]->lb( new Label(-$j,-0.5,-$j, 'black','center','middle')); } }$gr[0] -> stamps( closed_circle(-4,0,'blue') );
$gr[0] -> stamps( closed_circle(4,0,'blue') );$gr[1] -> moveTo(-4,0);
$gr[1] -> lineTo(4,0,'blue',3);$gr[1] -> stamps( open_circle(-4,0,'blue') );
$gr[1] -> stamps( open_circle(4,0,'blue') );$gr[2] -> moveTo(-4,0);
$gr[2] -> arrowTo(-6,0,'blue',3);$gr[2] -> moveTo(4,0);
$gr[2] -> arrowTo(6,0,'blue',3);$gr[2] -> stamps( open_circle(-4,0,'blue') );
$gr[2] -> stamps( open_circle(4,0,'blue') ); BEGIN_TEXT \{ image(insertGraph($gr[0]), width=>408, height=>68, tex_size=>700); \}

END_TEXT

ENDDOCUMENT();