WeBWorKdocs

sq_webwork:


Home
Current UR
courses
Visitor
page
Intro to
WeBWorK
WeBWorK 2
Twiki
WW
Community
Grant Support
& awards
Discussion
group
Problem
library
Write/modify
problems
Create &
manage course
Tutorial on
running a course
HowTos
FAQ
WeBWorK2
FAQ
Software
Download
How to
Install WW server
Feedback
Site Map
Change
preferences
Change
password





Prev | Next | tutorial

This page is no longer being maintained. The new URL for this content is http://webwork.maa.org/wiki/DynamicImages

The on-the-fly graphics example

To obtain this problem
(1 pt) rochesterLibrary/setMAAtutorial/ontheflygraphicsexample1.pg

On-the-fly Graphics Example1

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):

is the graph of the function

is the graph of the function's first derivative

is the graph of the function's second derivative


WARNINGS
µ¦å{h­

{viewSource(setMAAtutorial/ontheflygraphicsexample1.pg)}



Comments:

  1. 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).
  2. We define a function and it's first and second derivatives on the domain [-4,4]
    We need to mix up the colors assigned to each function, since it won't do us any good if every student's function is colored blue, their first derivative red, and their second derivative green.
    Create a scrambled list of colors and letters. Here are the basic colors @colors = ("blue", "red", "green"); Slice will contain the numbers 1,2,3 in some permuted order @slice = NchooseK(3,3); The slice of the color list (sc) contains the colors in a new order defined by the ordering in @slice. This construction @array[@slice] is the way to apply a permutation to a list. @sc = @colors[@slice]; Now we scramble the letters labeling the graphs using the same permutation. These list will contain the correct answers in the proper order. @sa = ('A','B','C')[@slice];
  3. $f = FEQ("sin($a+$b*cos(x)) for x in <-$dom,$dom> using color:$sc[0] and weight:2");

    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 @sc and using a weight (width) of two pixels."

    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.

  4. 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. See Fun.pm for more details.

  5. Create labels for each function The 'left' tag determines the justification of the label to the defining point.
    Place the second letter in the permuted letter list at the point (-.75, fp(-.75)) using the second color in the permuted color list.
  6. The construction \{ image(insertGraph($graph)) \} inserts the graph at this point in the text.


Prev | Next | tutorial

Last update: Monday, March 3, 2008 at 7:14:47 PM.
This site maintained using Manila and Frontier software.