Difference between revisions of "DoubleIntegral1"

From WeBWorK_wiki
Jump to navigation Jump to search
m
Line 309: Line 309:
   
 
[[Category:Top]]
 
[[Category:Top]]
[[Category:Authors]]
+
[[Category:Sample Problems]]
  +
[[Category:Subject Area Templates]]

Revision as of 17:34, 3 January 2012

Setting up a Double Integral

Click to enlarge

This PG code shows how to allow students to set up a double integral and integrate in either order.

  • Download file: File:DoubleIntegral1.txt (change the file extension from txt to pg when you save it)
  • File location in NPL: FortLewis/Authoring/Templates/IntegralCalcMV/DoubleIntegral1.pg


Templates by Subject Area

PG problem file Explanation

Problem tagging data

Problem tagging:

DOCUMENT();        

loadMacros(
"PGstandard.pl",
"MathObjects.pl",
"parserMultiAnswer.pl",
);

TEXT(beginproblem());

Initialization: Since there are multiple answer blanks that are dependent upon each other, we use parserMultiAnswer.pl.

Context("Numeric");
Context()->variables->are(
x=>"Real",dx=>"Real",
y=>"Real",dy=>"Real");
Context()->flags->set(reduceConstants=>0);

#
#  limits of integration
#
$a = random(1,5,1);
$b = $a + random(1,4,1);
do { $c = random(1,5,1); } until ($c != $a);
do { $d = $c + random(1,4,1); } until ($d != $b);

#
#  integrand and volume
#
$f = Formula("x*y");
$V = Formula("($b^2-$a^2) * ($d^2-$c^2) / 4");


#
#  differentials and limits of integration
#
#  Case 0, element 0 of each array below, is 
#  if the order of integration is dx dy
#
#  Case 1, element 1 of each array below, is
#  if the order of integration is dy dx
# 
#  "id" and "od" stand for inner and outer differential
#
@id = (Formula("dx"),Formula("dy"));  # (case 0, case 1)
@od = (Formula("dy"),Formula("dx"));  # (case 0, case 1)
#
#  A = outer integral, lower limit
#  B = outer integral, upper limit
#  C = inner integral, lower limit
#  D = inner integral, upper limit
#
@A = (Formula("$c"),Formula("$a")); # (case 0, case 1)
@B = (Formula("$d"),Formula("$b")); # (case 0, case 1)
@C = (Formula("$a"),Formula("$c")); # (case 0, case 1)
@D = (Formula("$b"),Formula("$d")); # (case 0, case 1)


