From: Mike G. v. a. <we...@ma...> - 2005-07-28 19:41:26
|
Log Message: ----------- updating modelCourse to conform to hosted.webwork Added Files: ----------- webwork2/courses/modelCourse/templates/setMAAtutorial: MAAtutorialSetHeader.pg conditionalquestionexample.pg hello.pg hermitegraphexample.pg javaappletexample.pg javascriptexample1.pg javascriptexample2.pg liteApplet1.pg liteApplet2.pg matchinglistexample.pg multiplechoiceexample.pg ontheflygraphicsexample1.pg ontheflygraphicsexample2.pg paperHeader.pg popuplistexample.pg prob3.pg prob4.pg screenHeader.pg simple_drawing.pg simplemultiplechoiceexample.pg standardexample.pg truefalseexample.pg vectorfieldexample.pg Revision Data ------------- --- /dev/null +++ courses/modelCourse/templates/setMAAtutorial/standardexample.pg @@ -0,0 +1,47 @@ +DOCUMENT(); +loadMacros("PGbasicmacros.pl", + "PGchoicemacros.pl", + "PGanswermacros.pl", + "PGauxiliaryFunctions.pl" +); + +TEXT(beginproblem(), $BR,$BBOLD, "Standard Example", $EBOLD, $BR,$BR); + +# A question requiring a string answer. +$str = 'world'; +#$str = "Dolly"; +BEGIN_TEXT +Complete the sentence: $BR +\{ ans_rule(20) \} $str; +$PAR +END_TEXT + +ANS( str_cmp( "Hello") ); + +# A question requiring a numerical answer. +#define the variables +$a = 3; +$b = 5; +#$a=random(1,9,1); +#$b=random(2,9,1); + +BEGIN_TEXT +Enter the sum of these two numbers: $BR + \($a + $b = \) \{ans_rule(10) \} +$PAR +END_TEXT + +$sum = $a + $b; +ANS( num_cmp( $sum ) ); + +# A question requiring an expression as an answwer +BEGIN_TEXT +Enter the derivative of \[ f(x) = x^{$b} \] $BR +\(f '(x) = \) \{ ans_rule(30) \} +$PAR +END_TEXT +$new_exponent = $b-1; +$ans2 = "$b*x^($new_exponent)"; +ANS( fun_cmp( $ans2 ) ); +ENDDOCUMENT(); + \ No newline at end of file --- /dev/null +++ courses/modelCourse/templates/setMAAtutorial/javascriptexample1.pg @@ -0,0 +1,146 @@ +DOCUMENT(); + +loadMacros( + "PGbasicmacros.pl", + "PGchoicemacros.pl", + "PGanswermacros.pl", +); +TEXT(beginproblem(), $BR,$BBOLD, "JavaScript Example 1", $EBOLD, $BR,$BR); +# define function to be evaluated +$a= random(1,3,1); +$b= random(-4,4,.1); +$c = random(-4,4,1); +$x0=random(-2,2,1); + +# function = ${a}x^2+${b}x +${c} +# This is just to provide the correct answer. +# This function will be defined for javaScript below. +sub fp { # define a perl subroutine to calculate the derivative + my $x = shift; + 2*$a*$x+$b; +} +$ans = fp($x0); + +## This text will be placed in the header section of the HTML page +## not in the body where TEXT output is placed. +## Not processing is done. + +HEADER_TEXT(<<EOF); +<SCRIPT LANGUAGE="JavaScript"> +<!-- Begin + +function func(x) { +return( $a*Math.pow(x,2) + $b*x +$c );} + // We redefine the function for the javaScript + // A savy student will be able to tell to read this + // by looking at the HTML source of their window. + // Later we'll see other methods that make this + // difficult or impossible. + +// End + --> +</SCRIPT> + +EOF + +TEXT(beginproblem()); +TEXT(MODES( TeX => "", + Latex2HTML => "\begin{rawhtml} + <NOSCRIPT> This problem requires that Java Script be + enabled </NOSCRIPT> ~~n\end{rawhtml} + ", + HTML_tth => "<NOSCRIPT> This problem requires that javaScript be enabled + </NOSCRIPT>~~n", + HTML => "<NOSCRIPT> This problem requires that javaScript be enabled + </NOSCRIPT>~~n" +)); + +$functionArrow = MODES( + TeX => "\(- f\rightarrow\)", + Latex2HTML => "\(- f\rightarrow \) ", + HTML_tth => "-- f -- > ", + HTML => '-- f -- > ' +); + +# The following string contains a combination of HTML and javaScript +# which displays the input table for the javaScript calculator + +$javaScript =<<ENDOFSCRIPT; +<CENTER> +<TABLE BORDER=4> +<TR> +<TD> +<INPUT TYPE="text" NAME="Input1" Value = "$x0" Size="20"> +</TD> +<TD> +<INPUT TYPE="button" VALUE="---f-->" + OnClick="this.form.Output1.value=func(this.form.Input1.value)"> +</TD> +<TD> +<INPUT TYPE="text" NAME="Output1" Size="20"> +</TD> +</TR> +<TR> +<TD> +<INPUT TYPE="text" NAME="Input2" Value = "$x0" Size="20"> +</TD> +<TD> +<INPUT TYPE="button" VALUE="---f-->" + OnClick="this.form.Output2.value=func(this.form.Input2.value)"> +</TD> +<TD> +<INPUT TYPE="text" NAME="Output2" Size="20"> +</TD> +</TR> +<TR> +<TD> +<INPUT TYPE="text" NAME="Input3" Value = "$x0" Size="20"> +</TD> +<TD> +<INPUT TYPE="button" VALUE="---f-->" + OnClick="this.form.Output3.value=func(this.form.Input3.value)"> +</TD> +<TD> +<INPUT TYPE="text" NAME="Output3" Size="20"> +</TD> +</TR> +</TABLE> + +</CENTER> +ENDOFSCRIPT + + + +BEGIN_TEXT + +Find the derivative of the function f(x). The windows below will tell +you the value of f for any input x. (I call this an "oracle function", since +if you ask, it will tell.) +$PAR +\(f '( $x0 ) \) = \{ans_rule(50 ) \} +$PAR +You may want to use a +\{ htmlLink(alias("${htmlDirectory}calc.html"), + 'calculator', + qq! TARGET = "ww_calculator" + ONCLICK="window.open( this.href,this.target, + 'width=200, height=350, scrollbars=no, resizable=off' + )" +!) \} + +to find the result. + You can also enter numerical expressions and have + WeBWorK do the calculations for you. +END_TEXT + +# Here is where we actually print the javaScript, or alternatives for printed output. + +TEXT(MODES( + TeX => " \fbox{ The java Script calculator was displayed here + }", + HTML => $javaScript, + )); + +ANS(num_cmp($ans,reltol => 1) ); #We are allowing 1 percent error for the answer. + +ENDDOCUMENT(); \ No newline at end of file --- /dev/null +++ courses/modelCourse/templates/setMAAtutorial/MAAtutorialSetHeader.pg @@ -0,0 +1,106 @@ +DOCUMENT(); + +loadMacros( + "PGbasicmacros.pl", + "PGchoicemacros.pl", + "PGanswermacros.pl" +); + +TEXT($BEGIN_ONE_COLUMN); + +TEXT(MODES(TeX =>EV3(<<'EOT'), HTML=>"", Latex2HTML=>"" )); +\noindent {\large \bf $studentName} +\hfill +\noindent {\large \bf MAA Minicourse New Orleans January 2001} +\par +\noindent WeBWorK assignment number \{ protect_underbar($setNumber) \} due $formattedDueDate;. +\hrule +EOT + + +################## +# EDIT BELOW HERE +################## + +BEGIN_TEXT +$BR +$BR +Welcome to the MAA short course on $BBOLD WeBWorK $EBOLD. +$PAR +Here is a synopsis of the tutorial examples presented in this set. They have been designed for learning the PG language, and are not necessarily the best questions to use for mathematics instruction. +$PAR +$BBOLD 1. Hello world example: $EBOLD Illustrates the basic structure of a PG problem. +$PAR +$BBOLD 2. Standard example: $EBOLD This covers what you need to know to ask the majority of the questions you would want to ask in a calculus course. Problems with text answers, numerical answers and answers involving expressions are covered. +$PAR +$BBOLD 3. Simple multiple choice example: $EBOLD Uses lists(arrays) to implement a multiple choice question. +$PAR +$BBOLD 4. Multiple choice example: $EBOLD Uses the multiple choice object to implement a multiple choice question. +$PAR +$BBOLD 5. Matching list example: $EBOLD +$PAR +$BBOLD 6. True/false example: $EBOLD +$PAR +$BBOLD 7. Pop-up true/false example: $EBOLD Answers are chosen from a pop-up list. +$PAR +$BBOLD 8. On-the-fly graphics example 1: $EBOLD The graphs are regenerated each time you press the submit button +$PAR +$BBOLD 9. On-the-fly-graphics example 2: $EBOLD -- Adds some randomization to the first example. +$PAR +$BBOLD 10. Static graphics example: $EBOLD Presents graphs created on a separate application (e.g. Mathematica) and saved. +$PAR +$BBOLD 11. Hermite graph example: $EBOLD A particularly useful way of generating predictable graphs by specifying the value and first derivative of a function at each point. Piecewise linear graphs are also included in this example. +$PAR +$BBOLD 12. HTML links example: $EBOLD Shows how to link other web resources to your WeBWorK problem. +$PAR +$BBOLD 13. JavaScript example 1: $EBOLD An example which takes advantage of this interactive media! This one requires students to calculate the derivative of a function from the definition. +$PAR +$BBOLD 14. JavaScript example 2: $EBOLD A variant of the previous example that generates the example function as a cubic spline so that students can't read the javaScript code to find out the answer. +$PAR +$BBOLD 15. Vector field example $EBOLD Generates vector field graphs on-the-fly. +$PAR +$BBOLD 16. Conditional question example: $EBOLD Illustrates how you can create a problem which first asks an easy question, and once that has been answered correctly, follows up with a more involved question on the same material. +$PAR +$BBOLD 17 Java applet example: $EBOLD A preliminary example of how to include Java applets in WeBWorK problems. +$HR +END_TEXT + +################## +# EDIT ABOVE HERE +################## +BEGIN_TEXT +The primary purpose of WeBWorK is to let you know if you are getting the right answer or to alert +you if you get the wrong answer. Usually you can attempt a problem as many times as you want before +the due date. However, if you are having trouble figuring out your error, you should +consult the book, or ask a fellow student, one of the TA's or +your professor for help. Don't spend a lot of time guessing -- it's not very efficient or effective. +The computer has NO CLUE about WHY your answer is wrong. Computers are good at checking, +but for help go to a human. + +$PAR +Give 4 or 5 significant digits for (floating point) numerical answers. +For most problems when entering numerical answers, you can if you wish +enter elementary expressions such as \( 2\wedge3 \) instead of 8, \( sin(3*pi/2) \)instead +of -1, \( e\wedge (ln(2)) \) instead of 2, +\( (2+tan(3))*(4-sin(5))\wedge6-7/8 \) instead of 27620.3413, etc. + Here's the +\{ htmlLink(qq!http://webwork.math.rochester.edu/webwork_system_html/docs/docs/pglanguage/availablefunctions.html!,"list of the functions") \} + which WeBWorK understands. +$PAR +You can use the Feedback button on each problem +page to send e-mail to the professors. + + +$END_ONE_COLUMN +END_TEXT +#<<<######################################################## +BEGIN_TEXT +$HR +You can view the +\{ htmlLink(sourceAlias("links/set$setNumber/MAAtutorialSetHeader.html"), + "source", q!TARGET="source"!)\} +for this header file. +END_TEXT +#########################################################>>> +ENDDOCUMENT(); # This should be the last executable line in the problem. + --- /dev/null +++ courses/modelCourse/templates/setMAAtutorial/hermitegraphexample.pg @@ -0,0 +1,126 @@ +DOCUMENT(); +loadMacros("PGbasicmacros.pl", + "PGchoicemacros.pl", + "PGanswermacros.pl", + "PGnumericalmacros.pl", + "PGgraphmacros.pl" +); +TEXT($BEGIN_ONE_COLUMN); +TEXT(beginproblem(), $BR,$BBOLD, "Hermite polynomial graph example", $EBOLD, $BR,$BR); +$showPartialAnswers = 1; + +$graph = init_graph(-5,-5,5,5,'axes'=>[0,0],'grid'=>[10,10]); + +my (@x_values1, @y_values1); +foreach $i (0..10) { + $x_values1[$i] =$i-5; + $y_values1[$i] = random(-4,4,1); +} + +# creates a reference to a perl subroutine for the piecewise linear function +# passing through the defined points +$fun_rule = plot_list(~~@x_values1, ~~@y_values1); + +#new function is to be plotted in graph +$f1=new Fun($fun_rule, $graph); +$f1->color('black'); + +$trans = non_zero_random(-2,2,1); +# add a new function to the graph which is a translate of the first +$fun_rule2 = sub{ my $x = shift; &$fun_rule($x-$trans) }; +$f2 = new Fun($fun_rule2, $graph); +$f2->color('orange'); + +$graph->stamps(open_circle(-1,&$fun_rule(-1),'black') ); +# indicates open interval at the left endpoint +$graph->stamps(closed_circle(4,&$fun_rule(4), 'black') ); +# and a closed interval at the right endpoint +# Be careful about getting the stamps properly located on the translated +# function below: +$graph->stamps(open_circle(-1 + $trans, &$fun_rule(-1),'orange') ); +# indicates open interval at the left endpoint +$graph->stamps(closed_circle(4 +$trans, &$fun_rule(4), 'orange') ); +# and a closed interval at the right endpoint + +$graph2 = init_graph(-4,-4,4,4,'axes'=>[0,0],'grid'=>[8,8]); +$b1= random(-3.5,3.5,.5); +$b2= random(-3.5,3.5,.5); +$b3= random(-3.5,3.5,.5); +@x_val3 = (-4,-3,-2,-1, 0, 1, 2, 3, 4 ); +@y_val3 = ( 0, 1, 2, 0,$b1, $b2, $b3, 1, 2 ); +@yp_val3= ( .1, 1, 0,-2, 0, 1, 2, -3, 1 ); +$hermite = new Hermite( + ~~@x_val3, # x values + ~~@y_val3, # y values + ~~@yp_val3 # y prime values + ); +$spline_rule = $hermite->rf_f; +$f3 = new Fun($spline_rule, $graph2); +$f3->color('green'); +$graph2->stamps(closed_circle(-4, &$spline_rule(-4), 'green') ) ; +$graph2->stamps(closed_circle( 4, &$spline_rule( 4), 'green') ) ; + +# Insert the graphs and the text. +BEGIN_TEXT + +$PAR +We have developed other ways to specify graphs which are to be created 'on the fly'. +All of these new methods consist of adding macro packages to WeBWorK. Since they +do not require the core of WeBWorK to be changed, these enhancements can be added by +anyone using WeBWorK. +$PAR + These two piecewise linear graphs were created by specifying the points at the nodes. + $BR Click on the graph to view a larger image. +$PAR +\{ image(insertGraph($graph),tex_size => 300, width=> 300, height=> 300 ) \} +$HR +If the black function is written as \(f(x)\), then the orange function +would be written as \( f( \) \{ ans_rule \} \( ) \). +\{ANS(function_cmp("x-$trans")),'' \} +END_TEXT +# $PAR +# The numerical calculations were all written in Perl using +# numerical routines adapted from the Numerical Analysis book by Burden and Faires. +# $BR +# We are also working on a macro which will automatically +# identify the maximum, minimum and inflection points of an arbitary hermite +# cubic spline from its specifying values. This will allow automatic generation +# of problems in which the maximum, minimum and inflection points are to be +# deduced from a graph. +# +# Get the internal local maximums +@critical_points = keys %{$hermite->rh_critical_points}; +@critical_points = num_sort( @critical_points); +@minimum_points = (); +foreach my $x (@critical_points) { + push(@minimum_points, $x) if &{$hermite->rf_fpp}($x) >0 ; +} +# TEXT(pretty_print(~~@minimum_points)); # (for debugging purposes) +$answer_string = ""; +foreach my $x (@minimum_points) { + $answer_string .= EV2(' \{ ans_rule(10) \} '); +} + +BEGIN_TEXT +$HR +This graph was created using a hermite spline by specifying points at + +\{ begintable(1+scalar( @x_val3 ) ) \} +\{ row('x', @x_val3)\} +\{ row('y', @y_val3) \} +\{ row('yp',@yp_val3) \} +\{endtable() \} + +$PAR +\{ begintable(2) \} +\{row( image(insertGraph($graph2), tex_size => 300,width=>300, height=> 300), + "List the internal local minimum points $BR in increasing order: $BR $answer_string" + ) \} +\{ endtable() \} + +$PAR +END_TEXT +ANS(num_cmp([ @minimum_points ], tol => .3)); + +TEXT($END_ONE_COLUMN); +ENDDOCUMENT(); \ No newline at end of file --- /dev/null +++ courses/modelCourse/templates/setMAAtutorial/prob4.pg @@ -0,0 +1,95 @@ +#<PRE> +#Description +# Testing knowledge of differentiation rules +#EndDescription + +DOCUMENT(); # This should be the first executable line in the problem. + +loadMacros("PGbasicmacros.pl", + "PGchoicemacros.pl", + "PGanswermacros.pl", + "PGgraphmacros.pl", + "PGnumericalmacros.pl" + ); + +TEXT(&beginproblem); +$showPartialCorrectAnswers = 0; + + + +# allow the student to change the seed for this problem. +$newProblemSeed = ( defined( ${$inputs_ref}{'newProblemSeed'} ) )? ${$inputs_ref}{'newProblemSeed'} : $problemSeed; +$PG_random_generator->srand($newProblemSeed); +BEGIN_TEXT + +To see a different version of the problem change +the problem seed and press the 'Submit Answer' button below.$PAR Problem Seed: +\{ M3( +qq! Change the problem seed to change the problem:$problemSeed!, +qq! Change the problem seed to change the problem: + \begin{rawhtml} + <INPUT NAME="newProblemSeed" VALUE = "$newProblemSeed" SIZE = "10"> + \end{rawhtml}!, +qq! <INPUT NAME="newProblemSeed" VALUE = "$newProblemSeed" SIZE = "10">! +) +\} + +$HR +END_TEXT + +######################################################################## +# Make a new select list +$ml = new_select_list(); +#$ml -> rf_print_q(~~&my_print_q); +# New versions using the macros in PGchoicemacros.pl +$ml->rf_print_q(~~&pop_up_list_print_q); +$ml -> ra_pop_up_list([ No_answer => " ?",SR => "Sum Rule",PR => "Product Rule",CR => "Chain rule",QR => "Quotient rule" ] ); + + +$ml -> qa ( +"\( (f(x) + g(x) )' = f'(x) + g'(x) \)", +"SR", +"\( ( f(x)g(x) )' = f'(x)g(x) + f(x)g'(x) \)", +"PR", +"\( ( f(g(x)) )' = f'(g(x))g'(x) \) ", +"CR", +"\( \frac{d}{dx} \sin(\cos(x)) = - \cos(\cos(x))\sin(x) \)", +"CR", +"\( (f(x) - g(x) )' = f'(x) - g'(x) \)", +"SR", +); + +$ml ->choose(5); + +#coda + + + + +BEGIN_TEXT + $PAR + +For each example below, list the label of the differentiation rule used in that example: $BR + +\{ $ml -> print_q \} + +$PAR +You can view the +\{ htmlLink(alias("${htmlDirectory}links/setDerivativeRules/prob2.html"), "source",q!TARGET="source"!) \} +for this problem. +or consult the +\{ htmlLink("/webwork_system_html/docs/techdescription/pglanguage/index.html","documentation") \} for more details on the PG language. + +END_TEXT + +install_problem_grader(~~&std_problem_grader); + +ANS( str_cmp( $ml->ra_correct_ans ) ) ; + +BEGIN_TEXT +$PAR +There are only a few examples in this problem. A production verison +would need more examples to choose from. +END_TEXT +ENDDOCUMENT(); # This should be the last executable line in the problem. +#</PRE> --- /dev/null +++ courses/modelCourse/templates/setMAAtutorial/matchinglistexample.pg @@ -0,0 +1,129 @@ +DOCUMENT(); # This should be the first executable line in the problem. + +loadMacros( + "PGbasicmacros.pl", + "PGchoicemacros.pl", + "PGanswermacros.pl", + ); + + +TEXT(beginproblem(), $BR,$BBOLD, "Matching list example", $EBOLD, $BR,$BR); + + +# Since this is a matching question, we do not usually wish to tell students +# which parts of the matching question have been answered correctly and which +# areincorrect. That is too easy. To accomplish this we set the following +# flag to zero. +$showPartialCorrectAnswers = 0; + +# Make a new match list +$ml = new_match_list(); +# enter questions and matching answers +$ml -> qa ( + "\( \sin(x) \)", # Notice the use of the LateX construction + "\( \cos(x) \)", # for math mode: \\( ... \\) and the use of TeX + "\( \cos(x) \)", # symbols such as \\sin and \\tan. + "\( -\sin(x) \)", + "\( \tan(x) \)", + "\( \sec^2(x) \)", # Remember that in these strings we are + # only specifying typography,via TeX, + "\( x^{20} \)", #not any calculational rules. + "\( 20x^{19} \)", + "\( \sin(2x) \)", + "\( 2\cos(2x) \)", + "\( \sin(3x) \)", + "\( 3\cos(3x) \)" +); + + +# Calculate coefficients for another question +$b=random(2,5); +$exp= random(2,5); +$coeff=$b*$exp; +$new_exp = $exp-1; + +# Store the question and answers in the match list object. +$ml -> qa ( + '\( ${b}x^$exp \)', + '\( ${coeff}x^{$new_exp} \)', +); + +# Add another example +$b2=random(2,5); +$exp2= random(2,5); +$coeff2=$b2*$exp; +$new_exp2 = $exp-1; +$ml -> qa ( + "\( ${b2}x^$exp2 \)", + "\( ${coeff2}x^{$new_exp2} \)", +); + +# Choose four of the question and answer pairs at random. +$ml ->choose(4); +# Using choose(8) would choose all eight questions, +# but the order of the questions and answers would be +# scrambled. + +# The following code is needed to make the enumeration work right within tables +# when LaTeX output is being used. +# It is an example of the powerful tools of TeX and perl which are available +# for each PG problem author. +# Once we figure out the best way to protect enumerated lists automatically +# we will include it in the tables macro. Meantime, it is better to have +# have to do it by hand, rather than to have the wrong thing done automatically. + +$BSPACING = MODES( TeX => '\hbox to .5\linewidth {\hspace{0.5cm}\vbox {', + HTML =>' ', + Latex2HTML => ' ' +); +$ESPACING = MODES(TeX => '}}', HTML =>'', Latex2HTML => ''); +sub protect_enumerated_lists { + my @in = @_; + my @out = (); + foreach my $item (@in) { + push(@out, $BSPACING . $item . $ESPACING); + } + @out; +} +# End of code for protecting enumerated lists in TeX. + +# Now print the text using $ml->print_q for +# the questions and $ml->print_a to print the answers. + +BEGIN_TEXT +$PAR + +Place the letter of the derivative next to each function listed below: $BR +\{ $ml -> print_q \} +$PAR +\{$ml -> print_a \} +$PAR +END_TEXT + +ANS( str_cmp( $ml->ra_correct_ans ) ) ; +# insist that the first two questions (labeled 0 and 1) are always included +$ml ->choose([0,1],1); +BEGIN_TEXT +Let's print the questions again, but insist that the +first two questions (about sin and cos) always be included. +Here is a second way to format this question, using tables: +$PAR +\{begintable(2)\} +\{row(protect_enumerated_lists( $ml->print_q, $ml -> print_a) )\} +\{endtable()\} +$PAR +And below is yet another way to enter a table of questions and answers: +$PAR +END_TEXT +ANS( str_cmp( $ml->ra_correct_ans ) ) ; +# Finally add a last answer +$ml ->makeLast("The derivative is $BR not provided"); +BEGIN_TEXT + \{ begintable(2) \} + \{ row( protect_enumerated_lists($ml->print_q, $ml ->print_a))\} + \{endtable()\} +END_TEXT +# Enter the correct answers to be checked against the answers to the students. +ANS( str_cmp( $ml->ra_correct_ans ) ) ; + +ENDDOCUMENT(); \ No newline at end of file --- /dev/null +++ courses/modelCourse/templates/setMAAtutorial/javascriptexample2.pg @@ -0,0 +1,154 @@ +DOCUMENT(); + +loadMacros("PGbasicmacros.pl", + "PGchoicemacros.pl", + "PGanswermacros.pl", + "PGnumericalmacros.pl", # needed for the javaScript spline code + ); +TEXT(beginproblem(), $BR,$BBOLD, "JavaScript Example 2", $EBOLD, $BR,$BR); + +# define function to be evaluated +$a= random(1,3,1); +$b= random(-4,4,.1); +$c = random(-4,4,1); +$x0=random(-2,2,1); + +# function = ${a}x^2+${b}x +${c}sin(x) +# This is just to provide the correct answer. +# This function will be defined for javaScript below. +sub fp { # define a perl subroutine to calculate the derivative + my $x = shift; + 2*$a*$x+$b; +} +$ans = fp($x0); + +# approximate the function by a cubic spline +sub fun{ + my $x = shift; + ${a}*$x**2+$b*$x +$c; +} +@x = (); +@y = (); +for ( $x1 = -3; $x1<3; $x1 = $x1+.1) { + push(@x, $x1); + push(@y, fun($x1) ); +} +#warn join(" ", @x) ; # test the calculation of the data points +#warn join(" ", @y) ; +$javascript= javaScript_cubic_spline(~~@x, ~~@y, name =>'func'); + +#$javascript =~s/</\</g; # make the script visible for debugging +#warn "script=$javascript" ; # check that the script was created + + + +## This text will be placed in the header section of the HTML page +## not in the body where TEXT output is placed. +## Not processing is done. + +HEADER_TEXT( javaScript_cubic_spline(~~@x, ~~@y, name =>'func') ); + + +TEXT(beginproblem()); +TEXT(MODES( TeX => "", + Latex2HTML => "\begin{rawhtml} + <NOSCRIPT> This problem requires that Java Script be + enabled </NOSCRIPT> ~~n\end{rawhtml} + ", + HTML_tth => "<NOSCRIPT> This problem requires that javaScript be + enabled </NOSCRIPT>~~n", + HTML => "<NOSCRIPT> This problem requires that javaScript be + enabled </NOSCRIPT>~~n" +)); + +$functionArrow = MODES( + TeX => "\(- f\rightarrow\)", + Latex2HTML => "\(- f\rightarrow \) ", + HTML_tth => "-- f -- > ", + HTML => '-- f -- > ' +); + +# The following string contains a combination of HTML and javaScript +# which displays the input table for the javaScript calculator + +$javaScript =<<ENDOFSCRIPT; +<CENTER> +<TABLE BORDER=4> +<TR> +<TD> +<INPUT TYPE="text" NAME="Input1" Value = "$x0" Size="20"> +</TD> +<TD> +<INPUT TYPE="button" VALUE="---f-->" + OnClick="this.form.Output1.value=func(this.form.Input1.value)"> +</TD> +<TD> +<INPUT TYPE="text" NAME="Output1" Size="20"> +</TD> +</TR> +<TR> +<TD> +<INPUT TYPE="text" NAME="Input2" Value = "$x0" Size="20"> +</TD> +<TD> +<INPUT TYPE="button" VALUE="---f-->" + OnClick="this.form.Output2.value=func(this.form.Input2.value)"> +</TD> +<TD> +<INPUT TYPE="text" NAME="Output2" Size="20"> +</TD> +</TR> +<TR> +<TD> +<INPUT TYPE="text" NAME="Input3" Value = "$x0" Size="20"> +</TD> +<TD> +<INPUT TYPE="button" VALUE="---f-->" + OnClick="this.form.Output3.value=func(this.form.Input3.value)"> +</TD> +<TD> +<INPUT TYPE="text" NAME="Output3" Size="20"> +</TD> +</TR> +</TABLE> + +</CENTER> +<!-- Script Size: 1.89 KB --> +ENDOFSCRIPT + +BEGIN_TEXT +Find the derivative of the function f(x). The windows below will tell +you the value of f for any input x. (I call this an "oracle function", since +if you ask, it will tell.) +$PAR +\(f'( $x0 ) \) = \{ans_rule(50 ) \} +$PAR +You may want to use a +\{ htmlLink(alias("${htmlDirectory}calc.html"), + 'calculator', + qq! TARGET = "ww_calculator" + ONCLICK="window.open( this.href,this.target, + 'width=200, height=350, scrollbars=no, resizable=off' + )" +!) \} + +to find the result. You can also enter numerical expressions and +have WeBWorK do the calculations for you. +END_TEXT + +# Here is where we actually print the javaScript, or alternatives for printed output. +TEXT(MODES( + TeX => " \fbox{ The java Script calculator was displayed here + }", + Latex2HTML => "\begin{rawhtml} $javaScript \end{rawhtml}", + HTML_tth => $javaScript, + HTML => $javaScript, + )); + + + + +ANS(num_cmp($ans,reltol => 1) ); #We are allowing 1 percent error for the answer. + + +ENDDOCUMENT(); --- /dev/null +++ courses/modelCourse/templates/setMAAtutorial/ontheflygraphicsexample1.pg @@ -0,0 +1,117 @@ +DOCUMENT(); +loadMacros( + "PGbasicmacros.pl", + "PGchoicemacros.pl", + "PGanswermacros.pl", + "PGgraphmacros.pl" +); + +TEXT(beginproblem(), $BR,$BBOLD, "On-the-fly Graphics Example1", $EBOLD, $BR,$BR); +$showPartialCorrectAnswers = 0; + +# First we define a graph with x and y in the range -4 to 4, axes (strong lines) +# defined at the point [0,0] and +# with 8 gridlines horizontally and 8 grid lines veritically. +# $graph is a graph object (or more appropriately, a pointer to a graph object). + +# We will define a function and it's first and second derivatives defined +# on the domain [-4,4] +$dom = 4; +$graph = init_graph(-$dom,-$dom,$dom,$dom,'axes'=>[0,0],'grid'=>[8,8]); + +# Here are the basic colors -- we'll mix them up in the next example +@colors = ("blue", "red", "green"); #orange, yellow, +@scrambled_colors = @colors; +@labels = ('A', 'B', 'C'); +@scrambled_labels = @labels; + +$a=random(0, 6.3, .1); +$b=random(1.1, 1.5, .1); +# now define the functions too be graphed +# defining strings need to be on one line (\n is not handled correctly) +# The three variables $f, $fp, and $fpp contain strings +# with the correct syntax to be inputs into the plot_function +# macro. The FEQ macro (Format EQuation) cleans up the writing of the function. +# Otherwise we would need to worry about the signs of $a, $b and so forth. +# For example if $b were negative, then after interpolation +# $a+$b might look like 3+-5. FEQ replaces the +- pair by -, which is what you want. + +# The first string (for $f) should be read as: "The function is calculated +# using sin($a+$b*cos(x)) +# and is defined for all x in the +# interval -$dom to +$dom. Draw the function using the first color +# in the permuted color list @scrambled_colors +# and using a weight (width) of two pixels." + +$f = FEQ( + "sin($a+$b*cos(x)) for x in <-$dom,$dom> using color:$scrambled_colors[0] and weight:2" +); +$fp = FEQ( + "cos($a+${b}*cos(x))*(-$b)*sin(x) for x in <-$dom,$dom> using color=$scrambled_colors[1] and weight:2" +); +# The multiplication signs are not actually needed, although they are allowed. + $fpp = FEQ("-sin($a+${b}*cos(x))*$b*$b* sin(x)* sin(x)+ cos($a+$b* cos(x))*(-$b)*cos(x) for x in <-$dom,$dom> using color=$scrambled_colors[2] and weight=2" +); + + + +# Install the functions into the graph object. +# Plot_functions converts the string to a subroutine which performs the +# necessary calculations and +# asks the graph object to plot the functions. + +($fRef,$fpRef,$fppRef) = plot_functions( $graph, + $f,$fp,$fpp + ); + +# The output of plot_functions is a list of pointers to functions which +# contain the appropriate data and methods. +# So $fpRef->rule points to the method which will calculate the value +# of the function. +# &{$fpRef->rule}(3) calculates the value of the function at 3. + +# create labels for each function +# The 'left' tag determines the justification of the label to the defining point. + + +$label_point=-0.75; +$label_f = new Label ( $label_point,&{$fRef->rule}($label_point), + $scrambled_labels[0], $scrambled_colors[0],'left'); + # NOTE: $fRef->ruleis a reference to the subroutine which calculates the + # function. It was defined in the output of plot_functions. + # It is used here to calculate the y value of the label corresponding + # to the function, and below to find the y values for the labels + # corresponding to the first and second derivatives. + +$label_fp = new Label ( $label_point,&{$fpRef->rule}($label_point), + $scrambled_labels[1],$scrambled_colors[1],'left'); +# Place the second letter in the permuted letter list at the point +# (-.75, fp(-.75)) using the second color in the permuted color list. + +$label_fpp = new Label ( $label_point,&{$fppRef->rule}($label_point), + $scrambled_labels[2],$scrambled_colors[2],'left'); + +# insert the labels into the graph +$graph->lb($label_f,$label_fp,$label_fpp); + +# make sure that the browser will fetch +# the new picture when it is created by changing the name of the +# graph each time the problem seed is changed. This helps prevent caching problems +# on browsers. + + $graph->gifName($graph->gifName()."-$newProblemSeed"); +# Begin writing the problem. +# This inserts the graph and then asks three questions: + +BEGIN_TEXT +\{ image(insertGraph($graph)) \} $PAR +Identify the graphs A (blue), B( red) and C (green) as the graphs +of a function and its +derivatives (click on the graph to see an enlarged image):$PAR +\{ans_rule(4)\} is the graph of the function $PAR +\{ans_rule(4)\} is the graph of the function's first derivative $PAR +\{ans_rule(4)\} is the graph of the function's second derivative $PAR +END_TEXT +ANS(str_cmp( [@scrambled_labels] ) ); + +ENDDOCUMENT(); \ No newline at end of file --- /dev/null +++ courses/modelCourse/templates/setMAAtutorial/hello.pg @@ -0,0 +1,18 @@ +DOCUMENT(); +loadMacros("PGbasicmacros.pl", + "PGchoicemacros.pl", + "PGanswermacros.pl", + ); + +BEGIN_TEXT +Complete the sentence: $PAR +\{ ans_rule(20) \} world! +END_TEXT + +ANS( str_cmp( "Hello" ) ); # here is the answer, a string. + + + + +ENDDOCUMENT(); + \ No newline at end of file --- /dev/null +++ courses/modelCourse/templates/setMAAtutorial/liteApplet1.pg @@ -0,0 +1,68 @@ +DOCUMENT(); + +loadMacros("PGbasicmacros.pl", + "PGchoicemacros.pl", + "PGanswermacros.pl", +); + +$showPartialCorrectAnswers = 1; +TEXT(beginproblem()); + +# The link to the java applet is hard wired to use the java applet +# served from the University of Rochester WeBWorK machine. +# It is possible to set this up so that the java applet is served +# from any machine +# For details use the Feedback button to contact the authors of WeBWorK + +BEGIN_TEXT +This is a lite applet designed by Frank Wattenberg. +$BR +\{htmlLink( '/webwork2_course_files/demoCourse/live_map_instructions.html ', +'Instructions for using the map',' target="intro" ' )\} +$HR +END_TEXT +$appletText = +appletLink( +q! archive="/courses/system_html/applets/Image_and_Cursor_All/Image_and_Cursor.jar" +code="Image_and_Cursor" width = 500 height = 458 +!, +q!Your browser does not support Java, so nothing is displayed. + <param name = "applet_width" value = "500"> + <param name = "applet_height" value = "458"> + <param name = "image_width" value = "351"> + <param name = "image_height" value = "378"> + <param name = "backdrop_filename" value = "/courses/system_html/applets/Image_and_Cursor_All/AF-MAP.JPG"> + <param name = "display_placement" value = "1"> + <param name = "display_sw" value = "0"> +! +); +sub dist { + my $ra_pt1 = shift; + my $ra_pt2 =shift; + my $conversion = 300 /(145 - 72); # number of km per pixel + return $conversion* sqrt( ($ra_pt1->[0] - $ra_pt2->[0])**2 + ($ra_pt1->[1] - $ra_pt2->[1])**2); +} + +$kandahar = [132,101]; +$kabul = [209,185]; +$mazur_e_sharif = [170, 243]; +$shindand = [46, 155]; + +$questions = EV3( +"$PAR How far is it from Kandahar to Kabul? " , ans_rule(30), +" $PAR How far is it from Kabul to Mazar-e-Sharif? ", ans_rule(30), +" $PAR How far is it from Kandahar to Shindand? " , ans_rule(30), +); +#TEXT( +#begintable(2), +#row( $appletText, $questions), +#endtable() +#); +TEXT($appletText, $questions); +ANS(num_cmp(dist($kandahar,$kabul), reltol => 3, units=>'km')); +ANS(num_cmp(dist($kabul, $mazur_e_sharif), reltol => 3, units=>'km')); +ANS(num_cmp(dist($kandahar,$shindand), reltol => 3, units=>'km')); + + + +ENDDOCUMENT(); \ No newline at end of file --- /dev/null +++ courses/modelCourse/templates/setMAAtutorial/paperHeader.pg @@ -0,0 +1,22 @@ +## Paper set header for setSampleGraders + +DOCUMENT(); + +loadMacros( +"PG.pl", +"PGbasicmacros.pl", +"PGchoicemacros.pl", +"PGanswermacros.pl" +); + + +BEGIN_TEXT +$BEGIN_ONE_COLUMN +This set shows how to write simple WeBWorK problems and introduces you to the most common +constructions. +$END_ONE_COLUMN + +END_TEXT + + +ENDDOCUMENT(); --- /dev/null +++ courses/modelCourse/templates/setMAAtutorial/ontheflygraphicsexample2.pg @@ -0,0 +1,124 @@ +DOCUMENT(); + +loadMacros("PGbasicmacros.pl", + "PGchoicemacros.pl", + "PGanswermacros.pl", + "PGgraphmacros.pl" +); + +TEXT(beginproblem(), $BR,$BBOLD, "On-the-fly Graphics Example2", $EBOLD, $BR,$BR); + +# First we define a graph with x and y in the range -4 to 4, axes (strong lines) +# defined at the point [0,0] and +# with 8 gridlines horizontally and 8 grid lines veritically. +# $graph is a graph object (or more appropriately, a pointer to a graph object). + +# We will define a function and it's first and second derivatives +# defined on the domain [-4,4] + +$dom = 4; +$graph = init_graph(-$dom,-$dom,$dom,$dom,'axes'=>[0,0],'grid'=>[8,8]); + +# We need to scramble the colors and the labels -- otherwise every student +# will have the function is A, the derivative is B, etc. +# and the colors won't be scrambled either. + +#This provides a permutation of the numbers (0,1,2); + +@slice = NchooseK(3,3); + +# Here are the basic colors + +@colors = ("blue", "red", "green"); #orange, yellow, + +# This lists the colors in the order defined by the list in @slice +# It effectively applies the same permutation to the list of colors +# and to the list of labels. A will always be blue, B red, and C green +#and applies the same permutation to the list of labels + +@scrambled_colors = @colors[@slice]; +@labels = ('A', 'B', 'C'); +@scrambled_labels = @labels[@slice]; + +# The rest of this example is the same as ontheflygraphicsexample1 + +# function definitions need to be on one line +$a=random(0, 6.3, .1); +$b=random(1.1, 1.5, .1); + +# The three variables $f, $fp, and $fpp contain strings +# with the correct syntax to be inputs into the plot_function +# macro. The FEQ macro (Format EQuation) cleans up the writing of the function. +# Otherwise we would need to worry about the signs of $a, $b and so forth. +# For example if $b were negative, then after interpolation +# $a+$b might look like 3+-5. FEQ replaces the +- pair by -, which is what you want. + +# The first string (for $f) should be read as: "The function is calculated +# using sin($a+$b*cos(x)) +# and is defined for all x in the +# interval -$dom to +$dom. Draw the function using the first color +# in the permuted color list @scrambled_colors +# and using a weight (width) of two pixels." + +$f = FEQ("sin($a+$b*cos(x)) for x in <-$dom,$dom> using color:$scrambled_colors[0] and weight:2"); +$fp = FEQ("cos($a+${b}*cos(x))*(-$b)*sin(x) for x in <-$dom,$dom> using color=$scrambled_colors[1] and weight:2"); +$fpp = FEQ("-sin($a+${b}*cos(x))*$b*$b* sin(x)* sin(x)+ cos($a+$b* cos(x))*(-$b)*cos(x) for x in <-$dom,$dom> using color=$scrambled_colors[2] and weight=2"); + + +# Install the functions into the graph object. +# Plot_functions converts the string to a subroutine which performs the +# necessary calculations and +# asks the graph object to plot the functions. + +($fRef,$fpRef,$fppRef) = plot_functions( $graph, + $f,$fp,$fpp + ); +# The output of plot_functions is a list of pointers to functions which +# contain the appropriate data and methods. +# So $fpRef->rule points to the method which will calculate the value +# of the function. +# &{$fpRef->rule}(3) calculates the value of the function at 3. + +# create labels for each function +# The 'left' tag determines the justification of the label to the defining point. + + +$label_point=-0.75; +$label_f = new Label ( $label_point,&{$fRef->rule}($label_point), + $scrambled_labels[0],$scrambled_colors[0],'left') ; + # NOTE: $fRef->ruleis a reference to the subroutine which calculates the + # function. It was defined in the output of plot_functions. + # It is used here to calculate the y value of the label corresponding + # to the function, and below to find the y values for the labels + # corresponding to the first and second derivatives. + +$label_fp = new Label ( $label_point,&{$fpRef->rule}($label_point), + $scrambled_labels[1],$scrambled_colors[1],'left') ; +# Place the second letter in the permuted letter list at the point +# (-.75, fp(-.75)) using the second color in the permuted color list. + +$label_fpp = new Label ( $label_point,&{$fppRef->rule}($label_point),$scrambled_labels[2],$scrambled_colors[2],'left'); + +# insert the labels into the graph +$graph->lb($label_f,$label_fp,$label_fpp); + +# make sure that the browser will fetch +# the new picture when it is created by changing the name of the +# graph each time the problem seed is changed. +$graph->gifName($graph->gifName()."-$newProblemSeed"); + +# Begin writing the problem. +# This inserts the graph and then asks three questions: + +BEGIN_TEXT +\{ image(insertGraph($graph),width => 200, height => 200) \} $PAR +Identify the graphs A (blue), B( red) and C (green) as the graphs of a function and its +derivatives (click on the graph to see an enlarged image):$PAR +\{ans_rule(4)\} is the graph of the function $PAR +\{ans_rule(4)\} is the graph of the function's first derivative $PAR +\{ans_rule(4)\} is the graph of the function's second derivative $PAR +END_TEXT + +ANS(str_cmp( [@scrambled_labels] ) ); + +ENDDOCUMENT(); \ No newline at end of file --- /dev/null +++ courses/modelCourse/templates/setMAAtutorial/liteApplet2.pg @@ -0,0 +1,74 @@ +DOCUMENT(); + +loadMacros("PGbasicmacros.pl", + "PGchoicemacros.pl", + "PGanswermacros.pl", +); + +$showPartialCorrectAnswers = 1; +TEXT(beginproblem()); + + +BEGIN_TEXT +This is a lite applet designed by Frank Wattenberg. +$BR +\{htmlLink( '/webwork2_course_files/demoCourse/live_map_instructions.html ', +'Instructions for using the map',' target="intro" ' )\} +$HR +END_TEXT +TEXT( +appletLink( +q! archive="/courses/system_html/applets/Image_and_Cursor_All/Image_and_Cursor.jar" +code="Image_and_Cursor" width = 500 height = 458 +!, +q!Your browser does not support Java, so nothing is displayed. + <param name = "applet_width" value = "500"> + <param name = "applet_height" value = "458"> + <param name = "image_width" value = "351"> + <param name = "image_height" value = "378"> + <param name = "backdrop_filename" value = "/courses/system_html/applets/Image_and_Cursor_All/AF-MAP.JPG"> + <param name = "display_placement" value = "1"> + <param name = "display_sw" value = "0"> +! +), +); +sub dist { + my $ra_pt1 = shift; + my $ra_pt2 =shift; + $conversion = 300 /(145 - 72); # number of km per pixel + return $conversion * sqrt( ($ra_pt1->[0] - $ra_pt2->[0])**2 + ($ra_pt1->[1] - $ra_pt2->[1])**2); +} +@cities = ( + { name => 'Kandahar', location => [132,101] }, + { name => 'Kabul', location => [209,185] }, + { name => 'Mazur e Sharif', location => [170, 243] }, + { name => 'Shindand', location => [46, 155] }, + { name => 'Zaranj', location => [39, 93] } +); +@index = NchooseK(scalar(@cities), 3 ); +sub cityName { + my $index = shift ; + $cities[$index -1]->{name}; +} +sub cityLoc { + my $index = shift; + $cities[$index-1]->{location}; +} + +$conversion = 300 /(145 - 72); # number of km per pixel +BEGIN_TEXT +$PAR +How far is it from \{cityName($index[1])\} to \{cityName($index[2])\}? \{ans_rule(30)\} +$PAR +How far is it from \{cityName($index[1])\} to \{cityName($index[3])\}? \{ans_rule(30)\} +$PAR +How far is it from \{cityName($index[2])\} to \{cityName($index[3])\}? \{ans_rule(30)\} +END_TEXT + +ANS(num_cmp(dist(cityLoc($index[1]),cityLoc($index[2])), reltol=>3, units=>'km')); +ANS(num_cmp(dist(cityLoc($index[2]), cityLoc($index[2])), reltol=>3, units=>'km')); +ANS(num_cmp(dist(cityLoc($index[2]),cityLoc($index[2])), reltol=>3, units=>'km')); + + + +ENDDOCUMENT(); \ No newline at end of file --- /dev/null +++ courses/modelCourse/templates/setMAAtutorial/vectorfieldexample.pg @@ -0,0 +1,94 @@ +DOCUMENT(); # This should be the first executable line in the problem. + +loadMacros("PG.pl", + "PGbasicmacros.pl", + "PGchoicemacros.pl", + "PGanswermacros.pl", + "PGgraphmacros.pl", +); + +TEXT(beginproblem()); # standard preamble to each problem. + +# Since this is a true questions, we do not usually wish to tell students which +# parts of the matching question have been answered correctly and which are +# incorrect. That is too easy. To accomplish this we set the following flag to zero. +$showPartialCorrectAnswers = 0; + + +# Make a new select list + +$tf = new_match_list(); + +$numberOfQuestions = 4; +$tf -> qa ( +"\(y'= 2y + x^2e^{2x} \)", +sub{my ($x,$y) = @_; 2*$y+($x**2)*exp(2*$x); }, +"\( y'= -2 + x - y \)", +sub{my ($x,$y) = @_; -2 + $x - $y;}, +"\(y'= e^{-x} + 2y\)", +sub{my ($x,$y) = @_; exp(-$x) + 2*$y;}, +"\(y'= 2\sin(x) + 1 + y\)", +sub{my ($x,$y) = @_; 2*sin($x) + 1 + $y;}, +"\(y'= -\frac{2x+y)}{(2y)} \)", +sub{my ($x,$y) = @_; ($y==0)? -2*$x/0.001 : -(2*$x+$y)/(2*$y);}, +"\(y'= y + 2\)", +sub{my ($x,$y) = @_; $y + 2 ;}, +); + +$tf ->choose($numberOfQuestions); +BEGIN_TEXT +$BEGIN_ONE_COLUMN + +Match the following equations with their direction field. +Clicking on each picture will give you an +enlarged view. While you can probably solve this problem by guessing, +it is useful to try to predict characteristics of the direction field +and then match them to the picture. +$PAR +Here are some handy characteristics to start with -- +you will develop more as you practice. +$PAR + +\{OL( + "Set y equal to zero and look at how the derivative behaves along the x axis.", + "Do the same for the y axis by setting x equal to 0", + "Consider the curve in the plane defined by setting y'=0 + -- this should correspond to the points in the picture where the + slope is zero.", + "Setting y' equal to a constant other than zero gives the curve of points + where the slope is that + constant. These are called isoclines, and can be used to construct the + direction field picture by hand." +)\} + + + \{ $tf->print_q \} + +END_TEXT +$dx_rule = sub{my ($x,$y) = @_; 1; }; +$dy_rule = sub{my ($x,$y) = @_; $y; }; +# prepare graphs: +@dy_rules = @{ $tf->{selected_a} }; + +for my $i (0..$numberOfQuestions-1) { + $graph[$i] = init_graph(-4,-4,4,4,'axes'=>[0,0],'grid'=>[8,8]); + $vectorfield[$i] = new VectorField($dx_rule, $dy_rules[$i], $graph[$i]); + $vectorfield[$i]->dot_radius(2); + $graphURL[$i] = insertGraph($graph[$i]); +} +#### +BEGIN_TEXT +$PAR + \{ imageRow( [@graphURL[0..$numberOfQuestions/2-1]], + [@ALPHABET[0..$numberOfQuestions/2-1]], height => 200, + width => 200,tex_size=>300 ) \} + \{ imageRow( [@graphURL[$numberOfQuestions/2..$numberOfQuestions-1]], + [@ALPHABET[$numberOfQuestions/2..$numberOfQuestions-1]], + height => 200, width => 200,tex_size=>300 ) \} + +$END_ONE_COLUMN +END_TEXT + +ANS( str_cmp( $tf->ra_correct_ans ) ) ; + +ENDDOCUMENT(); # This should be the last executable line in the problem. --- /dev/null +++ courses/modelCourse/templates/setMAAtutorial/truefalseexample.pg @@ -0,0 +1,63 @@ +DOCUMENT(); +loadMacros("PGbasicmacros.pl", + "PGchoicemacros.pl", + "PGanswermacros.pl", + +); +TEXT(beginproblem(), $BR,$BBOLD, "True False Example", $EBOLD, $BR,$BR); + +# Since this is a true questions, we do not usually wish to tell students which +# parts of the matching question have been answered correctly and which are +# incorrect. That is too easy. To accomplish this we set the following flag to +# zero. +$showPartialCorrectAnswers = 0; + +# True false questions are a special case of a "select list" +# Make a new select list +$tf = new_select_list(); +# $tf now "contains" the select list object. +# Insert some questions and whether or not they are true. + +$tf -> qa ( # each entry has to end with a comma +"All continuous functions are differentiable.", +"F", +"All differentiable functions are continuous.", +"T", +"All polynomials are differentiable.", +"T", +"All functions with positive derivatives are increasing.", +"T", +"All compact sets are closed", +"T", +"All closed sets are compact", +"F", +"All increasing functions have positive deriviatives", +"F", +"All differentiable strictly increasing functions have non-negative derivatives + at every point", +"T", +); + +# Choose four of the question and answer pairs at random. +$tf ->choose(4); + +# Now print the text using $ml->print_q for the questions +# and $ml->print_a to print the answers. + +BEGIN_TEXT +$PAR + +Enter T or F depending on whether the statement is true or false. +(You must enter T or F -- True and False will not work.)$BR + +\{ $tf-> print_q \} + +$PAR + +END_TEXT + +# Enter the correct answers to be checked against the answers to the students. + +ANS( str_cmp( $tf->ra_correct_ans ) ) ; + +ENDDOCUMENT(); # This should be the last executable line in the problem. \ No newline at end of file --- /dev/null +++ courses/modelCourse/templates/setMAAtutorial/popuplistexample.pg @@ -0,0 +1,65 @@ +DOCUMENT(); # This should be the first executable line in the problem. + +loadMacros("PGbasicmacros.pl", + "PGchoicemacros.pl", + "PGanswermacros.pl", +); + +TEXT(beginproblem(), $BR,$BBOLD, "True False Pop-up Example", $EBOLD, $BR,$BR); +$showPartialCorrectAnswers = 0; + +# Make a new select list +$tf = new_select_list(); +# $tf now "contains" the select list object. + +# change the printing mechanism of the object to +# use pop-up list instead of an answer rule. +$tf->rf_print_q(~~&pop_up_list_print_q); + +# What should the pop-up list contain, and what string should it +# submit for an answer when selected? +# These are specified in the statment below. +# To enter T as an answer choose the list element "True" +# To enter F as an answer choose the list element "False" +# The first choice is a blank to make the students do SOMETHING!!! +$tf -> ra_pop_up_list( [ No_answer => " ?", T => "True", F => "False"] ); +# Note how the list is constructed [ answer => list element text, answer => list element text ] + +# Insert some questions and their answers. + +$tf -> qa ( # each entry has to end with a comma +"All continuous functions are differentiable.", +"F", +"All differentiable functions are continuous.", +"T", +"All polynomials are differentiable.", +"T", +"All functions with positive derivatives are increasing.", +"T", +"All compact sets are closed", +"T", +"All closed sets are compact", +"F", +"All increasing functions have positive deriviatives", +"F", +"All differentiable strictly increasing functions have non-negative derivatives + at every point", +"T", +); + +# Choose two of the question and answer pairs at random. +$tf ->choose(4); # Using choose(3) would choose all three + # questions, but the order of the questions + # and answers would be scrambled. + +# Now print the text using $ml->print_q for the questions. +BEGIN_TEXT +$PAR +Indicate whether each statement is true or false. $BR +\{ $tf-> print_q \} +$PAR +END_TEXT +# Enter the correct answers to be checked against the answers to the students. +ANS( str_cmp( $tf->ra_correct_ans ) ) ; + +ENDDOCUMENT(); # This should be the last executable line in the problem. \ No newline at end of file --- /dev/null +++ courses/modelCourse/templates/setMAAtutorial/simplemultiplechoiceexample.pg @@ -0,0 +1,33 @@ +DOCUMENT(); # This should be the first executable line in the problem. +loadMacros( + "PGbasicmacros.pl", + "PGchoicemacros.pl", + "PGanswermacros.pl", +); +TEXT(beginproblem(), $BR,$BBOLD, "Multiple choice example", $EBOLD, $BR,$BR); + + +$showPartialCorrectAnswers = 0; +$question = "What is the derivative of tan(x)?"; +# An example of a list or array variable. It begins with @. +@answer_list = ( "\( \sec^2(x) \)", # correct + "\( -\cot(x) \)", + "\( \tan(x) \)", + "\( \cosh(x) \)", + "\( \sin(x) \)", +); +# These commands permute the order of the answers. +#@permutation = NchooseK(5,5); # random permutation of the five answers +@permutation = (1,0,2,3,4); # example of fixed permutation +@permuted_answer_list = @answer_list[@permutation]; +@inverted_alphabet = @ALPHABET[invert( @permutation )]; # needed to check the answers + +# Use the macro OL to print an Ordered List of the answerslabeled with letters. +BEGIN_TEXT +$BR $question +$PAR \{ OL( @permuted_answer_list ) \} +$PAR Enter the letter corresponding to the correct answer: \{ ans_rule(10) \} +END_TEXT +ANS( str_cmp( $inverted_alphabet[0] ) ) ; + +ENDDOCUMENT(); \ No newline at end of file --- /dev/null +++ courses/modelCourse/templates/setMAAtutorial/prob3.pg @@ -0,0 +1,162 @@ +#<HTML> +#<BODY BGCOLOR = "#ffffff"> +#<PRE> +# Description +# The first example using match lists +# EndDescription + + +DOCUMENT(); # This should be the first executable line in the problem. + +loadMacros("PGbasicmacros.pl", + "PGchoicemacros.pl", + "PGanswermacros.pl", + "PGgraphmacros.pl", + "PGnumericalmacros.pl" + ); + +# TEXT( ... , ... , ) +# Is the simplest way of printing text, each string in the input is immediately printed. +# It does not do any of the simplifying and evaluating tricks performed by the BEGIN_TEXT/END_TEXT construction. + +# beginproblem() is a macro which outputs the string +# which contains the number +# of points the problem is worth. + +# Putting these two ideas together prints the standard opening line of a problem. +# We will use this construction routinely at the beginning of all subsequent problems. +TEXT(beginproblem()); + +# Since this is a matching questions, we do not usually wish to tell students which +# parts of the matching question have been answered correctly and which are +# incorrect. That is too easy. To accomplish this we set the following flag to zero. +$showPartialCorrectAnswers = 0; + + +##################################################################### +# This section allows you to manipulate the problem seed while working on the problem +# thus seeing different versions of the problem. Skip the details of how this works +# for now. + +# allow the student to change the seed for this problem. +$newProblemSeed = ( defined( ${$inputs_ref}{'newProblemSeed'} ) )? ${$inputs_ref}{'newProblemSeed'} : $problemSeed; +$PG_random_generator->srand($newProblemSeed); + +BEGIN_TEXT + +To see a different version of the problem change +the problem seed and press the 'Submit Answer' button below.$PAR Problem Seed: +\{ M3( +qq! Change the problem seed to change the problem:$problemSeed!, +qq! Change the problem seed to change the problem: + \begin{rawhtml} + <INPUT NAME="newProblemSeed" VALUE = "$newProblemSeed" SIZE = "10"> + \end{rawhtml}!, +qq! <INPUT NAME="newProblemSeed" VALUE = "$newProblemSeed" SIZE = "10">! +) +\} + +$HR +END_TEXT +##################################################################### + + +# Make a new match list +$ml = new_match_list(); + +# $ml now "contains" the match list object. (Actually $ml is a scalar variable which contains a pointer to +# the match list object, but you can think of the match list object as being shoe horned into the variable $ml. +# You need to remember that $ml contains (a pointer to) an object, and not ordinary data such as a number or string. + +# Some people use the convention $o_ml to remind them that the variable contains an object, but for short problems +# that is probably not necessary. + +# An object contains both data (in this case the list of questions and answers) and subroutines (called methods) +# for manipulating that data. + + +# Insert some questions and matching answers in the q/a list by calling on the objects qa method. +# using the construction $ml ->qa(..list of alternating questions and matching answers ...). +# Think of this as asking the object $ml to store the matching questions +# and answers given in the argument to the method qa. + +$ml -> qa ( +"\( \sin(x) \)", # Notice the use of the LateX construction for math mode: \\( ... \\) +"\( \cos(x) \)", # and the use of TeX symbols such as \\sin and \\tan +"\( \cos(x) \)", # Use " ... " to enter a string +"\( -\sin(x) \)", +"\( \tan(x) \)", +"\( \sec^2(x) \)" # Remember that in these strings we are only specifying typography, + # via TeX, not any calculational rules. +); + +# +# Calculate coefficients for another question +$b=random(2,5); +$exp= random(2,5); +$coeff=$b*$exp; +$new_exp = $exp-1; + +# Store the question and answers in the match list object. +$ml -> qa ( +"\( ${b}x^$exp \)", +"\( ${coeff}x^{$new_exp} \)", +); + +# Add another example +$b2=random(2,5); +$exp2= random(2,5); +$coeff2=$b2*$exp; +$new_exp2 = $exp-1; +$ml -> qa ( +"\( ${b2}x^$exp2 \)", +"\( ${coeff2}x^{$new_exp2} \)", +); + + +# Choose two of the question and answer pairs at random. +$ml ->choose(2); # Using choose(3) would choose all three questions, but the order of the questions and answers would be + # scrambled. + + +# Now print the text using $ml->print_q for the questions and $ml->print_a to print the answers. + +BEGIN_TEXT +$PAR + +Match the functions and their derivatives: $BR + +\{ $ml -> print_q \} + +$PAR + +\{$ml -> print_a \} +END_TEXT + +# Enter the correct answers to be checked against the answers to the students. + +ANS( str_cmp( $ml->ra_correct_ans ) ) ; + +# That's it. + +######################################################### + +BEGIN_TEXT +<hr> + +You can view the +\{ htmlLink(alias("${htmlDirectory}/links/set$setNumber/prob3.html"),"source", q!TARGET="source"!)\} +for this problem. +END_TEXT + +TEXT( +"$PAR Return to ", htmlLink($$inputs_ref{returnPage},$$inputs_ref{returnPage}), +) if exists($$inputs_ref{returnPage}); +######################################################### + + + +ENDDOCUMENT(); # This should be the last executable line in the problem. +#</PRE> +#</BODY> +#</HTML> --- /dev/null +++ courses/modelCourse/templates/setMAAtutorial/simple_drawing.pg @@ -0,0 +1,40 @@ +##DESCRIPTION +## A very simple drawing problem +##ENDDESCRIPTION + +##KEYWORDS('algebra') + +DOCUMENT(); # This should be the first executable line in the problem. + +loadMacros( +"PG.pl", +"PGbasicmacros.pl", +"PGchoicemacros.pl", +"PGanswermacros.pl", +"PGgraphmacros.pl", +"PGauxiliaryFunctions.pl" +); + + +$graph = init_graph(-5,-5,5,5,ticks=>[4,4],axes=>[0,0],pixels=>[400,400]); + +$graph->moveTo(-2,1); +$graph->lineTo(2,2,'blue'); +$graph->lineTo(-1,2,'red'); +$graph->lineTo(-2,1,'green'); +$graph->fillRegion([0,1.7,'yellow']); +BEGIN_TEXT +\{image(insertGraph($graph),width=>400,height=>400)\} + + +END_TEXT + +# At the moment there is no easy way to change the weight of the lines being drawn. To do so one would want +# to incorporate some of the code in Fun.pm into WWPlot.pm itself. The code involves gdBrushed. +# Since GD has +# gone through many revisions since the WWPlot.pm code was written it may now be possible to write some of +# this code more efficiently. + + + +ENDDOCUMENT(); # This should be the last executable line in the problem. --- /dev/null +++ courses/modelCourse/templates/setMAAtutorial/conditionalquestionexample.pg @@ -0,0 +1,83 @@ +DOCUMENT(); +loadMacros( + "PGbasicmacros.pl", + "PGchoicemacros.pl", + "PGanswermacros.pl" +); +TEXT(beginproblem(), $BR,$BBOLD, "Conditional questions example", $EBOLD, $BR,$BR); +$showPartialCorrectAnswers = 1; + +$a1 = random(3,25,1); +$b1 = random(2,27,1); +$x1 = random(-11,11,1); +$a2 = $a1+5; + +BEGIN_TEXT +If \( f(x) = $a1 x + $b1 \), find \( f'( $x1 ) \). +$BR $BR \{NAMED_ANS_RULE('first_answer',10) \} +$BR +END_TEXT + + + +$ans_eval1 = num_cmp($a1); +NAMED_ANS(first_answer => $ans_eval1); + +# Using named answers allows for more control. Any unique label can be +# used for an answer. +# (see http://webwork.math.rochester.edu/docs/docs/pglanguage/pgreference/managinganswers.html +# for more details on answer evaluator formats and on naming answers +# so that you can refer to them later. Look also at the pod documentation in +# PG.pl and PGbasicmacros.pl which you can also reach at +# http://webwork.math.rochester.edu/docs/techdescription/pglanguage/index.html) + +# Check to see that the first answer was answered correctly. If it was then we +# will ask further questions. +$first_Answer = $inputs_ref->{first_answer}; # We need to know what the answer + ... [truncated message content] |