## PREP 2015 Question Authoring - Archived

### Avoiding zero label on the axes/Pop ups

by Regina Souza -
Number of replies: 7
Question 1: Is there an intelligent solution to avoid the label zero on the axes when creating a graph (other than interrupting the counter)?

Question 2: What is wrong with my popups? Code follows:

#---------------------------------------------------------------------------------------------------------------------
# tagging and description section
#---------------------------------------------------------------------------------------------------------------------

# DESCRIPTION
# Recognizing properties of the parameters k and p from the graph of y=kx^p
# ENDDESCRIPTION
# Homework/Workshop3/Souza/problem3.pg

#---------------------------------------------------------------------------------------------------------------------
# initialization section
#---------------------------------------------------------------------------------------------------------------------

DOCUMENT();

"MathObjects.pl",
"PGgraphmacros.pl",
"parserPopUp.pl",
"PGML.pl",
"PGcourse.pl");

Context("Numeric");

#---------------------------------------------------------------------------------------------------------------------
# problem set-up section
#---------------------------------------------------------------------------------------------------------------------

#---------------------------------------------------------------------------------------------------------------------
# text section
#---------------------------------------------------------------------------------------------------------------------

TEXT(beginproblem());

$showPartialCorrectAnswers = 1;$refreshCachedImages = 1;

Context("Numeric");

$pixels = 200; # Create the canvas$gr = init_graph(-3,-3,3,6, # xmin, ymin, xmax, ymax
axes=>[0,0], grid=>[6,9], size=>[$pixels,$pixels]);
$gr -> lb('reset'); # remove default labels # axes labels$gr->lb( new Label(2.5,0,'x', 'black', 'center', 'bottom'));
$gr->lb( new Label(0.1,5.5,'y', 'black', 'left', 'middle')); # axes labels foreach my$i (-2..2) {
$gr->lb( new Label($i,0, $i, 'black', 'center', 'top')); } foreach my$i (-2..5) {
$gr->lb( new Label(-0.1,$i, $i, 'black', 'right', 'middle')); } ###### ###### Maybe randomize the graph? ###### # plot a function$f = Formula("2*sqrt(x)");
add_functions($gr, "$f for x in <-1,4> using color:blue and weight:2");

#########
### Problem worked up to here
#########

$showPartialCorrectAnswers = 0;$popup1 = PopUp(
"power function",
);

$popup2 = PopUp( ["choose","d less than 0","d greater than 1"], "d between 0 and 1", ); BEGIN_PGML >> [@ image(insertGraph($gr), width=>$pixels, height=>$pixels, tex_size=>900) @]*
[ f(x)=c\cdot x^d ] <<

a. Which type of function is this? [_________]{$popup1} b. What is the value of [ c ] ? [ c = ] [____] {2} c. Choose the best option for [ d ]: [@$popup2->menu() @]*

END_PGML

ANS( $popup2->cmp() ); #--------------------------------------------------------------------------------------------------------------------- # (answer and) solution section #--------------------------------------------------------------------------------------------------------------------- BEGIN_PGML_SOLUTION *SOLUTION* The correct answers are [@$popup1->correct_ans() @]* , 2 (the value of the function at 1) and
[@ $popup2->correct_ans() @]* (since the power function is increasing and concave down). END_PGML_SOLUTION ENDDOCUMENT(); In reply to Regina Souza ### Re: Avoiding zero label on the axes/Pop ups by Paul Pearson - Hi, When I ran your code, I received the error message:  Problem1 ERROR caught by Translator while processing problem file:tmpEdit/Experimental/Popup_debug.pg.pearson.tmp **************** ERRORS from evaluating PG file: The correct choice must be one of the PopUp menu items at line 2 of (eval 4648) Died within Value::Error called at line 100 of [PG]/macros/parserPopUp.pl from within parser::PopUp::new called at line 2 of (eval 4648) from within main::PopUp called at line 63 of (eval 4423)  which tells me that the correct answer is not among the choices listed in the PopUp. In particular, in the first popup you need "power function" to appear twice (once in the list of choices and once as the correct answer). ###### begin pg code ###########$popup1 = PopUp(
"power function",
);

###### end pg code ############

Similar remarks apply to the second popup.  Also, there should be no space between the answer blank and the answer: it should be [____]{"2"} and not [____] {"2"}.

Best regards,

Paul Pearson

########### begin pg file ###############

