Forums

Search results: 169

WeBWorK Problems -> Spontaneous answer reduction

by Olivia Henders -
What determines whether or not an answer gets reduced when it's displayed? In one problem (shown below), the answer displays as a "full" equation (no simplification), where in others, the answer gets simplified down to a single number. I know that using the reduce function can at least play a part in this, but I'm not using it anywhere. In fact, using it on the answer in the below example doesn't even change the answer, despite there being a coefficient of 1 in one place.


## DESCRIPTION
##
## ENDDESCRIPTION
## DBsubject()
## DBchapter()
## DBsection()

#############################################
# Initialization
DOCUMENT();
loadMacros(
 "PGstandard.pl",
 "MathObjects.pl",
 # Needed to support graph generation.
 "PGgraphmacros.pl",
 "unionTables.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());
# Refreshes the graph image every time the page is loaded, as opposed to
# retrieving a cached version.
$refreshCachedImages = 1;
#############################
# Setup
Context("Numeric");
# Value initialization.
$a = random(0,3,1);
$f = Compute("sqrt(x)+$a");
# Graph values
$minX = -5;
$minY = -5;
$maxX = 5;
$maxY = 5;
$originX = 0;
$originY = 0;
$gridHoriz = $maxX-$minX;
$gridVert = $maxY-$minY;
$shadedMinX = 1;
$shadedMinY = 0;
$shadedMaxX = 4;
$shadedMaxY = $f->eval(x=>$shadedMaxX);
# Converts $f to LaTeX for display later.
$ftex = $f->TeX;
# Calculates the value for the answer.
$answer = Compute("(2/3) * (4^(3/2) - 1) + 3*$a");
# Initialize graph at the required size.
$gr = init_graph($minX,$minY,$maxX,$maxY,grid=>[$gridHoriz,$gridVert],axes=>[$originX,$originY],size=>[300,300]);
$gr->lb('reset');
# Initializes the x-axis positive and negative number labels.
foreach my $i (1..$maxX-1) {
 $gr -> lb(new Label ( $i,-0.25, $i,'black','center','middle'));
}
foreach my $i (1..-$minX-1) {
 $gr -> lb(new Label (-$i,-0.25,-$i,'black','center','middle'));
}
# Initializes the y-axis positive and negative number labels.
foreach my $i (1..$maxY-1) {
 $gr -> lb(new Label (-0.25,$i,$i,'black','center','middle'));
}
foreach my $i (1..-$minY-1) {
 $gr -> lb(new Label (-0.25,-$i,-$i,'black','center','middle'));
}
# Define new graph colors
# Not all of these are used, but they are defined for easier use later.
$gr->new_color("skyblue", 86,180,233); # RGB
$gr->new_color("darkskyblue", 38,79,233);
$gr->new_color("orange", 230,159,0);
$gr->new_color("darkorange", 182, 58, 0);
#
# Choose colors
#
$light = "skyblue";
$dark = "darkskyblue";
# Graph the function and the filled region
add_functions($gr, "$f for x in <0,5> using color:$dark and weight:4");
$gr->moveTo(1,$a+1);

# Draws lines below function line to form boundary of shaded area.
$gr->lineTo($shadedMinX,$shadedMinY,$dark,4);
$gr->lineTo($shadedMaxX,$shadedMinY,$dark,4);
$gr->lineTo($shadedMaxX,$shadedMaxY,$dark,4);
# Fills in area that needs to be shaded.
$gr->fillRegion([$shadedMinX + 0.1, $shadedMinY + 0.1,$light]
);
#############################
# Main Text
# Defines the problem text.
# Places the following information in column1 (the leftmost) of the layout table.
$column1 = PGML::Format(<<END_PGML);
Use the graph to find the area of the shaded
region under [``f(x) = $ftex``].
Area = [______________][@ AnswerFormatHelp("numbers") @]*
END_PGML
# Places graph image in right-hand column.
$column2 = image( insertGraph($gr),height=>300,width=>300,tex_size=>800 ).
$BR.$BCENTER.
$BR.
"Graph of \( y = f(x) \)".
$ECENTER;
TEXT(ColumnTable($column1, $column2, indent => 0, separation => 30, valign => "TOP"));
#############################
# Answer Evaluation

# Setting this to 1 means that students will receive feedback on whether their
# answers are correct.
$showPartialCorrectAnswers = 1;
ANS($answer->cmp());
#############################
# Solution
BEGIN_PGML_SOLUTION
Solution explanation goes here.
END_PGML_SOLUTION
COMMENT('Uses PGML. Looks like pi.');
ENDDOCUMENT();

WeBWorK Problems -> arrays in PGML

by Valerio De Angelis -
In the following problem, I want to display four pictures in tabular form, so I tried to use (in PGML) [: Array( [$f0]*, [$f1]* ; [$f2]* , [$f3]* ) :]
but it did not work. I do not get an error message, but instead of a picture I get the code that defines it. So I just wrote

A [$f0]* [: quad quad :] B [$f1]*

C [$f2]* [: quad quad :] D [$f3]*

and this does the job well for the purpose of this problem, but I wonder how one could use Array in this situation.

A (maybe related?) problem I had in writing this problem was that in PGML, I could not display the images as [$fig[0]] [$fig[1]] [$fig[2]] [$fig[3]]
but had to instead define and use [$f0] [$f1] [$f2] [$f2]. I am guessing that it has something to do with how PGML interprets the square brackets.

Thanks for any information.




DOCUMENT();

loadMacros(
"PGstandard.pl",
"MathObjects.pl",
"parserPopUp.pl",
"PGML.pl",
"PGcourse.pl"
);
 
TEXT(beginproblem());

$refreshCachedImages=1;
 
$fig[0]=image("H1_1_1.png"); #the png files contain pictures of graphs
$fig[1]=image("H1_1_2.png");
$fig[2]=image("H1_1_3.png");
$fig[3]=image("H1_1_4.png");

$k = random(0,3,1); # $k, $a1,$a2,$a3 are a cyclic permutation of 0,1,2,3
$a1=($k+1)%4;
$a2=($k+2)%4;
$a3=($k+3)%4;


$f0=$fig[$k];
$f1=$fig[$a1];
$f2=$fig[$a2];
$f3=$fig[$a3];

$e=(1-$k)%4; # this selects fig[1] as the correct answer


@letter = ("A", "B", "C", "D");

$popup = PopUp(["?","A","B","C","D"], $letter[$e]);


BEGIN_PGML
Which picture A-D does *not* describe a function?
[$popup->menu() ]*

A [$f0]* [: quad quad :] B [$f1]*

C [$f2]* [: quad quad :] D [$f3]*

END_PGML


install_problem_grader(~~&std_problem_grader);
$showPartialCorrectAnswers = 0;

ANS( $popup->cmp() );

BEGIN_SOLUTION
$letter[$e] does not describe a function, because we can draw a vertical line that
intersects the graph twice.
END_SOLUTION



ENDDOCUMENT();

WeBWorK Problems -> Issues with re-randomization

by Eric Stroyan -
I am having an issue with problems re-randomizing on each access or reload of the browser page. This was not an issue in the past, having used these same problems from about 2005 to around 2011.
Basically, the problem accesses a macro to give students information about a particular element (atomic number, symbol, etc). They are then to answer some simple information about the element. What is happening now is that if a student answers incorrectly they get a new element and not the one thsy answered. If they simply refresh the page without any answer entry, they also get a new element.
Previously the student's numbers would persist as they do in most problems. I am wondering if the issue is with list_random or something else. Using ww and pg 2.12 on ubuntu 16.04.
Any help would be appreciated.

Here is the code I am referencing:
DOCUMENT(); # This should be the first executable line in the problem.
loadMacros(
"PG.pl",
"PGbasicmacros.pl",
"PGchoicemacros.pl",
"PGanswermacros.pl",
"PGauxiliaryFunctions.pl",
"isotopes.pl"
);
TEXT(&beginproblem);
$showPartialCorrectAnswers = 1;

@atomic_numbers = keys %isotopes;

$Z = list_random(@atomic_numbers);


$name = $isotopes{$Z}{name};
$symbol = $isotopes{$Z}{symbol};

for $who ( @{ $isotopes{$Z}{atomic_mass} } ) {
@atomic_mass = $who->{at_mass};
}

$A = list_random(@atomic_mass);

BEGIN_TEXT
How many protons are in a neutral atom of $name?
$BR

Number of protons = \{ans_rule(15)\} $BR

END_TEXT

$protons = $Z;

&ANS(num_cmp($protons,reltol=>1,format=>'%0.4g') );
ENDDOCUMENT();

The macro file has the basic structure:
%isotopes=( 1=>{name=>Hydrogen, symbol=>H, atomic_mass=> [{at_mass=>1}, {at_mass=>2}, ],}, 2=>{name=>Helium, symbol=>He, atomic_mass=> [{at_mass=>4}, {at_mass=>3}, ],}, 3=>{name=>Lithium, symbol=>Li, atomic_mass=> [{at_mass=>6}, {at_mass=>7}, ],}, 5=>{name=>Boron, symbol=>B, atomic_mass=> [{at_mass=>11}, {at_mass=>10}, ],},

WeBWorK Problems -> Issues creating Homework sets

by John Nicoletti -
Hello,

We have been using WebWork (v 2.8) at our campus for about two years now. Things have been going smoothly since the installation. Just recently, we migrated to use HTTPS/SSL. I am not sure if this is causing the issue, but that has been the only main change as of recent.

I do not work directly with WebWork, but rather am in IT and have set it up for our math department. One of the professors stopped down to show me an issue today.

He created a course 'Test'. Inside that course, he attempts to add home work sets. He goes to the library browser, picks a target set then chooses a subject. Normally, once the subject is picked, it refreshes with chapters he can choose on the next drop down. This is no longer happening. Nothing will auto-update. Instead, he has to go to 'Advanced Search' and hit 'Update Menus' every time he changes a drop down.

The other issue he is having is once he finally gets to problems he wants to add, if he clicks 'Add,' he doesn't get the normal confirmation which would typically appear in the white space across form the add button. Instead, all the way at the top of the page, it will say 'Added one problem to set xxxxx' with a green background. However, when you go look at the homework set, there are 0 problems added. 

So not only are the drop down menu's not auto-refreshing, but we also cannot add problems to homework sets.

Any help is appreciated!

Thank you, 
John
Hi Joel,

The image has a caching problem.  First the server is caching the image
so that the image is created only once.  This is usually what you want.
It can be turned off by: 
$refreshCachedImages =1;

But that is not enough because the browser is also caching the image. And I'm not sure how to turn that off easily.  You can see the true image using shift-reload which makes the browser request the image again instead of using the cache -- but that is annoying and hard to explain to students.

The best solution seems to be to add a time stamp to the image name -- so that every image is different.  I checked StackOverflow and this is at least one answer.  The downside is that stale images will pile up on your server so you might want to delete them from the tmp directory on a regular basis. 

Others may have cleverer ways to fool the browser into refreshing the image.

Anyway here is some code which works for me:

DOCUMENT();

loadMacros(
"PGstandard.pl",
"MathObjects.pl",
"PGML.pl",
"scaffold.pl",
"PGcourse.pl",
"PGgraphmacros.pl",
"PGinfo.pl",
);
#$refreshCachedImages=1;
# the above line is not needed if we are adding random numbers to the image name

TEXT(beginproblem());

Context("Numeric");
Context()->variables->are(t=>'Real');
$answer1 = Compute("sin(t)");

Scaffold::Begin(
  can_open => "when_previous_correct",
  is_open  => "first_incorrect"
);

Section::Begin("Part 1: The first part");
BEGIN_PGML
Enter [` \sin(t) `] [________]{$answer1}
END_PGML
Section::End();

$answer1_student = $inputs_ref->{ANS_NUM_TO_NAME(1)}; # alternate, perhaps more direct method

$gr = init_graph(-4,-1,4,1,
axes=>[0,0],
grid=>[8,2],
size=>[400,400]
);
$gr->imageName($gr->imageName."-".time);
#TEXT( "graph name ", $gr->imageName);
#$V_out = Formula("cos(t )");
#$G0 = FEQ(qq! $V_out for t in <-4,4> using color:blue and weight:2!);
#($f1n) = plot_functions( $gr, $G0 );
add_functions($gr, "$answer1_student for t in <-4,4> using color:blue and weight:2");

Section::Begin("Part 2: The second part");
BEGIN_PGML
The student's first answer was [$answer1_student].  
Here's a graph of the student's answer:

[@ image( insertGraph($gr), width=>200,height=>200,tex_size=>800 ) @]*
END_PGML

Section::End();

Scaffold::End();

ENDDOCUMENT();

WeBWorK Problems -> Accepting all varialbes

by Carl Yao -
Hello:

Is there a way to let WeBWorK accept any variable? For example, if the correct solution is {x|x>1}, and if a student typed in {Z|Z>1}, it would be considered correct?

Thank you!

Carl Yao
Math Instructor
Portland Community College

Sample code is here:

# WeBWorK problem written by Carl Yao
# Portland Community College
#
# Give a graph of an inequality, write the set notation and interval notation.
# Answer is like (3, inf).
#
# Last edited by Jordan 8/28/13; Carl Yao on 7/21/13
#
# ENDDESCRIPTION

## DBsubject('Algebra')
## DBchapter('Basic Algebra')
## DBsection('Inequalities')
## KEYWORDS('linear','inequality', 'number line','set notation','interval notation')
## DBCCSS('7.EE.4')
## TitleText1('')
## EditionText1('')
## AuthorText1('')
## Section1('')
## Problem1('')
## Author('Alex Jordan, Carl Yao, Chris Hughes')
## Institution('PCC')

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

DOCUMENT();

loadMacros(
"PGgraphmacros.pl",
"PGstandard.pl",
"MathObjects.pl",
"PGML.pl",
"parserPopUp.pl",
"contextInequalitySetBuilder.pl",
"PGcourse.pl",
);

##############################################
TEXT(beginproblem());
Context("Numeric");

$a = random(-4,4,0.5);

$symbol = '>';

InequalitySetBuilder::UseVerticalSuchThat();
Context("InequalitySetBuilder-Only");
$setans = Compute("{ x | x $symbol $a}");

Context("Interval");
Context()->flags->set("formatStudentAnswer"=>'parsed');
$intans = Compute("($a,inf)");
Context("Numeric");

%answer = (leftType => 'open',
rightType => 'inf', #use 'inf' regardles of +/- inf
);


$aspectRatio = 1/8;
$horPixel = 400;
$verPixel = $horPixel*$aspectRatio;
$screenXSize = $horPixel;
$screenYSize = $screenXSize*$aspectRatio;
$reach = 5;
$verticalSpace = $reach*$aspectRatio;
$hardCopyPercent = 1000; #meaning 100%


#initializing...
@gr=();

#indices will be 0..$#gr in some order, with the index of the correct graph in the 0th position.
@indices=();


#make the graphs
for $leftType ('open','closed', 'inf')
{
for $rightType ('open','closed', 'inf')
{
my $tempgr = init_graph(-$reach,-$verticalSpace,$reach,$verticalSpace,
axes=>[$reach+1,0],
size=>[$horPixel,$verPixel]
);
@ticks = ();
for my $j ((-$reach)..($reach)) {push(@ticks,$j);};

$tempgr->h_ticks(0,"black",@ticks);
$tempgr->lb( new Label(0,-$verticalSpace/5,0,'black','center','top'));

if (($leftType eq 'inf' or $rightType eq 'inf') and !(($leftType eq 'inf' and $rightType eq 'inf')))
{
$tempgr->lb( new Label($a,-$verticalSpace/5,$a,'blue','center','top'));
if ($leftType eq 'open' or $rightType eq 'open')
{
$tempgr->stamps( open_circle($a,0,'blue') )
}
else
{
$tempgr->stamps( closed_circle($a,0,'blue') )
};
$tempgr->moveTo($a,0);
if ($leftType eq 'inf') {$tempgr->arrowTo(-0.99*$reach,0,'blue',3)}
else {$tempgr->arrowTo(0.99*$reach,0,'blue',3)};
push(@gr,$tempgr);
if ($answer{leftType} ne $leftType or $answer{rightType} ne $rightType)
{push(@indices, $#gr);}
else {unshift(@indices, $#gr);}
}

}};

$alt = "Graph of an interval on a number line. There is a hollow circle at $a and everything right of that is shaded.";

##############################################
$refreshCachedImages = 1;

Context()->texStrings;
BEGIN_TEXT
Here is a graph of an interval.$PAR

$BCENTER
\{ image( insertGraph($gr[ $indices[0] ]), width=>$screenXSize, height=>$screenYSize, tex_size=>$hardCopyPercent,
extra_html_tags=>'title="$alt" alt= "$alt" align="top"' ) \}
$ECENTER
$PAR
END_TEXT
Context()->normalStrings;

BEGIN_PGML
Please type:

* *inf* for [`\infty`],
* *[$GTS]=* for [`\geq`],
* and *[$LTS]=* for [`\leq`]

Write this inequality in set-builder notation: [_____________________]


Write this inequality in interval notation: [_____________________]



END_PGML



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

ANS( $setans->cmp() );

ANS( $intans->cmp() );

BEGIN_PGML_SOLUTION

Since the given graph shades all the values greater than [`[$a]`] (but not equal to [`[$a]`]) the graph represents the inequality [`x [$symbol] [$a]`].

The corresponding set notation is [`[$setans]`].

The corresponding interval notation is [`[$intans]`].

END_PGML_SOLUTION

ENDDOCUMENT();


I would like the students to be able to always use the same notation for infinity in their answers, that is, I=infinity, -I=-Infinity. I know how to do this when the answer is just I or -I, but I am not able to get the answer evaluator to accept 
an interval in the form (-I,4] for example. In the problem below, the answer has to be entered as (-Infinity,2) or (-inf,2), but I would like the students to be able to enter (-I,2). Is this possible?
Thanks in advance.



DOCUMENT();       

loadMacros("PGstandard.pl",
"MathObjects.pl",
"PGgraphmacros.pl",
"PGML.pl",
"AnswerFormatHelp.pl",
"PGcourse.pl"
);




TEXT(beginproblem());


$showPartialCorrectAnswers = 1;
$refreshCachedImages=1;

Context("Point");

$pixels=400;

#create the canvas
$gr=init_graph(-10,-10,10,10,# xmin,ymin, xmax, ymax
axes=>[0,0],grid=>[20,20],size=>[$pixels,$pixels]);
$gr->lb('reset'); #remove default labels

# axes labels
$gr->lb(new Label(9.5,0,'x','black','center','bottom'));
$gr->lb(new Label(0.1,9.5,'y','black','left','middle'));

foreach my $i (-10..10){
$gr->lb( new Label($i,0,$i,'black','center','top'));
$gr->lb( new Label(-0.1,$i,$i,'black','right','middle'));
}
#plot a function
$e=0.1;
$t1=random(2,2,1);
$t11=$t1-$e;
$t12=$t1+$e;
$t2=$t1+2;
$t20=$t2-$e;
$t21=$t2+2*$e;
$t3=$t2+4;
$t30=$t3-$e;
$t31=$t3+$e/4;
$t22=$t2+2;


$L1=Formula("-1/(x-$t1)+2");
$L2=Formula("7/2");
$L3=Formula("3*sin(3*(x-$t3))+7/2");
$a=3*sin(3*(9-$t3))+7/2;

add_functions($gr, "$L1 for x in <-10,$t11> using color:blue and weight:2",
"$L1 for x in <$t12,$t20> using color:blue and weight:2",
"$L2 for x in <$t21,$t30> using color:blue and weight:2",
"$L3 for x in <$t31,9> using color:blue and weight:2");

$gr->stamps(
      new Circle($t2,2.5,4,'blue','blue'));
$gr->stamps(
      new Circle($t2,1.5,4,'blue',''));
$gr->stamps(
      new Circle($t2,3.5,4,'blue',''));
$gr->stamps(
      new Circle($t3,1,4,'blue','blue'));

$gr->stamps(
      new Circle($t3,3.5,4,'blue',''));

$gr->stamps(
      new Circle(9,$a,4,'blue','blue'));


$ans=Interval("(-inf,$t1)");


BEGIN_PGML
The graph of [` f(x)`] is shown in the picture. 

>>[@image(insertGraph($gr),width=>$pixels, height=>$pixels, tex_size=>900) @]*<<
The function is continuous on [_____]{$ans}
END_PGML

BEGIN_PGML_SOLUTION
*SOLUTION*
END_PGML_SOLUTION

ENDDOCUMENT();