-
-
Notifications
You must be signed in to change notification settings - Fork 436
Expand file tree
/
Copy pathflygraph.pg
More file actions
82 lines (70 loc) · 2.3 KB
/
Copy pathflygraph.pg
File metadata and controls
82 lines (70 loc) · 2.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
## DESCRIPTION
## WeBWorK Demo
## ENDDESCRIPTION
## KEYWORDS('demo')
## Tagged by jjh2b
## DBsubject('WeBWorK')
## DBchapter('Demos')
## DBsection('Problem')
## Date('')
## Author('')
## Institution('')
## TitleText1('')
## EditionText1('')
## AuthorText1('')
## Section1('')
## Problem1('')
DOCUMENT();
loadMacros(
"PGstandard.pl",
"PGchoicemacros.pl",
"PGgraphmacros.pl",
"PGcourse.pl"
);
$showPartialCorrectAnswers =0;
TEXT(beginproblem());
# Define the graph
$graph = init_graph(-4,-4,4,4,'axes'=>[0,0],'grid'=>[8,8]);
# create a scrambled list of colors and letters.
@colors = ("blue", "red", "green");
@slice = NchooseK(3,3);
@sc = @colors[@slice]; #scrambled colors
@sa = ('A','B','C')[@slice];
# Now we are ready to write the strings which define the function
$dom = 4;
$a=random(0, 6.3, .1);
$b=random(1.1, 1.5, .1);
$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");
# Install the functions into the graph object.
($fRef,$fpRef,$fppRef) = plot_functions( $graph,
$f,$fp,$fpp
);
# create labels for each function
$label_point=-0.75;
$label_f = new Label ( $label_point, &{$fRef->rule}($label_point),
$sa[0],$sc[0],'left');
$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);
# This inserts the graph and then asks three questions:
BEGIN_TEXT
\{ image(insertGraph($graph),
alt=>"Three curves labeled A (blue), B (red), and C (green) showing a function and its first and second derivatives on the same coordinate plane."
) \} $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( [@sa] ) );
&ENDDOCUMENT;