## DESCRIPTION ## Using a GeoGebra applet to provide an interactive accumulation function ## ENDDESCRIPTION ## KEYWORDS('GeoGebra applet example','GeoGebra web applet example', 'Accumulation function','Fundamental Theorem of Calculus') ## DBsubject('WeBWorK') ## DBchapter('WeBWorK Tutorial') ## DBsection('Fort Lewis Tutorial 2011') ## Date('11/04/2010') ## Author('Paul Pearson')## DESCRIPTION ## Using a GeoGebra applet to provide an interactive accumulation function ## ENDDESCRIPTION ## KEYWORDS('GeoGebra applet example','Accumulation function','Fundamental Theorem of Calculus') ## DBsubject('WeBWorK') ## DBchapter('WeBWorK Tutorial') ## DBsection('Fort Lewis Tutorial 2011') ## Date('11/04/2010') ## Author('Paul Pearson') ## Institution('Fort Lewis College') ## TitleText1('') ## EditionText1('') ## AuthorText1('') ## Section1('') ## Problem1('') ########### revised 12/18/13 for HTML5 Bruce Cohen ########################################## # Initialization DOCUMENT(); loadMacros( "PGstandard.pl", "MathObjects.pl", "unionTables.pl", "AppletObjects.pl", "parserNumberWithUnits.pl", "PGcourse.pl", ); $showPartialCorrectAnswers = 1; TEXT(beginproblem()); ########################################## # Setup Context("Numeric")->variables->are(t=>"Real"); $a = random(2,4,1); $b = random(5,8,1); $c = random(1,3,1); $d = random(1,3,1); while ($c == $d) { $d = random(1,3,1); } # $f = Formula("$c / (1+(t-2)^2) + $d / (1+(t-4)^2)"); $F = Formula("$c * arctan(t-2) + $d * arctan(t-4) - $c * arctan(-2) - $d * arctan(-4)"); $Fa = $F->eval(t=>$a); $Fb = $F->eval(t=>$b); $disp = $Fb-$Fa; ########################## # # GeoGebra Applet Setup $appletName = "ggbApplet"; $applet = GeogebraWebApplet( code => "geogebra.GeoGebraApplet", #archive => "geogebra.jar", #codebase => "/webwork2_course_files/fortlewis_math221/applets", #codebase => findAppletCodebase("geogebra.jar"), #codebase => "/webwork2_files/applets/geogebra_stable", #codebase => "https://test.webwork.maa.org/webwork2_files/applets/geogebra_stable", appletName => $appletName, appletId => $appletName, submitActionAlias => 'getXML', # default getXML initializeActionAlias => 'setXML', # default setXML setStateAlias => 'setXML', getStateAlias => 'getXML', setConfigAlias => '', getConfigAlias => '', returnFieldName => '', width => 486, height => 306, mayscript => "true", debugMode => 0, # 0 = no debug, 1 = xml visible, 2 = add alerts thru applet onInit => 'ggbOnInit', type => 'geogebra', parameter_string => GEOGEBRA_PARAMS(), # paste parameters in section at the bottom ); ############################################### # # PNG picture of GeoGebra applet for hardcopy $im = image( "AF7-c".$c."-d".$d.".png", width=>486, height=>335, tex_size=>900 ); ############################################### # # For persistence of GeoGebra applet state # when answers are submitted or page is refreshed. # Uses JavaScript interface to GeoGebra. HEADER_TEXT( qq! !); ####################################################### # # For setting initial values in GeoGebra from WeBWorK # Uses JavaScript interface to GeoGebra. TEXT( MODES(TeX=>'', HTML=>< 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 // Set variables "c" and "d" in GeoGebra to values $c and $d from WebWork applet.setValue("c", $c); applet.setValue("d", $d); } else { setTimeout("setAppletCoefficients()", 1000); } } else { setTimeout("setAppletCoefficients()",1000); } } ww_applet_list["$appletName"].setConfig = function() {setAppletCoefficients()}; END_SCRIPT ########################################## # # Main text Context()->texStrings; BEGIN_TEXT \{ ColumnTable( "The figure shows an interactive graph of velocity \( v(t) \), in meters per second, where time \( t \) is measured in seconds. You can change the value of \( t \) in the graph by clicking and dragging the red dot along the horizontal \( t \)-axis. $BR $BR (a) What is the displacement between \( t = 0 \) seconds and \( t = $a \) seconds? $BR". ans_rule(20). " (include ".helpLink('units').") $BR $BR (b) What is the displacement between \( t = 0 \) seconds and \( t = $b \) seconds? $BR". ans_rule(20). " (include ".helpLink('units').") $BR $BR (c) What is the displacement between \( t = $a \) seconds and \( t = $b \) seconds? $BR". ans_rule(20). " (include ".helpLink('units').")" , $BCENTER. MODES(HTML=>$applet->insertAll(debug=>0, reinitialize_button=>0, includeAnswerBox=>0,), TeX=>$im). $PAR. "Graph of velocity \( y = v(t) \)". $ECENTER , indent => 0, separation => 30, valign => "TOP" ); \} END_TEXT Context()->normalStrings; ##################################### # Answer Evaluation ANS( NumberWithUnits("$Fa","m") ->cmp(tolerance=>0.11, tolType=>'absolute') ); ANS( NumberWithUnits("$Fb","m") ->cmp(tolerance=>0.11, tolType=>'absolute') ); ANS( NumberWithUnits("$disp","m")->cmp(tolerance=>0.21, tolType=>'absolute') ); ################################################################## # # GeoGebra applet parameters sub GEOGEBRA_PARAMS { $result = qq{
}; } COMMENT('MathObject version. Uses GeoGebra applet.'); ENDDOCUMENT(); ## Institution('Fort Lewis College') ## TitleText1('') ## EditionText1('') ## AuthorText1('') ## Section1('') ## Problem1('') ########################################## # Initialization DOCUMENT(); loadMacros( "PGstandard.pl", "MathObjects.pl", "unionTables.pl", "AppletObjects.pl", "parserNumberWithUnits.pl", "PGcourse.pl", ); $showPartialCorrectAnswers = 1; TEXT(beginproblem()); ########################################## # Setup Context("Numeric")->variables->are(t=>"Real"); $a = random(2,4,1); $b = random(5,8,1); $c = random(1,3,1); $d = random(1,3,1); while ($c == $d) { $d = random(1,3,1); } # $f = Formula("$c / (1+(t-2)^2) + $d / (1+(t-4)^2)"); $F = Formula("$c * arctan(t-2) + $d * arctan(t-4) - $c * arctan(-2) - $d * arctan(-4)"); $Fa = $F->eval(t=>$a); $Fb = $F->eval(t=>$b); $disp = $Fb-$Fa; ########################## # # GeoGebra Applet Setup $appletName = "ggbApplet"; $applet = JavaApplet( code => "geogebra.GeoGebraApplet", archive => "geogebra.jar", codebase => "/webwork2_course_files/fortlewis_math221/applets", #codebase => findAppletCodebase("geogebra.jar"), #codebase => "/webwork2_files/applets/geogebra_stable", #codebase => "https://test.webwork.maa.org/webwork2_files/applets/geogebra_stable", appletName => $appletName, appletId => $appletName, submitActionAlias => 'getXML', # default getXML initializeActionAlias => 'setXML', # default setXML setStateAlias => 'setXML', getStateAlias => 'getXML', setConfigAlias => '', getConfigAlias => '', returnFieldName => '', width => 486, height => 306, mayscript => "true", debugMode => 0, # 0 = no debug, 1 = xml visible, 2 = add alerts thru applet onInit => 'ggbOnInit', type => 'geogebra', parameter_string => GEOGEBRA_PARAMS(), # paste parameters in section at the bottom ); ############################################### # # PNG picture of GeoGebra applet for hardcopy $im = image( "AF7-c".$c."-d".$d.".png", width=>486, height=>335, tex_size=>900 ); ############################################### # # For persistence of GeoGebra applet state # when answers are submitted or page is refreshed. # Uses JavaScript interface to GeoGebra. HEADER_TEXT( qq! !); ####################################################### # # For setting initial values in GeoGebra from WeBWorK # Uses JavaScript interface to GeoGebra. TEXT( MODES(TeX=>'', HTML=>< 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 // Set variables "c" and "d" in GeoGebra to values $c and $d from WebWork applet.setValue("c", $c); applet.setValue("d", $d); } else { setTimeout("setAppletCoefficients()", 1000); } } else { setTimeout("setAppletCoefficients()",1000); } } ww_applet_list["$appletName"].setConfig = function() {setAppletCoefficients()}; END_SCRIPT ########################################## # # Main text Context()->texStrings; BEGIN_TEXT \{ ColumnTable( "The figure shows an interactive graph of velocity \( v(t) \), in meters per second, where time \( t \) is measured in seconds. You can change the value of \( t \) in the graph by clicking and dragging the red dot along the horizontal \( t \)-axis. $BR $BR (a) What is the displacement between \( t = 0 \) seconds and \( t = $a \) seconds? $BR". ans_rule(20). " (include ".helpLink('units').") $BR $BR (b) What is the displacement between \( t = 0 \) seconds and \( t = $b \) seconds? $BR". ans_rule(20). " (include ".helpLink('units').") $BR $BR (c) What is the displacement between \( t = $a \) seconds and \( t = $b \) seconds? $BR". ans_rule(20). " (include ".helpLink('units').")" , $BCENTER. MODES(HTML=>$applet->insertAll(debug=>0, reinitialize_button=>0, includeAnswerBox=>0,), TeX=>$im). $PAR. "Graph of velocity \( y = v(t) \)". $ECENTER , indent => 0, separation => 30, valign => "TOP" ); \} END_TEXT Context()->normalStrings; ##################################### # Answer Evaluation ANS( NumberWithUnits("$Fa","m") ->cmp(tolerance=>0.11, tolType=>'absolute') ); ANS( NumberWithUnits("$Fb","m") ->cmp(tolerance=>0.11, tolType=>'absolute') ); ANS( NumberWithUnits("$disp","m")->cmp(tolerance=>0.21, tolType=>'absolute') ); ################################################################## # # GeoGebra applet parameters sub GEOGEBRA_PARAMS { $result = qq{ # For persistence of applet state when answers are submitted # The GeoGebra "source code" from GeoGebra -> File -> Export -> Dynamic worksheet as Webpage (html) }; } COMMENT('MathObject version. Uses GeoGebra applet.'); ENDDOCUMENT();