Forums

Search results: 169

WeBWorK Problems -> Custom Error Messages Issue

by Brittni Lorton -
I am attempting to add a custom error message to a specific problem and I seem to be running into an issue. The answer to this is the string "None" but I want to allow students to be able to enter points without a strange error message throwing them off. Ideally what I want is:

  • If student enters a number -> an error message saying "Your answer is not a point"
  • If a student enters a point -> no extra error message, just "Incorrect"
Below is what I have so far. When I type a number in I get the desired message of "Your answer isn't a point", but the problem is that when I enter a point, the error message that still pops up is "Your answer isn't a number (it looks like a point)".
Any help would be greatly appreciated.

Thanks,
*Brittni


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

DOCUMENT();

loadMacros(
"PGstandard.pl",
"MathObjects.pl",
"PGchoicemacros.pl",,
"parserAssignment.pl",
"AnswerFormatHelp.pl",
"PGML.pl",
"PGcourse.pl",
"contextLimitedPoint.pl",
);

TEXT(beginproblem());

$showPartialCorrectAnswers = 1;

$refreshCaschedImages = 1;

##########################
# Setup
Context("Numeric");
Context()->variables->add(t => 'Real');

##Random variables for slope ##
$a=list_random(0,1);

##formulas for x(t) and y(t)##
Context()->noreduce('(-x)-y','(-x)+y');
$x_t=Formula("t+(1/t)")->reduce;
$y_t=Formula("t-(1/t)")->reduce;

Context("LimitedPoint"); ## Maybe this is needed to allow students to enter a point without an error message, even though the answer is "none" here.
$blank = Point("(1,2)");

$pointChecker = sub {
my ($correct,$student,$ansHash) = @_;
Value->Error("Your answer isn't a point.") unless $student->class eq "Point";
return 1;
};


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

BEGIN_PGML
Given the parametric curve

[` \displaystyle x(t)=[$x_t], \hspace{.25cm} y(t)=[$y_t] `].

Find all the points on the curve at which the slope of the tangent line is [`m=[$a] `].

Enter your solution as a comma separated list of ordered pairs [`(x,y)`] or if there are no points on the curve at which the slope of the tangent line is the given slope enter NONE.

[_______________________________] [@ AnswerFormatHelp("points") @]*


END_PGML

ANS(String("NONE")->cmp(checker=>$pointChecker)->withPostFilter(sub {
my $ans = shift;
$ans->{ans_message} = "Incorrect"
if $ans->{ans_message} eq "Your answer isn't a number (it looks like a point)";
return $ans;
}));


#################################
# Solution

#BEGIN_PGML_SOLUTION
#Solution explanation goes here.
#END_PGML_SOLUTION

COMMENT('Uses PGML.');

ENDDOCUMENT();
I'm trying to use Geogebra in a WeBWorK problem, but the applet seems to have trouble with 3D commands.

I've written an optimization problem involving a cone, and I wanted to embed an interactive Geogebra graph so that the student can see the relationship between the independent variable and the volume of the cone. I have attached a screenshot of the error message that Geogebra produces within the WeBWorK problem. In the screenshot, you can see the expression (0,0,R/(2pi)*sqrt(4pi*t-t**2)), this is the vertex of the cone, and R-R*t*(2pi)^-1 is the radius of the cone. These are the only objects that were created in the 3D window.

It seems like 3D commands cause problems as I've never encountered this issue with 2D commands. I probably need to test a few other 3D commands to see if they work.

Has anyone encountered this problem?

(Edit: I'm not sure why my text isn't wrapping. Sorry about that.)

############## PG code below ############

# written by zach sharon 4/5/19
# based on Paul Pearson's problem at https://github.com/openwebwork/webwork-open-problem-library/blob/master/OpenProblemLibrary/FortLewis/Calc1/06-01-Antiderivatives-graphically/AF1/AF1.pghttps://github.com/openwebwork/webwork-open-problem-library/blob/master/OpenProblemLibrary/FortLewis/Calc1/06-01-Antiderivatives-graphically/AF1/AF1.pg

######### other resources used to make this problem
# http://webwork.maa.org/moodle/mod/forum/discuss.php?d=4041
# https://wiki.geogebra.org/en/Reference:GeoGebra_Apps_API
# http://dev.geogebra.org/examples/html/example-api-listeners.html
# http://webwork.maa.org/pod/pg_TRUNK/lib/Applet.html#methods_defined_for_the_javascript_applet_ww_applet_list_appletname_
#

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

DOCUMENT();

loadMacros(
"PGstandard.pl",
"MathObjects.pl",
"unionTables.pl",
"niceTables.pl",
"AppletObjects.pl",
"PGchoicemacros.pl",
"PGcourse.pl",
"parserImplicitPlane.pl",
"PGML.pl",
"PGbasicmacros.pl"
);
$showPartialCorrectAnswers = 1;

TEXT(beginproblem());


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

$r = random(3,8,1);
$ans = Compute("2*pi-sqrt(8/3)*pi");

######################################
# Create link to applet:
###################################

$appletName = "applet1";