DOCUMENT();

"MathObjects.pl",
"PGgraphmacros.pl",
"parserPopUp.pl",
"PGML.pl",
"PGcourse.pl");

Context("Numeric");

#---------------------------------------------------------------------------------------------------------------------
# problem set-up section
#---------------------------------------------------------------------------------------------------------------------

#---------------------------------------------------------------------------------------------------------------------
# text section
#---------------------------------------------------------------------------------------------------------------------

TEXT(beginproblem());

$showPartialCorrectAnswers = 1;$refreshCachedImages = 1;

Context("Numeric");

$pixels = 200; # Create the canvas$gr = init_graph(-3,-3,3,6, # xmin, ymin, xmax, ymax
axes=>[0,0], grid=>[6,9], size=>[$pixels,$pixels]);
$gr -> lb('reset'); # remove default labels # axes labels$gr->lb( new Label(2.5,0,'x', 'black', 'center', 'bottom'));
$gr->lb( new Label(0.1,5.5,'y', 'black', 'left', 'middle')); # axes labels foreach my$i (-2..2) {
$gr->lb( new Label($i,0, $i, 'black', 'center', 'top')); } foreach my$i (-2..5) {
$gr->lb( new Label(-0.1,$i, $i, 'black', 'right', 'middle')); } ###### ###### Maybe randomize the graph? ###### # plot a function$f = Formula("2*sqrt(x)");
add_functions($gr, "$f for x in <-1,4> using color:blue and weight:2");

#########
### Problem worked up to here
#########

$showPartialCorrectAnswers = 0;$popup1 = PopUp(
"power function",
);

$popup2 = PopUp( ["choose","less than 0","between 0 and 1","greater than 1",], "between 0 and 1", ); BEGIN_PGML >> [@ image(insertGraph($gr), width=>$pixels, height=>$pixels, tex_size=>900) @]*
[ f(x)=c\cdot x^d ] <<

a. Which type of function is this? [_________]{$popup1} b. What is the value of [ c ] ? [ c = ] [____]{"2"} c. Choose the best option for [ d ]: [__]{$popup2}

END_PGML

#---------------------------------------------------------------------------------------------------------------------
#---------------------------------------------------------------------------------------------------------------------

BEGIN_PGML_SOLUTION

*SOLUTION*

The correct answers are [@ $popup1->correct_ans() @]* , 2 (the value of the function at 1) and [@$popup2->correct_ans() @]* (since the power function is increasing and concave down).

END_PGML_SOLUTION

ENDDOCUMENT();

### Re: Avoiding zero label on the axes/Pop ups

by Regina Souza -
What the rookie eyes don't see! Thanks a lot!

Further questions: In the third colum "correct answer" the solutions are listed as 1 word "powerfunction" and "dbetween0and1". Any fix for that? (In the solutions field they are displayed correctly.) Did I understand correctly that one cannot display math in the pop ups? Can I at least force "d" to be in italics?

### Re: Avoiding zero label on the axes/Pop ups

by Gavin LaRose -
Hi Regina,

I didn't see an answer to this in the preceding, so I'll first take a stab at it:
Question 1: Is there an intelligent solution to avoid the label zero on the axes when creating a graph (other than interrupting the counter)?

My answer: no, not really. I'd just rewrite your label command as
foreach my $i (-2, -1, 1, 2) {$gr->lb( new Label($i,0,$i, 'black', 'center', 'top')); }

As for formatting in PopUps, I don't think they support non-plain text display. The old PG checkbox macros do, however.

Cheers,
Gavin

### Re: Avoiding zero label on the axes/Pop ups

by Jan Hlavacek -
Avoiding 0 (or any other values):

The suggested solution is good is the list od labels is not too long. If your labels go say from -20 to 20, it is easier to filter them with grep:
 foreach my $i (grep {$_ != 0 } -20..20) { ... 
You can also construct the labels first, and then use them:
 @ylabs = -20..-1; push @ylabs, 1..20; foreach my $i (@ylabs) { ...  In reply to Jan Hlavacek ### Re: Avoiding zero label on the axes/Pop ups by Davide Cervone - Easier just to use  foreach my$i (-20..-1,1..20) { ... }

than to use grep or make a separate array variable.

### Re: Avoiding zero label on the axes/Pop ups

by Jan Hlavacek -
Or that. :)

I would say that that is a pretty intelligent solution.
I did not know you can do that in Perl.