Parent Directory
|
Revision Log
214 new Differential Equations questions added to NPL
1 ## DESCRIPTION 2 ## Higher order ODEs: constant coefficient second order homogeneous linear ODEs 3 ## ENDDESCRIPTION 4 5 ## KEYWORDS('differential equations','second order linear ODE','constant coefficients') 6 7 ## DBsubject('Differential Equations') 8 ## DBchapter('Higher Order Differential Equations') 9 ## DBsection('Second Order Linear') 10 ## Date('01/30/2011') 11 ## Author('Paul Pearson') 12 ## Institution('Fort Lewis College') 13 ## TitleText1('Notes on Diffy Qs') 14 ## EditionText1('December 9, 2010') 15 ## AuthorText1('Jiri Lebl') 16 ## Section1('2.2') 17 ## Problem1('11') 18 19 20 ############################## 21 # Initialization 22 23 DOCUMENT(); 24 25 loadMacros( 26 "PGstandard.pl", 27 "MathObjects.pl", 28 "AnswerFormatHelp.pl", 29 "parserAssignment.pl", 30 ); 31 32 TEXT(beginproblem()); 33 34 35 ############################# 36 # Setup 37 38 Context("Numeric"); 39 Context()->variables->add( 40 A=>"Real",B=>"Real",y=>"Real", 41 ); 42 Context()->flags->set( 43 formatStudentAnswer=>'parsed', 44 reduceConstants=>0, 45 reduceConstantFunctions=>0, 46 ); 47 parser::Assignment->Allow; 48 49 $a = random(2,5,1); 50 $aa = $a**2; 51 $a2 = 2*$a; 52 do { $b = random(2,5,1); } until ($b != $a); 53 $bb = $b**2; 54 $c = $aa + $bb; 55 56 $s = random(-1,1,2); 57 $msa = -($s) * $a; 58 59 # char poly (r + $s $a)^2 + $b^2 60 61 if ($s==1) { 62 $diffeq = "y'' + $a2 y' + $c y = 0"; # tex 63 } else { 64 $diffeq = "y'' - $a2 y' + $c y = 0"; # tex 65 } 66 67 68 $answer = Compute("y = A e^($msa x) cos($b x) + B e^($msa x) sin($b x)"); 69 70 71 ###################### 72 # Main text 73 74 Context()->texStrings; 75 BEGIN_TEXT 76 Find the general solution to \( $diffeq \). 77 In your answer, use \( A \) and \( B \) to 78 denote arbitrary constants and \( x \) 79 the independent variable. 80 $BR 81 $BR 82 \{ ans_rule(40) \} 83 \{ AnswerFormatHelp("equations") \} 84 END_TEXT 85 Context()->normalStrings; 86 87 88 ###################### 89 # Answer evaluation 90 91 $showPartialCorrectAnswers = 1; 92 ANS( $answer->cmp( checker => sub { 93 my ( $correct, $student, $self ) = @_; 94 my $stu = Formula($student->{tree}{rop}); 95 96 ################################ 97 # Check for arbitrary constants 98 # 99 Value->Error("Is your answer the most general solution?") 100 if ( 101 Formula($stu->D('A'))==Formula(0) || 102 Formula($stu->D('B'))==Formula(0) 103 ); 104 105 ############################################ 106 # Check for linear independence (Wronskian) 107 # 108 my $x = Real(1.24); 109 110 my $a11 = $stu->eval(A=>1,B=>0,x=>$x,y=>0); 111 my $a12 = $stu->eval(A=>0,B=>1,x=>$x,y=>0); 112 113 my $a21 = $stu->D('x')->eval(A=>1,B=>0,x=>$x,y=>0); 114 my $a22 = $stu->D('x')->eval(A=>0,B=>1,x=>$x,y=>0); 115 116 my $wronskian = $a11*$a22 - $a21*$a12; 117 118 Value->Error("Your functions are not linearly independent or your answer is not complete") 119 if ($wronskian==Real(0)); 120 121 ######################################################## 122 # Check that the student answer is a solution to the DE 123 # 124 my $stux = Formula($stu->D('x')); 125 my $stuxx = Formula($stu->D('x','x')); 126 my $stuDE = Formula($stuxx + $s*$a2*$stux + $c*$stu) 127 ->with(test_points=>[[1,1,0.1,0],[2,1,0,0],[1,2,-0.1,0],[1,1,0,1]]); 128 129 return ($stuDE==Formula(0)); 130 131 })); 132 133 134 COMMENT("MathObject version."); 135 136 ENDDOCUMENT();
| aubreyja at gmail dot com | ViewVC Help |
| Powered by ViewVC 1.0.9 |