$applet = GeogebraWebApplet(
code => "geogebra.GeoGebraApplet",
archive => "geogebra.jar",
codebase => findAppletCodebase("geogebra.jar"),
appletName => $appletName,
appletId => $appletName,
submitActionAlias => 'getAppletValues', # default actionAlias
initializeActionAlias => 'configure', # default actionAlias
setStateAlias => 'setXML',
getStateAlias => 'getXML',
setConfigAlias => '',
getConfigAlias => '',
returnFieldName => '',
width => 720, # may want to modify width, originally 640
height => 540, # may want to modify height, originally 480
# mayscript => "true",
debugMode => 0, # set debugMode to 0 for no debug
# to 1 to make xml representation visible
# to 2 to add alerts detailing progression
# through the applet
XonInit=> 'ggbOnInit',
type => 'geogebraweb',
#submitActionScript => qq{ getQE('answerBox').value = getAppletValues() },
submitActionScript => '',
selfLoading => 1,
params => GEOGEBRA_PARAMS(),# paste parameters in

);

##################################
# Setup GeogebraWebApplet --
###################################

###############################################
#
# For persistence of GeoGebra applet state
# when answers are submitted or page is refreshed.
# Uses JavaScript interface to GeoGebra.

HEADER_TEXT(
qq!
<script Xlanguage="javascript">
function ggbOnInit(param) {
if (param == "$appletName") {
applet_loaded(param,1); // report that applet is ready.
ww_applet_list[param].safe_applet_initialize(2);
}
}

</script>
<noscript>For this question to work properly,
you must enable JavaScript, or use another browser
(or computer) on which JavaScript works.</noscript>
!);

####################
# PNG picture of GeoGebra applet for hardcopy

#$im = image( "AF1.png", width=>520, height=>520, tex_size=>900 );

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

BEGIN_PGML
A circle with radius [`[$r]`] has a sector with angle [`\theta`] cut out. The two cut edges of the larger piece are then joined to form the lateral surface of a cone. What angle [`\theta`] maximizes the volume of the cone?

[`\theta=`][______________________________]{$ans}
END_PGML

Context()->texStrings;
BEGIN_TEXT
\{

$BCENTER.
MODES(HTML=>$applet->insertAll(debug=>0, reinitialize_button=>1, includeAnswerBox=>0,), TeX=>$im).
$ECENTER

\}
END_TEXT
Context()->normalStrings;

#########################################
# The applet as a base64 string
#########################################

sub GEOGEBRA_PARAMS {
my $result = {
showResetIcon=>"false" ,
enableRightClick=>"false" ,
enableLabelDrags=>"false",
showMenuBar=>"false" ,
showToolBar=>"false",
showAlgebraInput=>"false",
useBrowserForJS=>"true",
ggbbase64=>"UEsDBBQACAgIAE9uiE4AAAAAAAAAAAAAAAAWAAAAZ2VvZ2VicmFfamF2YXNjcmlwdC5qc0srzUsuyczPU0hPT/LP88zLLNHQVKiu5QIAUEsHCEXM3l0aAAAAGAAAAFBLAwQUAAgICABPbohOAAAAAAAAAAAAAAAAFwAAAGdlb2dlYnJhX2RlZmF1bHRzMmQueG1s7VrfU9s4EH6+/hUaPd09kNhOnKQMoUM7c3PMUHpzMJ17VeyNo0ORfJYMDn99Zcm/QhIanFACLQ9Yq0gr6dtP69XKJx+yOUO3kEgq+Bi7HQcj4IEIKY/GOFXToxH+cPruJAIRwSQhaCqSOVFj7Octq35a6vg905vE8RgHjEhJA4xiRlTeZYxDjFAm6TEXl2QOMiYBXAUzmJMLERBltMyUio+73bu7u045XkckUTeKVCeTWoGeK5djXBSOtbqlTnc909xzHLf77+cLq/6IcqkIDwAjvY4QpiRlSuoiMJgDV0gtYhjjWLBFJDhGjEyAjfHfpVz0GOOhg0/f/XbCKIcrtWCA1IwGNxyknpGPCzWOLfxFwxByPDESeqVULXR5OMLdXIOciTskJv9BoLWqJIVqUCOYNvrnT4KJBCW6o9/DSFvD19omZgjC4hnRpY7r2D+3/95x3YHr2d6MLCBBt4TlrU0NSZUIjEJTOyVMQtlWD/1ZhGB/6RftOZ0bqyCpIDYLkTFAaErVUrV1F4Yolb6TbgHrWoBz7JYQthU1xO4LQewYgJ0VfJ3DxXOa8iBXePmVJNXqeMpYA8+Bj9ug4Tn9DXgM/cMHpFrcpzS5bbKr13ecVnjsyo5a636x2H2nPLZdKVeNvaol9Ps0AfijgajbDs/h0ACaPzSinu+/0I5z14MaCJGEEmVjfEkuMVoUz3v7NE0MOlf0vhjSb9Yac9Qz3wwxo7JG+MIINbK9NdDaOW7DVf1eeMDWI/flndmT+foErI/cFnwOIQaux1JLpHZbkX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P1W5OVcUD9wJdPDDyLpcmMqla7K5U7nFEMReOPF01+S9Ge6Izf0v0gIPsBi2IZs4hJGclbzviwL5buJX61fcW70yA3ouef1xq/FmS0g2wbMTfFu6muc8MHYN4XCIeqHw/f2No/I7b/0fXqv1BLBwi7diEyEwoAAJ0mAABQSwECFAAUAAgICABPbohORczeXRoAAAAYAAAAFgAAAAAAAAAAAAAAAAAAAAAAZ2VvZ2VicmFfamF2YXNjcmlwdC5qc1BLAQIUABQACAgIAE9uiE5UIeOr5AQAAFkmAAAXAAAAAAAAAAAAAAAAAF4AAABnZW9nZWJyYV9kZWZhdWx0czJkLnhtbFBLAQIUABQACAgIAE9uiE5JaPm6NgMAACMRAAAXAAAAAAAAAAAAAAAAAIcFAABnZW9nZWJyYV9kZWZhdWx0czNkLnhtbFBLAQIUABQACAgIAE9uiE67diEyEwoAAJ0mAAAMAAAAAAAAAAAAAAAAAAIJAABnZW9nZWJyYS54bWxQSwUGAAAAAAQABAAIAQAATxMAAAAA"
};

$result;
}


