Zig's
code works great for both numerical and string answers. I was blindly
trying to modify it to work with functions. I have included the pg
source (below) along with the error message. Note that the backslashes
have been removed by the posting program.
After fussing about, it is clear that the offending line is line 56
56 ($ans_eval1) = function_cmp($function1);
which means the answer evaluator returned by function_cmp is different
than that of num_cmp and str_cmp. I have stared at PGanswermacros.pl
long enough to know I haven't a clue how to fix this.
If there are suggestiongs out there, I would appreciate hearing.
Thanks,
Tom
Problem4
ERROR caught by PGtranslator while processing problem file:setf01Ch18S1/problem_4.pg
*
Not a CODE reference at (eval 49) line 57.
*
------Input Read
1 ## -*- perl -*- ##
2 ## Line above puts emacs in perl mode
3 ##
4 ## Description
5 ## Second Order Constant Coefficient ODE (distinct real roots)
6 ## EndDescription
7
8 DOCUMENT();
9 loadMacros(PG.pl,
10 PGbasicmacros.pl,
11 PGchoicemacros.pl,
12 PGanswermacros.pl,
13 PGauxiliaryFunctions.pl,
14 PGgraphmacros.pl,
15 "Dartmouthmacros.pl");
16
17
18 ## Do NOT show partial correct answers
19 $showPartialCorrectAnswers = 0;
20
21
22 $root1 = non_zero_random(-10,10);
23 $root2 = $root1 + random(1,5);
24 ## If $root2 is zero, then $root1 < 0
25 if ($root2 == 0) {$root2 = random(1,10);}
26 $function1 = "exp($root1*x)";
27 $function2 = "exp($root2*x)";
28
29 ## Ok, we are ready to begin the problem...
30 ##
31 TEXT(beginproblem());
32
33
34 BEGIN_TEXT
35 $BR
36 Find the general solution to the homogeneous
differential equation
37 [
38 frac{d^2y}{dx^2} - {$root1 + $root2}frac{dy}{dx} + {$root1 * $root2}y = 0
39 ]
40 $BR
41 The solution has the form
42 [y = C_1 f_1(x) + C_2 f_2(x)]
43 with
44 (f_1(x) = )
{NAMED_ANS_RULE(first_fcn,25)}
45 and (f_2(x) =) {NAMED_ANS_RULE(second_fcn,25)}
46 $BR
47
48 Left to your own devices, you will probably write down the correct
49 answers, but in case you want to quibble, enter your answers so that
50 (f_1, f_2) are normalized with their value at (x = 0) equal to
51 1.
52
53 $PAR
54 END_TEXT
55
56 ($ans_eval1) = function_cmp($function1);
57 $firstAnswer = $inputs_ref->{first_fcn};
58 $firstAnswer = '' unless defined($firstAnswer);
59
60 $rh_ans_hash = &$ans_eval1($firstAnswer);
61
62 if ( $rh_ans_hash->{score} == 1 )
63 {
64 NAMED_ANS( first_fcn, fun_cmp($function1) );
65 NAMED_ANS( second_fcn, fun_cmp($function2) );
66 }
67 else
68 {
69 NAMED_ANS( second_fcn, fun_cmp($function2) );
70 NAMED_ANS( first_fcn, fun_cmp($function1) );
71 }
72
73 ENDDOCUMENT();
<| Post or View Comments |>
|