Difference between revisions of "ProvingTrigIdentities3"

From WeBWorK_wiki
Jump to navigation Jump to search
(Quick save)
Line 44: Line 44:
 
"PGstandard.pl",
 
"PGstandard.pl",
 
"MathObjects.pl",
 
"MathObjects.pl",
  +
"PGML.pl",
  +
"scaffold.pl",
  +
"PGcourse.pl",
 
);
 
);
   
Line 53: Line 56:
 
<td style="background-color:#ddffdd;padding:7px;">
 
<td style="background-color:#ddffdd;padding:7px;">
 
<p>
 
<p>
<b>Initialization:</b>
+
<b>Initialization:</b> Load the <code>scaffold.pl</code> macro.
 
</p>
 
</p>
 
</td>
 
</td>
Line 64: Line 67:
 
<td style="background-color:#ffffdd;border:black 1px dashed;">
 
<td style="background-color:#ffffdd;border:black 1px dashed;">
 
<pre>
 
<pre>
  +
Context("Numeric")->variables->are(t=>"Real");
  +
 
Context("Numeric")->variables->are(t=>"Real");
 
Context("Numeric")->variables->are(t=>"Real");
   
Line 79: Line 84:
 
}
 
}
 
package main;
 
package main;
# Make it work on formulas as well as numbers
 
#sub cos {Parser::Function->call('cos',@_)} # if uncommented, this line will generate error messages
 
 
# Add the new functions to the Context
 
# Add the new functions to the Context
 
Context()->functions->add( sin => {class => 'NewFunc', TeX => '\sin'}, );
 
Context()->functions->add( sin => {class => 'NewFunc', TeX => '\sin'}, );
 
 
#
 
# You manually define the answers
 
#
 
@answers = ();
 
$answers[1] = Formula("1-cos(t)");
 
$answers[2] = Formula("sin(t)");
 
$answers[3] = Formula("1-(cos(t))^2");
 
 
 
#
 
# Automatic configuration for answer evaluation
 
#
 
@ans_eval = ();
 
@scores = ();
 
foreach my $i (1..$#answers) {
 
$ans_eval[$i] = $answers[$i] ->cmp();
 
$ans_hash[$i] = $ans_eval[$i]->evaluate($inputs_ref->{ANS_NUM_TO_NAME($i)});
 
$scores[$i] = $ans_hash[$i]->{score};
 
}
 
 
</pre>
 
</pre>
 
</td>
 
</td>
 
<td style="background-color:#ffffcc;padding:7px;">
 
<td style="background-color:#ffffcc;padding:7px;">
 
<p>
 
<p>
<b>Setup:</b>
 
  +
<b>Setup:</b> We cleverly redefine the sine function so that when the student enters <code>sin(t)</code>, it is interpreted and evaluated internally as <code>exp(pi*t)</code> but displayed to the student as <code>sin(t)</code>.
 
</p>
 
</p>
 
</td>
 
</td>
Line 117: Line 99:
 
<td style="background-color:#ffdddd;border:black 1px dashed;">
 
<td style="background-color:#ffdddd;border:black 1px dashed;">
 
<pre>
 
<pre>
Context()->texStrings;
 
  +
BEGIN_PGML
BEGIN_TEXT
 
  +
This problem has three parts. A part may be open if it is correct or if it is the first incorrect part.
${BBOLD}Part 1 of 3:${EBOLD}
 
  +
Clicking on the heading for a part toggles whether it is displayed.
$BR
 
  +
END_PGML
$BR
 
  +
  +
Scaffold::Begin(is_open => "correct_or_first_incorrect");
  +
  +
Section::Begin("Part 1");
  +
BEGIN_PGML
 
In this multi-part problem, we will use algebra to verify
 
In this multi-part problem, we will use algebra to verify
 
the identity
 
the identity
$BCENTER
 
  +
>> [` \displaystyle \frac{ \sin(t) }{ 1-\cos(t) } = \frac{ 1+\cos(t) }{ \sin(t) }. `] <<
\( \displaystyle \frac{ \sin(t) }{ 1-\cos(t) } = \frac{ 1+\cos(t) }{ \sin(t) }. \)
 
  +