COMMENT('Uses GeoGebraWeb (JavaScript) so it should work on computers and tablets. Uses MO and is NOT randomized. Does not use a JS listener. Uses a blank geogebra applet just to show an interactive diagram.');

ENDDOCUMENT();

Attachment errorMessage.PNG
We are updating our WW very soon, so I can just wait until then to have the fix.

Now I am a bit curious about the problem level fix though (it certainly isn't a high priority though).

I did try including that snippet to inject the GeoGebra applet into the problem and it didn't seem to work. Below is the code with the change bold. Before the change, that bold snippet was:

TEXT($PAR, MODES(TeX=>$im,
HTML=>$applet->insertAll(
debug =>0,
reinitialize_button => 0,
includeAnswerBox=>1,
)));

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

DOCUMENT();

loadMacros(
"PGstandard.pl", # Standard macros for PG language
"MathObjects.pl",
"PGgraphmacros.pl",
"AppletObjects.pl",
"parserImplicitEquation.pl",
"source.pl",
);

# Print problem number and point value (weight) for the problem
TEXT(beginproblem());

# Show which answers are correct and which ones are incorrect
$showPartialCorrectAnswers = 1;

##############################################################
#
# Setup
#
#
Context("ImplicitEquation");
Context()->variables->are(x=>["Real", limits=>[-8,8]], y=>["Real", limits=>[-8,8]]);
Context()->noreduce('(-x)-y');

$a = non_zero_random(-3,7,1);
do{ $b = non_zero_random(-5,5,1); } until ( $a != 1 || $b != 1 );
$c = $a*$b;

$f = Formula("$b x+$a y")->reduce;

$answer = ImplicitEquation("$f = $c");

######################################
# Create link to applet:
###################################
# You can name your applet (anything reasonable :-) )
# Adjust the height and width as desired
# Paste the geogebra parameters in at the bottom of the page just above the
# command end command
# so that they don't get in the way
###################################


$appletName = "ggbfoo";

$applet = GeogebraWebApplet(
code => "geogebra.GeoGebraApplet",
archive => "geogebra.jar",
codebase => findAppletCodebase("geogebra.jar"),
appletName => $appletName,
appletId => $appletName,
submitActionAlias => 'getAppletValues', # default actionAlias
initializeActionAlias => 'configure', # default actionAlias
setStateAlias => 'setXML',
getStateAlias => 'getXML',
setConfigAlias => '',
getConfigAlias => '',
returnFieldName => '',
width => 400, # may want to modify width
height => 400, # may want to modify height
# mayscript => "true",
debugMode => 0, # set debugMode to 0 for no debug
# to 1 to make xml representation visible
# to 2 to add alerts detailing progression
# through the applet
onInit => 'ggbOnInit',
type => 'geogebraweb',
submitActionScript => qq{ getQE('answerBox').value = getAppletValues() },
#submitActionScript => '',
selfLoading => 1,
params => GEOGEBRA_PARAMS(),# paste parameters in

);



###############################################
#
# PNG picture of GeoGebra applet for hardcopy

$im = init_graph(-8,-8,8,8,
size=>[400,400],
grid=>[16,16],
axes=>[0,0]
);

##################################
# Setup GeogebraWebApplet --
###################################

###############################################
#
# For persistence of GeoGebra applet state
# when answers are submitted or page is refreshed.
# Uses JavaScript interface to GeoGebra.

HEADER_TEXT(
qq!
<script language="javascript">
function ggbOnInit(param) {
if (param == "$appletName") {
applet_loaded(param,1); // report that applet is ready.
ww_applet_list[param].safe_applet_initialize(2);
}
}
</script>
<noscript>For this question to work properly,
you must enable JavaScript, or use another browser
(or computer) on which JavaScript works.</noscript>
!);


#######################################################
#
# For setting initial values in GeoGebra from WeBWorK
# Uses JavaScript interface to GeoGebra.

TEXT( MODES(TeX=>'', HTML=><<END_SCRIPT ) );
<script language="javascript">
function setAppletCoefficients() {
var applet=getApplet("$appletName"); // alert("Updating coefficients");
if (typeof(applet)!="undefined") {
if (typeof(applet.setValue)!="undefined") {
 
////////////////////////////////////////////////////////////////
// List the values of the parameters to be set in the applet here
// Setup the grid, then establish values, points, then the line

applet.setPerspective("G");
applet.setPointCapture(1,2);
applet.setCoordSystem(-8,8,-8,8);
applet.setAxisSteps(1,1,1);
applet.setGridVisible('true');

applet.evalCommand("a = 1");
applet.evalCommand("b = 1");
applet.evalCommand("A = (a,0)");
applet.evalCommand("B = (0,b)");
applet.evalCommand("l = Line[A,B]");

//applet.setColor('A',228,27,23);
//applet.setColor('B',228,27,23);
//applet.setColor('l',228,27,23);


} else {
setTimeout("setAppletCoefficients()", 1000);
}
} else {
setTimeout("setAppletCoefficients()",1000);
}
}
ww_applet_list["$appletName"].setConfig = function() {setAppletCoefficients()};
</script>
END_SCRIPT

#######################################################
#
# For retrieving values from GeoGebra into WeBWorK
#

HEADER_TEXT( MODES(TeX=>'', HTML=><<END_SCRIPT ) );
<script language="javascript">
function getAppletValues() {
console.log("getAppletValues() entered");
// get a handle for the applet object
var applet = $appletName;
var l = applet.getLaTeXString("l");
return( l );
}
</script>
END_SCRIPT

##############################################################
#
# Text
#
#

Context()->texStrings;
BEGIN_TEXT

Graph the line, and submit your answer.
\[$f = $c\]


END_TEXT
Context()->normalStrings;

###################################
# insert applet into body -- this does not need to be changed
# except to adjust the insertion of the reinitialize_button or
# a hidden AnswerBox
###################################
TEXT($PAR, MODES(TeX=>'geogebraweb code',
HTML=>"<div class='enclose_ggb_obj'>".$applet->insertAll(
debug =>0,
reinitialize_button => 1,
includeAnswerBox=>1 )."</div>"
));


##############################################################
#
# Answers
#
#

NAMED_ANS( 'answerBox' => $answer->cmp() );

sub GEOGEBRA_PARAMS {
my $result = {
appName=>"classic", # instead of using ggbbase64
enableShiftDragZoom=>"false",
showResetIcon=>"false" ,
enableRightClick=>"false" ,
enableLabelDrags=>"false",
showMenuBar=>"false" ,
showToolBar=>"false",
showAlgebraInput=>"false",
useBrowserForJS=>"true",
#ggbbase64=>''
};

$result;
}



ENDDOCUMENT();

WeBWorK Main Forum -> geogebra javascript tutorial

by Joel Trussell -
I'm trying to modify the example in
I"ve copied that to my server. I can create scripts in my desktop Geogebra Classic 6 as in the tutorial
https://wiki.geogebra.org/en/Tutorial:Introduction_to_GeoGebraScript
I'd like to transfer the script approach to webwork and alter the example problem to use the buttons to set variables in the geobebra window in webwork.
I can do some simply things like changing colors and point sizes. I want to have the values of a vector set by the user via input of magnitude and angle/phase. I can do this in the desktop geogebra - inpt the magnitude and phase, compute the (x,y) coordinates of the vector and execute the vector command with the right values.

If I leave the input box in the gbb64 code and copy it to the webwork problem, I can set the vector. BUT I don't want the input boxes in the graph. I want the input to be in the position of the buttons and boxes in the example problem 6 at UofR.

This presents a problem for me - I don't know if I can use inputbox in the script of the example. I have tried to use button and set the coordinates with something like

<input type="button" value="set coords of V1: " onclick="setCoords('V1', setXfield.value, setYfield.value);">
<input type="text" name="setXfield" id="V1x" size="5" value="">
<input type="text" name="setYfield" id="V1y" size="5" value="">

this doesn't work.

I have searched and can't find a tutorial for interfacing the script commands of geogebra with the javescript used in the example. can you point me in the right direction for instruction?

for the record: my code is below
thanks

## DBsubject(Algebra)
## DBchapter(Conic sections)
## DBsection(Circles)
DOCUMENT();
loadMacros(
"PGstandard.pl",
"MathObjects.pl",
"PGinfo.pl",
"AppletObjects.pl",
#"source.pl",
"PGcourse.pl",
);
TEXT(beginproblem());

$showPartialCorrectAnswers = 1;

Context("Complex");
Context()->flags->set(
#tolerance => 0.15,
#tolType => "relative",
#zeroLevel=>10,
#zeroLevelTol=>0.2

);
#################################
# Set up problem
# Set parameters for a circle
#################################
$F= random(1,1.5,0.1);
$G = random(1,1.5,0.1);
$V1a=-($F+$G*i);
$V2a=-($F+$G*i)**2;
$V3a=-($F+$G*i)**3;
$V4a=-($F+$G*i)**4;


#$V1vr=re($V1v);
$V1ang=(arg($V1a)%(2*pi))/pi*180;
$V2ang=(arg($V2a)%(2*pi))/pi*180;
$V3ang=(arg($V3a)%(2*pi))/pi*180;
$V4ang=(arg($V4a)%(2*pi))/pi*180;


$V1abs=abs($V1a);
$V2abs=abs($V2a);
$V3abs=abs($V3a);
$V4abs=abs($V4a);
$xmax=ceil(1.25*(sqrt(2)*abs($V4a)));
$xmin=-$xmax;
$ymax=$xmax;
$ymin=$xmin;






$answer = Compute("($V1abs,$V1ang,$V2abs,$V2ang,$V3abs,$V3ang,$V4abs,$V4ang)");
@tol=(0.1,3); # Magnitude Tolerance 0.1, Angular Tolerance 3 degrees
@type=(0,1,0,1,0,1,0,1); #0 for magnitude value, 1 for angular value in degrees



######################################
# Create link to applet:
###################################
# You can name your applet (anything reasonable :-) )
# Adjust the height and width as desired
# Paste the geogebra parameters in at the bottom of the page just above the
# command end command
# so that they don't get in the way
###################################


$appletName = "ggbfoo";
$applet = GeogebraWebApplet(
code => "geogebra.GeoGebraApplet",
archive => "geogebra.jar",
codebase => findAppletCodebase("geogebra.jar"),
appletName => $appletName,
appletId => $appletName,
submitActionAlias => 'getAppletValues', # default actionAlias
initializeActionAlias => '', # default actionAlias
setStateAlias => 'setXML',
getStateAlias => 'getXML',
setConfigAlias => '',
getConfigAlias => '',
returnFieldName => '',
width => 700, # may want to modify width
height => 700, # may want to modify height
# mayscript => "true",
debugMode => 0, # set debugMode to 0 for no debug
# to 1 to make xml representation visible
# to 2 to add alerts detailing progression
# through the applet
onInit => 'ggbOnInit',
type => 'geogebraweb',
submitActionScript => qq{ getQE('answerBox').value = getAppletValues() },
selfLoading => 1,
params => GEOGEBRA_PARAMS(),# paste parameters in
);


##################################
# Setup GeogebraWebApplet --
###################################
###############################################
#
# For persistence of GeoGebra applet state
# when answers are submitted or page is refreshed.
# Uses JavaScript interface to GeoGebra.

HEADER_TEXT(
qq!
<script language="javascript">
function ggbOnInit(param) {
if (param == "$appletName") {
applet_loaded(param,1); // report that applet is ready.
ww_applet_list[param].safe_applet_initialize(2);
}




}

</script>

<noscript>For this question to work properly, you must enable JavaScript, or use another browser (or computer) on which JavaScript works.</noscript>
!);

#######################################################
#
# For setting initial values in GeoGebra from WeBWorK
# Uses JavaScript interface to GeoGebra.
TEXT( MODES(TeX=>'', HTML=><<END_SCRIPT ) );
<script language="javascript">
function setAppletCoefficients() {
var applet=getApplet("$appletName"); // alert("Updating coefficients");
if (typeof(applet)!="undefined") {
if (typeof(applet.setValue)!="undefined") {
////////////////////////////////////////////////////////////////
// List the values of the parameters to be set in the applet here
applet.setValue("xmin", $xmin);
applet.setValue("xmax", $xmax);
applet.setValue("ymin",$ymin);
applet.setValue("ymax", $ymax);






} else {
setTimeout("setAppletCoefficients()", 1000);
}
} else {
setTimeout("setAppletCoefficients()",1000);
}
}
ww_applet_list["$appletName"].setConfig = function() {setAppletCoefficients()};

</script>

END_SCRIPT

HEADER_TEXT( MODES(TeX=>'', HTML=><<END_SCRIPT ) );

<script language="javascript">
function getAppletValues() {
console.log("getAppletValues() entered");
// get a handle for the applet object
var applet = $appletName;
var V1m = applet.getValue("V1m");
var V1ang= applet.getValue("V1ang");
var V2m = applet.getValue("V2m");
var V2ang= applet.getValue("V2ang");
var V3m = applet.getValue("V3m");
var V3ang= applet.getValue("V3ang");
var V4m = applet.getValue("V4m");
var V4ang= applet.getValue("V4ang");
return(V1m + ',' +V1ang +','+V2m + ',' +V2ang +','+ V3m + ',' +V3ang +','+V4m + ',' +V4ang);
}
</script>
END_SCRIPT
###################################
#insert applet into body -- this does not need to be changed
# except to adjust the insertion of the reinitialize_button or
# a hidden AnswerBox
###################################
TEXT($PAR, MODES(TeX=>'geogebraweb code',
HTML=>$applet->insertAll(
debug =>0,
reinitialize_button => 1,
includeAnswerBox=>1,
)));

#######################################
# TEXT
#######################################
Context()->texStrings;
BEGIN_TEXT
$test;
Given \(y = -($F + $G j) ^n\), $BR
Plot the graph of this function in polar coordinates with n = 1, 2, 3, and 4
Please drag the four vectors to the correct positions in the figure below. The red, green, blue and magenta vectors correspond to the cases of n=1, 2, 3 and 4 respectively. Note: WeBWork and MATLAB adopt different conventions for the phase angles, namely \([0^{\circ},360^{\circ}) \) and \((-180,180]\) respectively. However, this should not affect the geometry relationship between the vectors in your plot. Considering the difficulties in operating on the screen, your vector magnitude will be checked to \(\pm $tol[0]\) and your angle will be checked to \(\pm $tol[1] ^{\circ}\).
Click the submit answers button when you are done.
@{correct}

END_TEXT

#TEXT($PAR, "foostate |", $inputs_ref->{ "${appletName}_state"}, "|");

TEXT( "run SetConfig", q!<script language="javascript">setConfig()</script> !) if $inputs_ref->{ "${appletName}_state"} =~ "restart_applet";

TEXT(MODES( TeX => "GeoGebra Applet",
HTML =><<"END_APPLET" ) ); # " " means interpolate variables

<input type="button" value="Hide V1" onclick="getApplet('$appletName').setVisible('V1', false);">
<input type="button" value="Show V1" onclick="getApplet('$appletName').setVisible('V1', true);">
<input type="button" value="V1 red" onclick="getApplet('$appletName').setColor('V1', 255, 0, 0);">
<input type="button" value="V1 blue" onclick="getApplet('$appletName').setColor('V1', 0, 0, 255);">
<input type="button" value="Delete V1" onclick="getApplet('$appletName').deleteObject('V1');">
<input type="button" value="Reset" onclick="getApplet('$appletName').reset();">
 
$PAR
<input type="button" value="get coords of V1: " onclick="getCoords('V1');">
<input type="text" name="getXfield" id="V1x" size="5">
<input type="text" name="getYfield" id="V1y" size="5">
$PAR

<input type="button" value="set coords of V1: " onclick="setCoords('V1', setXfield.value, setYfield.value);">
<input type="text" name="setXfield" id="V1x" size="5" value="">

<input type="text" name="setYfield" id="V1y" size="5" value="">

 


END_APPLET

#########################################
# ANSWER section
#########################################
#$test=List('answerBox');
#NAMED_ANS( 'answerBox' => $answer->cmp(ordered=>1) );

NAMED_ANS( 'answerBox' =>$answer->
cmp(list_checker => sub {
my ($correct,$student,$ansHash,$value) = @_;
my $n = scalar(@$student); # number of student answers
my $score = 0; # number of correct student answers
my @errors = (); # stores error messages
my $i; # loop counters
#
# Loop though the student answers
##
for ($i = 0; $i < $n; $i++) {
my $err,$errt;
my $ith = Value::List->NameForNumber($i+1);
my $p = $student->[$i]; # i-th student answer
my $a = $p->value;
my $q = $correct->[$i]; # i-th student answer
my $b = $q->value;
if ($type[$i]==0){
$err=abs($a-$b)
}
if ($type[$i]==1){
$errt=abs($a-$b);
$err=min($errt,360-$errt);
}

if ($err<$tol[$type[$i]] ) {$score++} else {
push(@errors,"Your $ith point is not correct") unless $ansHash->{isPreview}
}
}
return ($score,@errors);
}));


sub GEOGEBRA_PARAMS {
my $result = {
showResetIcon=>"false" ,
enableRightClick=>"false" ,
enableLabelDrags=>"false",
showMenuBar=>"false" ,
showToolBar=>"false",
showAlgebraInput=>"false",
useBrowserForJS=>"true",
allowRescaling=>"false",
enableShiftDragZoom=>"false",
#geogebra work sheet link https://ggbm.at/stSsYPfV
ggbbase64=>"UEsDBBQACAgIAPiKvUwAAAAAAAAAAAAAAAAXAAAAZ2VvZ2VicmFfZGVmYXVsdHMyZC54bWztml9z2ygQwJ+vn4Lh6e4htpAl28lE6aSdubnMpGnmkuncK5awzAWDTqBYzqcvAlmSazv1v9ROLnkIWryA+O1qWZDOP+ZjBh5JKqngAUQtBwLCQxFRHgcwU8OTPvx48eE8JiImgxSDoUjHWAXQLzSrdlpqed1+UYeTJIAhw1LSEIKEYVU0CaAYDhnlBAKQS3rGxQ0eE5ngkNyFIzLG1yLEyvQ1Uio5a7cnk0lrNmpLpHE7jlUrlxEE+o65DGB5caa7m2s06Rh113FQ+58v17b7E8qlwjzU4+vZRGSIM6akviSMjAlXQE0TEsBEUK4gYHhAWABvCwn8PkwJ+QOCspGG5MCLD7+dy5GYADH4l4S6TqUZqdoZoV3o6J8/CyZSkAaw14MgtsUggK7va1YsGeEAOlaZ4SlJwSNmVQ3OlAhNe1M7xEySma4e6YuIiP3FK/U5HRuKQCqizYAgkAkhkbmyM0TGJlNj3kZ/oRBpJEEewBt8A8G0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3EMm74FMHkDGVAz5DRUask8V81B8DmS7Ue0Hs2zPrcmza4ENv5dcj1nf4ttX5fKOfLNdq+zBbxoeEcSORXpk7FI+dkl+OCnpvwfjdvD6l7NksbS5TerV9RfT6cR/3PIv1gHswmR/MqV3kbUBc1NM25mX7Fw3TSq3H3R1neDHUIQudRNJd+QXN5N0VKbx2CRxTxIkereQhD/AaG21qeefjry1aXc/n7JjOe3ab7M62v7E6X5w0P3G9cX/AVBLBwjHVHkcWQkAALUrAABQSwECFAAUAAgICAD4ir1MYKrbFOsEAABUJgAAFwAAAAAAAAAAAAAAAAAAAAAAZ2VvZ2VicmFfZGVmYXVsdHMyZC54bWxQSwECFAAUAAgICAD4ir1MELnUiuUCAADYDAAAFwAAAAAAAAAAAAAAAAAwBQAAZ2VvZ2VicmFfZGVmYXVsdHMzZC54bWxQSwECFAAUAAgICAD4ir1M1je9uRkAAAAXAAAAFgAAAAAAAAAAAAAAAABaCAAAZ2VvZ2VicmFfamF2YXNjcmlwdC5qc1BLAQIUABQACAgIAPiKvUzHVHkcWQkAALUrAAAMAAAAAAAAAAAAAAAAALcIAABnZW9nZWJyYS54bWxQSwUGAAAAAAQABAAIAQAAShIAAAAA"};
$result;
}
ENDDOCUMENT();
Thanks - the weighted parts looks like a good first approach. If you make the multiple choice parts sufficiently small, they will figure out that thye shouldn't waste attempts on them. The multipart problem look intriguing and we'll investigate.
I tried the weighted part method unsuccessfully. I tried a weighting of 80/10/10 and got parts b and c correct - but Webwork said the test student got 67%, not 80% as I'd expected.
WEIGHTED_ANS($F5->cmp(), 80 );
WEIGHTED_ANS( $popup->cmp(), 10 );
WEIGHTED_ANS( $popupc->cmp(), 10 );


the problem is copied below

# DESCRIPTION
# Problem from 'Mathematics: The Language of Electrical and Computer Engineering', Viniotis and Trussell, 3rd ed.
# WeBWorK problem written by Joel Trussell, <hjt@ncsu.edu>
# ENDDESCRIPTION

## DBsubject(Electrical Engineering)
## DBchapter(Fourier Series)
## DBsection(Problems)
## Institution(North Carolina State University)
## Author(H. J. Trussell)
## TitleText1('Mathematics: The Language of Electrical and Computer Engineering')
## AuthorText1('Viniotis and Trussell')
## EditionText1('3')
## Problem1('9.31')


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

DOCUMENT();

loadMacros(
"PGstandard.pl",
"MathObjects.pl",
"PGchoicemacros.pl",
"PGgraphmacros.pl",
"parserPopUp.pl",
"unionTables.pl",
"weightedGrader.pl"
);

$refreshCachedImages=1;

TEXT(beginproblem());


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

Context("Numeric");
Context()->flags->set( reduceConstants=>0 );
Context()->variables->are( t=> "Real" );
Context()->flags->set(
tolerance => 0.001,
tolType => "absolute",
);

#
# Part A
#

$T = random(1,6,1);
$w0 = 2*pi/$T;
$f = random(2,8,1);
$f2 = 2 * $f;
$Ymax = 1.5*$f;
$Ymin = -1.5*$f;

$F1 = Compute("$f/2 + $f2/pi cos($w0 t)");
$F3 = Compute("$f/2 + $f2/pi cos($w0 t) - $f2/(3 pi) cos(3 $w0 t) ");
$F5 = Compute("$f/2 + $f2/pi cos($w0 t) - $f2/(3 pi) cos(3 $w0 t) + $f2/(5 pi) cos(5 $w0 t)");

#
# Part B
#

$g1 = $F3;
$g2 = Compute("$f/2 + $f2/pi sin($w0 t) - $f2/(3 pi) sin(3 $w0 t)");
#$g2 = Compute("$f/2 + $f2/pi cos($w0 t) - $f2/(3 pi) cos(3 $w0 t) ");;
$g3 = -($F5);

$g[0] = "$F5 for t in <-$T,$T> using color:red and weight:2";
$gr[0] = init_graph(-$T,$Ymin,$T,$Ymax,'axes'=>[0,0]);
$gr[0]->lb('reset');
$gr[0]->lb(new Label(5.25,0.25,'t','black','center','middle'));
$gr[0]->lb(new Label(0.25,5.25,'y','black','center','middle'));

$g[1] = "$g1 for t in <-$T,$T> using color:red and weight:2";
$gr[1] = init_graph(-$T,$Ymin,$T,$Ymax,'axes'=>[0,0]);
$gr[1]->lb('reset');
$gr[1]->lb(new Label(5.25,0.25,'t','black','center','middle'));
$gr[1]->lb(new Label(0.25,5.25,'y','black','center','middle'));

$g[2] = "$g2 for t in <-$T,$T> using color:red and weight:2";
$gr[2] = init_graph(-$T,$Ymin,$T,$Ymax,'axes'=>[0,0]);
$gr[2]->lb('reset');
$gr[2]->lb(new Label(5.25,0.25,'t','black','center','middle'));
$gr[2]->lb(new Label(0.25,5.25,'y','black','center','middle'));

$g[3] = "$g3 for t in <-$T,$T> using color:red and weight:2";
$gr[3] = init_graph(-$T,$Ymin,$T,$Ymax,'axes'=>[0,0]);
$gr[3]->lb('reset');
$gr[3]->lb(new Label(5.25,0.25,'t','black','center','middle'));
$gr[3]->lb(new Label(0.25,5.25,'y','black','center','middle'));


for $i (0..3) {
# use ($fin) to make graphs smooth - note you need the parentheses
($f1n) = plot_functions( $gr[$i], $g[$i]);
$f1n->steps(100);
$fig[$i]=image(insertGraph($gr[$i]),
width=>200,height=>200,tex_size=>450);
}

$k = 0;

@perm = shuffle(4);
@fig = @fig[@perm];
@inv = invert(@perm);

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

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

#
# Part C
#

@ftex = ();

$ftex[0] =
"
\left\lbrace
\begin{array}{rrr}
0, && -T/2 \leq t < -T/4,
\\
$f, && -T/4 \leq t \leq T/4,
\\
0, && T/4 < t \leq T/2.
\end{array}
\right.
";


$ftex[1] =
"
\left\lbrace
\begin{array}{rrr}
0, && -T/2 \leq t < -T/4,
\\
-$f, && -T/4 \leq t \leq T/4,
\\
0, && T/4 < t \leq T/2.
\end{array}
\right.
";

$ftex[2] =
"
\left\lbrace
\begin{array}{rrr}
-$f, && -T/2 \leq t < 0,
\\
$f, && 0 \leq t \leq T/2.
\end{array}
\right.
";

$ftex[3] =
"
\left\lbrace
\begin{array}{rrr}
$f, && -T/2 \leq t < 0,
\\
-$f, && 0 \leq t \leq T/2.
\end{array}
\right.
";


$k = 0;

@permc = shuffle(4);
@ftex = @ftex[@permc];
@invc = invert(@permc);

@functionname = ("s1(t)", "s2(t)", "s3(t)", "s4(t)");

$popupc = PopUp(["?","s1(t)","s2(t)","s3(t)","s4(t)"], $functionname[$invc[$k]]);



Context()->texStrings;
BEGIN_TEXT
This problem is related to Problem 9.31 in the text
(a) A signal, \( s(t) \), with period \( T = $T\), is approximated by using the first few terms in the frequency domain by the following non-zero (complex) Fourier coefficients (all others are zero):
\( \displaystyle S(0) = \frac{$f}{2} \),
\( \displaystyle S(1) = S(-1) = \frac{$f}{\pi} \),
\( \displaystyle S(3) = S(-3) = -\frac{$f}{3 \pi} \),
\( \displaystyle S(5) = S(-5) = \frac{$f}{5 \pi} \).
Find the approximation \( \hat{s}(t) \), where $BR
\[\hat{s}(t) = \sum_{n = -5}^5 S(n) e^{jn\omega_0 t} = \sum_{n = 0}^5 C(n) cos(n\omega_0 t + \theta_n).\] (See Section 9.1.2 of the text.)
$BR
Write the answer as the sum of cosines with phase. There should be no complex numbers in your formula.
$PAR
\( \hat{s}(t) = \) \{ ans_rule(70) \}
$BR
$BR
(b) Using a MATLAB, graph the Fourier approximation
\( \hat{s}(t) \) and then select the letter of the graph which
most closely resembles your graph. \{ $popup->menu() \}
$BR
Note that the scales on the graphs below are not needed to answer this question. You may use any \( \omega_0 \) that you desire for your plot.
$BR
\{
$BCENTER.
BeginTable().
AlignedRow([$fig[0],$fig[1],$fig[2],$fig[3]]).
TableSpace(5,0).
AlignedRow(["A","B","C","D"]).
EndTable().
$BR.
"(Click on a graph to enlarge it.)" .
$ECENTER
\}
$BR
$BR
(c) Which signal given below could the signal that is being approximated?
\( s(t) \) model? \{ $popupc->menu() \}
$BR
$BR
\{
$BCENTER.
BeginTable().
AlignedRow([ "\( \displaystyle s_1(t) = $ftex[0] \)", "\( \displaystyle s_2(t) = $ftex[1] \)" ]).
TableSpace(25,0).
AlignedRow([ "\( \displaystyle s_3(t) = $ftex[2] \)", "\( \displaystyle s_4(t) = $ftex[3] \)" ]).
EndTable().
$ECENTER
\}
END_TEXT
Context()->normalStrings;

$showPartialCorrectAnswers = 1;


WEIGHTED_ANS($F5->cmp(), 80 );

WEIGHTED_ANS( $popup->cmp(), 10 );

WEIGHTED_ANS( $popupc->cmp(), 10 );

COMMENT('MathObject version');
ENDDOCUMENT();

WeBWorK Problems -> Draggable proofs -> Re: Draggable proofs

by tim Payer -
Yes Peter,

I hope you have some success with debugging the draggable proofs.
I have been wanting to use the feature for some time but can't with its current bug. The draggable proof problems needs an automatic "refresh" with each successive attempt. Without a refresh the chosen word snippets are duplicated in the original column.

I wish I had more expertise to offer....:(

OPL Maintenance -> OPL keyword search not working

by Alex Jordan -
We are using 2.13. The keyword search feature for the OPL in the Library Browser appears to be not working. I just ran OPL-update and restarted apache to be sure.

If I go to advanced search and type in a keyword (concavity), I'm not sure what is supposed to happen. It doesn't auto-refresh like when you use the drop-down taxonomy menus. If I press ENTER it reacts as if I had clicked "Add All". If I directly click "View Problems", it says "There are no matching WeBWorK problems". But there are many, for instance Library/Union/setDervConcavity/4-3-49.pg.

Does anyone else experience this in their Library Browser?
Does it render properly when you act as the student and view the problem? If so, it's probably at least partly related to the browser.

This happens to me every once in a while, and usually refreshing the page fixes it. I suspect that in the cases I've seen it has been a result of the connection being interrupted while MathJax is being loaded. I think I've seen the same thing when the page load times out before MathJax is loaded.

If refreshing doesn't work, try holding down "shift" and refreshing the page. This forces a reload of not only the page itself, but all the dependencies including the javascript.

WeBWorK Main Forum -> Weird rendering problem occasionally

by Wesley Burr -
Hi, all,

My GoogleFu has failed me, and I can't find anyone else this has applied to. We're running ~ 600 quizzes per week in WeBWorK, and in the last two weeks I've had two students who've had questions not render properly. Refreshing / logging back in doesn't seem to work. It's a gateway/quiz setup, 15 minute limit. They've both seem something like the attached image, where all the options of the multiple choice are replaced by "[math]".

In the second case, I know the student's details: he was running the latest version of Google Chrome on Mac OSX 10.12. I don't recall the first time it happened.

Unfortunately, with the randomization of questions, it's hard to be able to tell what the solutions for a given student should be, so I've just overwritten the score for these two students. I'd like to figure out what's going on, though, so I can fix it in general, or at least have a workaround for the TAs to use.

Any thoughts?


Attachment ww_render.jpg