#Description # Tests the ability to recognize the graphs created by # translation and stretching transformations. #EndDescription DOCUMENT(); loadMacros("PG.pl", "PGbasicmacros.pl", "PGchoicemacros.pl", "PGanswermacros.pl", "PGgraphmacros.pl", "numericalmethods.pl" ); # allow the student to change the seed for this problem. $newProblemSeed = ( defined( ${$inputs_ref}{'newProblemSeed'} ) )? ${$inputs_ref}{'newProblemSeed'} : $problemSeed; $PG_random_generator->srand($newProblemSeed); TEXT(beginproblem()); @questStr = ( "\( F(x+3)\) ", "\(F(x-3) \)" , "\( -F(-x)\) ", "\( F(-x) \)", "\( 5F(x) \)", "\( F(3x) \)" , "\( F(x/3) \)", "\( F(x^2) \)", ); # create a graph to hold a function ### Tutorial for creating on the fly graphics $graph = init_graph(-5,-5,5,5,'axes'=>[0,0],'grid'=>[8,8]); my (@x_values1, @y_values1); foreach $i (0..8) { $x_values1[$i] =$i-4; $y_values1[$i] = random(-4,4,1); } ### More details on graphics commands under "Graphs" $fun_rule = plot_list(~~@x_values1, ~~@y_values1); $f1=new Fun($fun_rule, $graph); #new function is to be plotted in graph $f1->color('black'); $fun_rule2 = sub{ my $x = shift; &$fun_rule($x-1) }; $f2 = new Fun($fun_rule2, $graph); # adds a new function to the graph which is a translate of the first $f2->color('orange'); $f2->domain(-1,4); $graph->stamps(open_circle(-1,&$fun_rule2(-1),'orange') ); # indicate open interval at the left endpoint $graph->stamps(closed_circle(4,&$fun_rule2(4), 'orange') ); # and a closed interval at the right endpoint # 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"); $graph2 = init_graph(-5,-5,5,5,'axes'=>[0,0],'grid'=>[4,4]); $b1= random(-5,5,1); $b2= random(-5,5,1); $b3= random(-5,5,1); @x_val3 = (-4,-3,-2,-1, 0, 1, 2, 3, 4 ); @y_val3 = ( 0, 1, 2, 0,$b1, $b2, $b3, 1, 2 ); @yp_val3= ( 0, 1, 0,-2, 0, 1, 2, -3, 1 ); $spline_rule = hermite_spline(~~@x_val3, # x values ~~@y_val3, # y values ~~@yp_val3 # y prime values ); $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 graph and the text. ###A description of "insertGraph" and other graphics commands 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} \end{rawhtml}!, qq! ! ) \} $PAR We are developing 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) ) \} $PAR 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 \{image(insertGraph($graph2)) \} $PAR The macro packages which allow creating graphs in this fashion are still be refined -- particularly the error messages. 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. $PAR You can view the \{ htmlLink(alias("prob4.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;