WeBWorK Main Forum

Understanding quotes and decimal approximations

Re: Understanding quotes and decimal approximations

by Thomas Hoft -
Number of replies: 0

Alex, 

This also fixed the numerical issue that led me down this rabbit hole!

Thanks! - Thomas

DOCUMENT();     
loadMacros("PGstandard.pl", "PGML.pl", "PGcourse.pl");
Context("Numeric");
Context()->variables->are(k1=>"Real", k2=>"Real", t=>"Real");
Context()->flags->set(reduceConstants => 0, reduceConstantFunctions => 0);
$y1 = Compute("e^(-4t)");
$y2 = Compute("e^(-2t)");
$yp = Compute("7/85 cos(t) + 6/85 sin(t)");
$y_gen = Compute("k1 $y1 + k2 $y2 + $yp");
$const_1 = Formula("2/17"); # k1
$const_2 = Formula("-1/5"); # k2
$y_spec = $y_gen->substitute(k1=>$const_1, k2=>$const_2); 
$y_spec->{test_points} = [ [1,1,0.005] ];
$y_gen->cmp(diagnostics=>1, 
checker => sub {
  my ($correct, $student, $ansHash) = @_;
  if ( ( ($student->substitute(k1=>1, k2=>0) == $y1 + $yp) || # one of terms is y1
         ($student->substitute(k1=>0, k2=>1) == $y1 + $yp) ) && 
       ( ($student->substitute(k1=>1, k2=>0) == $y2 + $yp) || # one of terms is y2
         ($student->substitute(k1=>0, k2=>1) == $y2 + $yp) ) #&& 
     ) 
  { return 1; } else { return 0; } 
}
);
BEGIN_PGML
(a) Find the general solution of the differential equation
[`\displaystyle \frac{d^2y}{dt^2} + 6 \frac{dy}{dt} + 8 y = \cos{t}. `]
[`y(t) = `] [______________________________________________________]{$y_gen}
Use "k1" and "k2" for the constants in your solution.
(b) Find the solution of the initial-value problem 
[`\displaystyle \frac{d^2y}{dt^2} + 6 \frac{dy}{dt} + 8 y = \cos{t}, \quad y(0)=y'(0)=0. `]
[`y(t) = `] [_______________________________________________________]{$y_spec}
END_PGML ENDDOCUMENT();        


Attachment wwDE.png