#Description #KEYWORDS('derivatives', 'graphs') # Identify the graphs of the function and the derivative #EndDescription &DOCUMENT; loadMacros("PG.pl", "PGbasicmacros.pl", "PGchoicemacros.pl", "PGanswermacros.pl", "PGgraphmacros.pl"); $a=random(0, 6.3, .1); $b=random(1.1, 1.5, .1); $dom = 4; @slice = NchooseK(3,3); @colors = ("blue", "red", "green"); @sc = @colors[@slice]; #scrambled colors @sa = ('A','B','C')[@slice]; # define the functions and their derivatives. # FEQ (Format EQuations) cleans up the writing of the functions (see FEQ in PGbasicmacros) # Otherwise we would need to worry about the signs of $a, $b and so forth. $f = FEQ("sin($a+$b*cos(x)) for x in <-$dom,$dom> using color:$sc[0] and weight:2"); $fp = FEQ("cos($a+$b*cos(x))*(-$b)*sin(x) for x in <-$dom,$dom> using color=$sc[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=$sc[2] and weight=2"); $graph = init_graph(-4,-4,4,4,'axes'=>[0,0],'grid'=>[8,8]); ($fRef,$fpRef,$fppRef) = plot_functions( $graph, $f,$fp,$fpp ); # create labels $label_point=-0.75; $label_f = new Label ( $label_point,&{$fRef->rule}($label_point),$sa[0],"$sc[0]",'left') ; # NOTE: $fRef->rule is 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),$sa[1],"$sc[1]",'left') ; $label_fpp = new Label ( $label_point,&{$fppRef->rule}($label_point),$sa[2],"$sc[2]",'left'); # insert the labels into the graph $graph->lb($label_f,$label_fp,$label_fpp); $showPartialCorrectAnswers =0; TEXT(beginproblem()); TEXT(image(insertGraph($graph))); TEXT(EV2(qq! 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 !)); ANS(str_cmp( [@sa] ) ); BEGIN_TEXT $PAR You can view the \{ htmlLink(alias("prob8.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 &ENDDOCUMENT;