[rochester] / trunk / rochester_problib / setSampleGraphs / prob4.pg Repository:
ViewVC logotype

View of /trunk/rochester_problib/setSampleGraphs/prob4.pg

Parent Directory Parent Directory | Revision Log Revision Log


Revision 823 - (download) (annotate)
Mon May 16 02:27:31 2005 UTC (8 years, 1 month ago) by gage
File size: 5072 byte(s)
Cleaned up &beginproblem  and &ANS old style function reference.

    1 #Description
    2 # Tests the ability to recognize the graphs created by
    3 # translation and stretching transformations.
    4 #EndDescription
    5 DOCUMENT();
    6 loadMacros("PG.pl",
    7            "PGbasicmacros.pl",
    8            "PGchoicemacros.pl",
    9            "PGanswermacros.pl",
   10            "PGgraphmacros.pl",
   11            "PGnumericalmacros.pl"
   12            );
   13 
   14 
   15 
   16 
   17 
   18 
   19 # allow the student to change the seed for this problem.
   20 $newProblemSeed = ( defined( ${$inputs_ref}{'newProblemSeed'} ) )?  ${$inputs_ref}{'newProblemSeed'} : $problemSeed;
   21 $PG_random_generator->srand($newProblemSeed);
   22 
   23 
   24 TEXT(beginproblem());
   25 
   26 @questStr = (
   27 "\( F(x+3)\) ",
   28 "\(F(x-3) \)" ,
   29 "\( -F(-x)\) ",
   30 "\( F(-x) \)",
   31 "\( 5F(x) \)",
   32 "\( F(3x) \)" ,
   33 "\( F(x/3) \)",
   34 "\( F(x^2) \)",
   35 );
   36 
   37 # create a graph to hold a function
   38 ### <A HREF="/webwork_system_html/docs/techdescription/pglanguage/graphtutorial.html">Tutorial for creating on the fly graphics</A>
   39 $graph = init_graph(-5,-5,5,5,'axes'=>[0,0],'grid'=>[8,8]);
   40 my (@x_values1, @y_values1);
   41 foreach $i (0..8) {
   42   $x_values1[$i] =$i-4;
   43   $y_values1[$i] = random(-4,4,1);
   44 }
   45 
   46 ### <A HREF="/webwork_system_html/cgi-bin/system/pod2webwork.pl%3Fpath%3D/webwork/system/courseScripts/PGgraphmacros.pl%26up%3D/webwork_system_html/docs/techdescription/pglanguage/index.html">More details on graphics commands under "Graphs"</A>
   47 $fun_rule = plot_list(~~@x_values1, ~~@y_values1);
   48 $f1=new Fun($fun_rule, $graph); #new function is to be plotted in graph
   49 $f1->color('black');
   50 
   51 $fun_rule2 = sub{ my $x = shift; &$fun_rule($x-1)  };
   52 $f2 = new Fun($fun_rule2, $graph);  # adds a new function to the graph which is a translate of the first
   53 $f2->color('orange');
   54 $f2->domain(-1,4);
   55 $graph->stamps(open_circle(-1,&$fun_rule2(-1),'orange') ); # indicate open interval at the left endpoint
   56 $graph->stamps(closed_circle(4,&$fun_rule2(4), 'orange') ); # and a closed interval at the right endpoint
   57 
   58 # make sure that the browser will fetch the new picture when it is created by changing the name of the
   59 # graph each time the problem seed is changed.
   60 $graph->gifName($graph->gifName()."-$newProblemSeed");
   61 
   62 
   63 
   64 $graph2 = init_graph(-5,-5,5,5,'axes'=>[0,0],'grid'=>[4,4]);
   65 $b1= random(-5,5,1);
   66 $b2= random(-5,5,1);
   67 $b3= random(-5,5,1);
   68 @x_val3 = (-4,-3,-2,-1,  0,   1,   2,  3, 4 );
   69 @y_val3 = ( 0, 1, 2, 0,$b1, $b2,  $b3,  1, 2 );
   70 @yp_val3= ( 0, 1, 0,-2,  0,    1,  2, -3, 1 );
   71 $spline_rule = hermite_spline(~~@x_val3,   # x values
   72                               ~~@y_val3,   # y values
   73                               ~~@yp_val3   # y prime values
   74                          );
   75 
   76 $f3 = new Fun($spline_rule, $graph2);
   77 $f3->color('green');
   78 $graph2->stamps(closed_circle(-4, &$spline_rule(-4), 'green') ) ;
   79 $graph2->stamps(closed_circle( 4, &$spline_rule( 4), 'green') ) ;
   80 
   81 # Insert the graph and the text.
   82 ###<A HREF="/webwork_system_html/cgi-bin/system/pod2webwork.pl%3Fpath%3D/webwork/system/courseScripts/PGgraphmacros.pl%26up%3D/webwork_system_html/docs/techdescription/pglanguage/index.html">A description of "insertGraph" and other graphics commands</A>
   83 
   84 BEGIN_TEXT
   85 
   86 To see a different version of the problem change
   87 the problem seed and press the 'Submit Answer' button below.$PAR Problem Seed:
   88 \{  M3(
   89 qq! Change the problem seed to change the problem:$problemSeed!,
   90 qq! Change the problem seed to change the problem:
   91     \begin{rawhtml}
   92     <INPUT NAME="newProblemSeed" VALUE = "$newProblemSeed" SIZE = "10">
   93     \end{rawhtml}!,
   94 qq! <INPUT NAME="newProblemSeed" VALUE = "$newProblemSeed" SIZE = "10">!
   95 )
   96 \}
   97 $PAR
   98 We are developing other ways to specify graphs which are to be created 'on the fly'.
   99 All of these new methods consist of adding macro packages to WeBWorK.  Since they
  100 do not require the core of WeBWorK to be changed, these enhancements can be added by
  101 anyone using WeBWorK.
  102 $PAR
  103  These two piecewise linear graphs were created by specifying the points at the nodes.
  104  $BR Click on the graph to view a larger image.
  105 $PAR
  106 \{ image(insertGraph($graph) ) \}
  107 $PAR
  108 This graph was created using a hermite spline by specifying points at
  109 
  110 \{ begintable(1+scalar( @x_val3 ) ) \}
  111 \{ row('x', @x_val3)\}
  112 \{ row('y', @y_val3) \}
  113 \{ row('yp',@yp_val3) \}
  114 \{endtable() \}
  115 
  116 $PAR
  117 \{image(insertGraph($graph2)) \}
  118 
  119 $PAR
  120 The macro packages which allow creating graphs in this fashion are still be refined --
  121 particularly the error messages.  The numerical calculations were all written in Perl using
  122 numerical routines adapted from the Numerical Analysis book by Burden and Faires.
  123 $BR
  124 We are also working on a macro which will automatically
  125 identify the maximum, minimum and inflection points of an arbitary hermite
  126 cubic spline from its specifying values.  This will allow automatic generation
  127 of  problems in which the maximum, minimum and inflection points are to be
  128 deduced from a graph.
  129 
  130 $PAR
  131 You can view the \{ htmlLink(alias("prob4.html"),"source", q!TARGET="source"!)\} for this problem.
  132 or consult the \{ htmlLink("/webwork_system_html/docs/techdescription/pglanguage/index.html","documentation") \}  for  more details on the PG language.
  133 
  134 END_TEXT
  135 
  136 
  137 &ENDDOCUMENT;

aubreyja at gmail dot com
ViewVC Help
Powered by ViewVC 1.0.9