$ECENTER
 
$BR
 
 
First, using algebra we may rewrite the equation above as
 
First, using algebra we may rewrite the equation above as
$BR
 
  +
[` \displaystyle \sin(t) = \left( \frac{1+\cos(t)}{\sin(t)} \right) \cdot \Big( `] [_____________]{"1-cos(t)"} [` \Big) `].
$BR
 
  +
END_PGML
\( \displaystyle \sin(t) = \left( \frac{1+\cos(t)}{\sin(t)} \right) \cdot \Big( \)
 
  +
Section::End();
\{ ans_rule(20) \}
 
  +
\( \Big) \)
 
  +
Section::Begin("Part 2");
END_TEXT
 
  +
BEGIN_PGML
Context()->normalStrings;
 
  +
Using algebra we may rewrite the equation as
  +
[` \sin(t) \cdot \big( `] [______________]{"sin(t)"} [` \big) = \big(1+\cos(t)\big) \cdot \big(1-\cos(t)\big) `].
  +
END_PGML
  +
Section::End();
   
ANS( $ans_eval[1] );
 
  +
Section::Begin("Part 3");
  +
BEGIN_PGML
  +
Finally, using algebra we may rewrite the equation as
  +
[` \sin^2(t) = `] [_______________]{"1-(cos(t))^2"}, which is true since
  +
[` \cos^2(t) + \sin^2(t) = 1 .`] Thus, the original identity can be derived by reversing these steps.
  +
END_PGML
  +
Section::End();
  +
  +
Scaffold::End();
 
</pre>
 
</pre>
 
<td style="background-color:#ffcccc;padding:7px;">
 
<td style="background-color:#ffcccc;padding:7px;">
 
<p>
 
<p>
<b>Main Text and Answer Evaluation Part 1:</b>
 
  +
<b>Main Text:</b> This is where we use the scaffold.
 
</p>
 
</p>
 
</td>
 
</td>
 
</tr>
 
</tr>
   
 
<tr valign="top">
 
<td style="background-color:#eeddff;border:black 1px dashed;">
 
<pre>
 
if ($scores[1]==1) {
 
 
Context()->texStrings;
 
BEGIN_TEXT
 
$PAR
 
$HR
 
${BBOLD}Part 2 of 3:${EBOLD}
 
$BR
 
$BR
 
Then, using algebra we may rewrite the equation as
 
$BR
 
$BR
 
\( \sin(t) \cdot \big( \)
 
\{ ans_rule(20) \}
 
\( \big) = \big(1+\cos(t)\big) \cdot \big(1-\cos(t)\big) \),
 
END_TEXT
 
Context()->normalStrings;
 
 
ANS( $ans_eval[2] );
 
 
} # end if
 
</pre>
 
<td style="background-color:#eeccff;padding:7px;">
 
<p>
 
<b>Main Text and Answer Evaluation Part 2:</b>
 
</p>
 
</td>
 
</tr>
 
   
 
<!-- Solution section -->
 
<!-- Solution section -->
Line 184: Line 147:
 
<td style="background-color:#ddddff;border:black 1px dashed;">
 
<td style="background-color:#ddddff;border:black 1px dashed;">
 
<pre>
 
