[npl] / trunk / NationalProblemLibrary / Dartmouth / setStewartCh18S1 / problem_1.pg Repository: Repository Listing bbplugincoursesdistsnplrochestersystemwww

View of /trunk/NationalProblemLibrary/Dartmouth/setStewartCh18S1/problem_1.pg

Sat Jun 3 14:39:59 2006 UTC (6 years, 11 months ago) by gage
File size: 2780 byte(s)
 Cleaned problem code using convert-functions.pl


    1 ## DESCRIPTION
2 ## Calculus
3 ## ENDDESCRIPTION
4
5 ## KEYWORDS('homogeneous' 'differential equation')
6 ## Tagged by tda2d
7
8 ## DBsubject('Calculus')
9 ## DBchapter('Second-Order Differential Equations')
10 ## DBsection('Second-Order Linear Equations')
11 ## Date('')
12 ## Author('')
13 ## Institution('Dartmouth')
14 ## TitleText1('Calculus')
15 ## EditionText1('5')
16 ## AuthorText1('Stewart')
17 ## Section1('18.1')
18 ## Problem1('')
19
20 DOCUMENT();
22            "PGbasicmacros.pl",
23            "PGchoicemacros.pl",
25            "PGauxiliaryFunctions.pl",
26            );
27
28 ##Hack around evaluation problem
29 sub calleval {
30    my ($ans_evaluator,$student_answer) = @_;
31    my $rh_ans_hash = ""; 32 if ( ref($ans_evaluator) eq 'AnswerEvaluator' ) { # new style
33             $rh_ans_hash =$ans_evaluator->evaluate($student_answer); 34 } elsif (ref($ans_evaluator) eq  'CODE' )     { #old style
35             $rh_ans_hash = &$ans_evaluator($student_answer); 36 } else { 37 warn "There is a problem using the answer evaluator"; 38 } 39 return$rh_ans_hash;
40 }
41
42 ## Do NOT show partial correct answers
43 $showPartialCorrectAnswers = 0; 44 45 46$root1 = non_zero_random(-10,10);
47 $root2 =$root1 + random(1,5);
48 ## If $root2 is zero, then$root1 < 0
49 if ($root2 == 0) {$root2 = random(1,10);}
50 $function1 = "exp($root1*t)";
51 $function2 = "exp($root2*t)";
52
53 ## Ok, we are ready to begin the problem...
54 ##
55 TEXT(beginproblem());
56
57
58 BEGIN_TEXT
59 $BR 60 Find the general solution to the homogeneous differential equation 61 $62 \frac{d^2y}{dt^2} - \{root1 + root2\}\frac{dy}{dt} + \{root1 * root2\}y = 0 63$ 64$BR
65 The solution has the form
66 $y = C_1 f_1(t) + C_2 f_2(t)$
67 with
68 $$f_1(t) =$$ \{NAMED_ANS_RULE(first_fcn,25)\}
69 and $$f_2(t) =$$ \{NAMED_ANS_RULE(second_fcn,25)\}
70 $BR 71 72 Left to your own devices, you will probably write down the correct 73 answers, but in case you want to quibble, enter your answers so that 74 $$f_1, f_2$$ are normalized with their value at $$t = 0$$ equal to 75 1. 76 77$PAR
78 END_TEXT
79
80 ($ans_eval1) = num_cmp(exp($root1));             ## Value of $function1 at t = 1 81$firstAnswer = $inputs_ref->{first_fcn}; ## Grab the first answer entered by student 82$firstAnswer = '' unless defined($firstAnswer); ## Make sure it is defined 83$firstAnswer =~ s/t/(1)/g;                       ## Globally substitute (1) for t in $firstAnswer 84$rh_ans_hash = &calleval($ans_eval1,$firstAnswer);        ## Check first answer against given
85
86
88 if ( $rh_ans_hash->{score} == 1 ) 89 { 90 NAMED_ANS(first_fcn, fun_cmp($function1, vars=>['t']) );
91     NAMED_ANS(second_fcn, fun_cmp($function2, vars=>['t']) ); 92 } 93 else 94 { 95 NAMED_ANS(first_fcn, fun_cmp($function2, vars=>['t']) );