[npl] / trunk / NationalProblemLibrary / Dartmouth / setStewartCh18S1 / problem_4.pg Repository:
ViewVC logotype

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 269 - (download) (annotate)
Sat Jun 3 14:39:59 2006 UTC (7 years ago) by gage
File size: 2686 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();
   21 loadMacros("PG.pl",
   22            "PGbasicmacros.pl",
   23            "PGchoicemacros.pl",
   24            "PGanswermacros.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*x)";
   51 $function2 = "exp($root2*x)";
   52 
   53 ## Ok, we are ready to begin the problem...
   54 ##
   55 TEXT(beginproblem());
   56 
   57 
   58 BEGIN_TEXT
   59 Find the general solution to the homogeneous differential equation
   60 \[
   61     \frac{d^2y}{dx^2} - \{$root1 + $root2\}\frac{dy}{dx} + \{$root1 * $root2\}y = 0
   62 \]
   63 $BR
   64 The solution has the form
   65 \[y = C_1 f_1(x) + C_2 f_2(x)\]
   66 with
   67 \(f_1(x) = \) \{NAMED_ANS_RULE(first_fcn,25)\}
   68 and \(f_2(x) =\) \{NAMED_ANS_RULE(second_fcn,25)\}
   69 $BR
   70 
   71 Left to your own devices, you will probably write down the correct
   72 answers, but in case you want to quibble, enter your answers so that
   73 \(f_1, f_2\) are normalized with their value at \(x = 0\) equal to
   74 1.
   75 END_TEXT
   76 
   77 ($ans_eval1) = num_cmp(exp($root1)); ## Value of $function1 at x = 1
   78 $firstAnswer = $inputs_ref->{first_fcn};  ## Grab the first answer entered by student
   79 $firstAnswer = '' unless defined($firstAnswer);  ## Make sure it is defined
   80 $firstAnswer =~ s/x/(1)/g;  ## Globally substitute (1) for x in $firstAnswer
   81 $rh_ans_hash = &calleval($ans_eval1,$firstAnswer);  ## Check first answer against given
   82 
   83 if ( $rh_ans_hash->{score} == 1 )
   84 {
   85     NAMED_ANS(first_fcn, fun_cmp($function1),vars=>['x'] );
   86     NAMED_ANS(second_fcn, fun_cmp($function2),vars=>['x'] );
   87 }
   88 else
   89 {
   90     NAMED_ANS(first_fcn, fun_cmp($function2),vars=>['x'] );
   91     NAMED_ANS(second_fcn, fun_cmp($function1),vars=>['x'] );
   92 }
   93 
   94 ENDDOCUMENT();
   95 
   96 
   97 
   98 

aubreyja at gmail dot com
ViewVC Help
Powered by ViewVC 1.0.9