$multians = MultiAnswer( $f, $id[0], $od[0], $A[0], $B[0], $C[0], $D[0] )->with(
    singleResult => 1,
    checker => sub {
        my ( $correct, $student, $self ) = @_;
        my ( $fstu, $idstu, $odstu, $Astu, $Bstu, $Cstu, $Dstu ) = @{$student};
        if ( 
             ( 
             $f      == $fstu &&
             $id[0]  == $idstu && 
             $od[0]  == $odstu &&
             $A[0] == $Astu &&
             $B[0] == $Bstu &&
             $C[0] == $Cstu &&
             $D[0] == $Dstu  
             )
             ||
             (
             $f      == $fstu &&
             $id[1]  == $idstu && 
             $od[1]  == $odstu &&
             $A[1] == $Astu &&
             $B[1] == $Bstu &&
             $C[1] == $Cstu &&
             $D[1] == $Dstu  
             )
           ) {
           return 1;
        } elsif (
             (
             $f      == $fstu &&
             $id[0]  == $idstu && 
             $od[0]  == $odstu &&
             ($A[0] != $Astu || $B[0] != $Bstu) &&
             $C[0] == $Cstu &&
             $D[0] == $Dstu 
             )  
             ||
             (
             $f      == $fstu &&
             $id[1]  == $idstu && 
             $od[1]  == $odstu &&
             ($A[1] != $Astu || $B[1] != $Bstu) &&
             $C[1] == $Cstu &&
             $D[1] == $Dstu 
             )  
             ||
             (
             $f      == $fstu &&
             $id[0]  == $idstu && 
             $od[0]  == $odstu &&
             $A[0] == $Astu &&
             $B[0] == $Bstu &&
             ($C[0] != $Cstu || $D[0] != $Dstu) 
             )  
             ||
             (
             $f      == $fstu &&
             $id[1]  == $idstu && 
             $od[1]  == $odstu &&
             $A[1] == $Astu &&
             $B[1] == $Bstu &&
             ($C[1] != $Cstu || $D[1] != $Dstu) 
             )  
           ) {
           $self->setMessage(1,"Check your limits of integration.");
           return 0.94;
        } elsif (
             (
             $f      == $fstu &&
             $id[0]  == $idstu && 
             $od[0]  == $odstu &&
             ($A[0] != $Astu || $B[0] != $Bstu) &&
             ($C[0] != $Cstu || $D[0] != $Dstu)   
             )  
             ||
             (
             $f      == $fstu &&
             $id[1]  == $idstu && 
             $od[1]  == $odstu &&
             ($A[1] != $Astu || $B[1] != $Bstu) &&
             ($C[1] != $Cstu || $D[1] != $Dstu)   
             )  
           ) {
           $self->setMessage(1,
           "Check your limits of integration and order of integration.");
           return 0.47;
        } else {
             return 0;
        }
    }
);

Setup: There are two separate cases: integrating with respect to dx dy (which we call case 0) or with respect to dy dx (which we call case 1). The zeroth and first entries in each of the arrays @id, @od, @A, @B, @C, @D hold the values for case 0 and case 1, respectively. We used constant limits of integration to keep this example easy to follow, but we encourage you to write questions over non-rectangular regions.

The $multians object has been compartmentalized, so you shouldn't need to change it unless you want to fiddle with the weighted score for each answer blank (by changing the return values). The return values are set so that the percentages come out nicely.

Context()->texStrings;
BEGIN_TEXT
Set up a double integral in rectangular coordinates
for calculating the volume of the solid under the 
graph of the function \( f(x,y) = $f \) over the 
region \( $a \leq x \leq $b \) and \( $c \leq y \leq $d \).
$BR
$BR
${BITALIC}Instructions:${EITALIC}
Please enter the integrand in the first answer box. 
Depending on the order of integration you choose,  
enter ${BITALIC}dx${EITALIC} and ${BITALIC}dy${EITALIC} 
in either order into the second and third answer boxes 
with only one ${BITALIC}dx${EITALIC} or 
${BITALIC}dy${EITALIC} in each box.  Then, enter the limits of 
integration and evaluate the integral to find the volume. 
$BR
$BR
\( \displaystyle \int_A^B \int_C^D \) 
\{ $multians->ans_rule(40) \}
\{ $multians->ans_rule(5) \}
\{ $multians->ans_rule(5) \}
$BR
$BR
A = \{ $multians->ans_rule(20) \} $BR
B = \{ $multians->ans_rule(20) \} $BR
C = \{ $multians->ans_rule(20) \} $BR
D = \{ $multians->ans_rule(20) \}
$BR
$BR
Volume = \{ ans_rule(40) \}
END_TEXT
Context()->normalStrings;

Main Text: The only interesting thing to note here is that you must use $multians->ans_rule(20) to make each answer blank known to the object $multians.

$showPartialCorrectAnswers = 1;

ANS( $multians->cmp() );
ANS( $V->cmp() );

Answer Evaluation:

Context()->texStrings;
BEGIN_SOLUTION
${PAR}SOLUTION:${PAR}
Solution explanation goes here.
END_SOLUTION
Context()->normalStrings;


COMMENT('MathObject version.  Allows integration in either order.');
ENDDOCUMENT();

Solution:

Templates by Subject Area