topic started 9/22/2001; 7:37:51 PM last post 9/22/2001; 7:37:51 PM |
9/22/2001; 7:37:51 PM (reads: 12472, responses: 0) |
|
The Java applet exampleTo obtain this problem(1 pt) rochesterLibrary/setMAAtutorial/javaappletexample.pg
WARNINGS µ¦å{h <hr /> Enter this code <pre>DOCUMENT();<br /><br />loadMacros("PG.pl",<br /> "PGbasicmacros.pl",<br /> "PGchoicemacros.pl",<br /> "PGanswermacros.pl",<br /> ); <br /> <br />TEXT(beginproblem(), $BR,$BBOLD, "Java applet example", $EBOLD, $BR,$BR); <br /># define function to be evaluated<br />$a= random(1,3,1);<br />$b= random(-4,4,.1);<br />$c = random(-4,4,1);<br />$x0=random(-2,2,1);<br />$function = FEQ(" ${a}x^2+${b}x +$c "); # This function will be redefined for javaScript as well. sub fp { # define a subroutine to calculate the derivative<br /> my $x = shift;<br /> 2*$a*$x+$b;<br />} $ans = fp($x0); BEGIN_TEXT $PAR This problem illustrates how you can embed Java applet code in a WeBWorK example to create an interactive homework problem that could never be provided by a text book. $PAR WeBWorK can use existing $BBOLD javaScript$EBOLD and $BBOLD Java $EBOLD code to augment its capabilities. $HR END_TEXT $javaApplet = <<EOF; <applet code="mathbeans.SliderGraphApplet.class" archive="/courses/system_html/applets/mathbeans.jar" codebase="../classes/" width=400 height=380> <PARAM NAME="variable1" VALUE="a"> <PARAM NAME="variable2" VALUE="b"> <param name="function" value="x^2 +a*x +b"> <param name="limits" value="-2 2 -9 9"> </applet> <H6><A HREF="http://math.hws.edu/mathbeans/applets/index.html"> mathbean applet from David Ecks</A> </H6> EOF # only print out the java applet code when viewing on the screen TEXT(MODES( TeX => " \fbox{ The java applet was displayed here<br /> }", HTML => $javaApplet, )); $a1= random(-3,3,.5); $a2= random(-3,3,.5); $a3= random(-3,3,.5); $b1 = ($a1/2)**2; # remember to use ** for exponentiation when # calculating in pure Perl! $b2= ($a2 / 2)**2; $b3 = ($a3 / 2)**2; ANS(num_cmp( $b1, reltol => 10, format=>'%0.2g')); ANS(num_cmp( $b2, reltol => 10, format=>'%0.2g')); ANS(num_cmp( $b3, reltol => 10, format=>'%0.2g')); BEGIN_TEXT $PAR The graph above represents the function \[f(x) = x^2 + a x +b \] where \( a \) and \( b \) are parameters. $PAR For each value of \( a \) find the value of \( b \) which makes the graph just touch the x-axis. $BR if a= $a1 then \{ ans_rule(10) \}$BR if a= $a2 then \{ ans_rule(10) \}$BR if a= $a3 then \{ ans_rule(10) \} $PAR Does this relationship between a and b specify b as a function of a? \{ ans_rule(4) \} (Yes or No)$BR Does this relationship between a and b specify a as a function of b? \{ ans_rule(4) \} (Yes or No)$BR Write a formula for calculating this value of \( b \) from \( a \).$BR b = \{ ans_rule(40) \} END_TEXT ANS(str_cmp('Yes') ); ANS(str_cmp('No') ); ANS(fun_cmp('(a/2)^2', vars=>'a')); ENDDOCUMENT();
Comments:This problem is just a demo -- it doesn't actually work if you push the submit answer button. (You can test a {linkWebworkProblem("tutorialCourse", "setFirstSteps","10","live")} version of this problem.)
|