<pre>
if ( ($scores[1]==1) && ($scores[2]==1) ) {
 
 
Context()->texStrings;
 
BEGIN_TEXT
 
$PAR
 
$HR
 
${BBOLD}Part 3 of 3:${EBOLD}
 
$BR
 
$BR
 
Finally, using algebra we may rewrite the equation as
 
$BR
 
$BR
 
\( \sin^2(t) = \)
 
\{ ans_rule(20) \}
 
$BR
 
$BR
 
which is true since \( \cos^2(t) + \sin^2(t) = 1 \).
 
Thus, the original identity can be derived
 
by reversing these steps.
 
END_TEXT
 
Context()->normalStrings;
 
 
ANS( $ans_eval[3] );
 
 
} # end if
 
 
 
 
COMMENT("MathObject version. This is a multi-part problem
 
COMMENT("MathObject version. This is a multi-part problem
 
in which the next part is revealed only after the previous
 
in which the next part is revealed only after the previous
 
part is correct. Prevents students from entering trivial
 
part is correct. Prevents students from entering trivial
identities (entering what they were given)");
+
identities (entering what they were given). Uses PGML.");
   
 
ENDDOCUMENT();
 
ENDDOCUMENT();
Line 220: Line 156:
 
<td style="background-color:#ddddff;padding:7px;">
 
<td style="background-color:#ddddff;padding:7px;">
 
<p>
 
<p>
<b>Main Text and Answer Evaluation Part 3:</b>
 
  +
<b>Comment section:</b>
 
</p>
 
</p>
 
</td>
 
</td>

Revision as of 17:49, 13 June 2015

Proving Trig Identities

Click to enlarge

This PG code shows how to write a multi-part question in which each new part is revealed only after the previous part is answered correctly. The parts are revealed sequentially on the same html page instead of each part having its own html page. We also cleverly redefine the sine function to require students to simplify their answers when applying well-known trig identities.

  • File location in OPL: []


Templates by Subject Area

PG problem file Explanation

Problem tagging data

Problem tagging:

DOCUMENT();

loadMacros(
"PGstandard.pl",
"MathObjects.pl",
"PGML.pl",
"scaffold.pl",
"PGcourse.pl",
);

TEXT(beginproblem());

$showPartialCorrectAnswers = 1;

Initialization: Load the scaffold.pl macro.

Context("Numeric")->variables->are(t=>"Real");

Context("Numeric")->variables->are(t=>"Real");

#
#  Redefine the sin(x) to be e^(pi x)
#
Context()->functions->remove("sin");
package NewFunc;
# this next line makes the function a 
# function from reals to reals
our @ISA = qw(Parser::Function::numeric);
sub sin {
  shift; my $x = shift;
  return CORE::exp($x*3.1415926535);
}
package main;
#  Add the new functions to the Context
Context()->functions->add( sin => {class => 'NewFunc', TeX => '\sin'}, );

Setup: We cleverly redefine the sine function so that when the student enters sin(t), it is interpreted and evaluated internally as exp(pi*t) but displayed to the student as sin(t).

BEGIN_PGML
This problem has three parts.  A part may be open if it is correct or if it is the first incorrect part.
Clicking on the heading for a part toggles whether it is displayed.
END_PGML

Scaffold::Begin(is_open  => "correct_or_first_incorrect");
    
Section::Begin("Part 1");
BEGIN_PGML
In this multi-part problem, we will use algebra to verify 
the identity
>> [` \displaystyle \frac{ \sin(t) }{ 1-\cos(t) } = \frac{ 1+\cos(t) }{ \sin(t) }. `] <<

First, using algebra we may rewrite the equation above as
[` \displaystyle \sin(t) = \left( \frac{1+\cos(t)}{\sin(t)} \right) \cdot \Big( `] [_____________]{"1-cos(t)"} [` \Big) `].
END_PGML
Section::End();
    
Section::Begin("Part 2");
BEGIN_PGML
Using algebra we may rewrite the equation as
[` \sin(t) \cdot \big( `] [______________]{"sin(t)"} [` \big) = \big(1+\cos(t)\big) \cdot \big(1-\cos(t)\big) `].
END_PGML
Section::End();

Section::Begin("Part 3");
BEGIN_PGML
Finally, using algebra we may rewrite the equation as
[` \sin^2(t) = `] [_______________]{"1-(cos(t))^2"}, which is true since
[` \cos^2(t) + \sin^2(t) = 1 .`] Thus, the original identity can be derived by reversing these steps.
END_PGML
Section::End();
  
Scaffold::End();

Main Text: This is where we use the scaffold.

COMMENT("MathObject version.  This is a multi-part problem 
in which the next part is revealed only after the previous 
part is correct.  Prevents students from entering trivial 
identities (entering what they were given).  Uses PGML.");

ENDDOCUMENT();

Comment section:

Templates by Subject Area