Difference between revisions of "HeavisideStep1"
Line 66: | Line 66: | ||
<td style="background-color:#ffffdd;border:black 1px dashed;"> |
<td style="background-color:#ffffdd;border:black 1px dashed;"> |
||
<pre> |
<pre> |
||
+ | $ftex = "5 u(t-3)"; |
||
+ | |||
Context("Numeric"); |
Context("Numeric"); |
||
Context()->variables->are(t=>"Real"); |
Context()->variables->are(t=>"Real"); |
||
Line 75: | Line 77: | ||
); |
); |
||
− | parserFunction("u(t)" => "1.5*sin(e*t)+2*pi/e"); |
||
$f = Formula("5*step(t-3)"); |
$f = Formula("5*step(t-3)"); |
||
− | $g = Formula("5*u(t-3)"); |
||
$answer1 = List($f->eval(t=>2),$f->eval(t=>3),$f->eval(t=>4)); |
$answer1 = List($f->eval(t=>2),$f->eval(t=>3),$f->eval(t=>4)); |
||
− | $answer2 = $g; |
||
</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 1:</b> |
We add the (Legacy) step function to the context with the name <code>step</code>. The function <code>step(t)</code> takes the value 1 when t > 0, and the value 0 when t ≤ 0. Using <code>parserFunction.pl</code>, we add another function named <code>u(x)</code> to the context. The reason for adding these two functions to the context is that |
We add the (Legacy) step function to the context with the name <code>step</code>. The function <code>step(t)</code> takes the value 1 when t > 0, and the value 0 when t ≤ 0. Using <code>parserFunction.pl</code>, we add another function named <code>u(x)</code> to the context. The reason for adding these two functions to the context is that |
||
Line 97: | Line 96: | ||
<p> |
<p> |
||
Notice that the function <code>u(t)</code> is never zero, is not constant, is differentiable, and takes moderately sized values, which makes its answer checking very robust. Also, notice that the formula for <code>u(t)</code> is not something students are likely to input as an answer out of nowhere. The function <code>u(t)</code> is great as a named function that stands in for the Heaviside function when the answer is a function. However, if the answer is a number obtained by evaluating the Heaviside function, then <code>step(t)</code> should be used instead of <code>u(t)</code> for obvious reasons. |
Notice that the function <code>u(t)</code> is never zero, is not constant, is differentiable, and takes moderately sized values, which makes its answer checking very robust. Also, notice that the formula for <code>u(t)</code> is not something students are likely to input as an answer out of nowhere. The function <code>u(t)</code> is great as a named function that stands in for the Heaviside function when the answer is a function. However, if the answer is a number obtained by evaluating the Heaviside function, then <code>step(t)</code> should be used instead of <code>u(t)</code> for obvious reasons. |
||
+ | </p> |
||
+ | <p> |
||
+ | Note: Currently, functions that are added to the context do not work with <code>test_points</code>, but they do work with changes to the domain <code>limits=>[a,b]</code> and the number of points <code>num_points=>c</code> set using Context flags. |
||
</p> |
</p> |
||
</td> |
</td> |
||
Line 121: | Line 123: | ||
$BR |
$BR |
||
$BR |
$BR |
||
− | (a) Evaluate the function \( $ |
+ | (a) Evaluate the function \( $ftex \) when |
\( t \) is 2, 3, and 4 and enter your answer |
\( t \) is 2, 3, and 4 and enter your answer |
||
as a comma separated list. |
as a comma separated list. |
||
Line 127: | Line 129: | ||
\{ ans_rule(20) \} |
\{ ans_rule(20) \} |
||
\{ AnswerFormatHelp("numbers") \} |
\{ AnswerFormatHelp("numbers") \} |
||
+ | END_TEXT |
||
+ | Context()->normalStrings; |
||
+ | </pre> |
||
+ | <td style="background-color:#ffcccc;padding:7px;"> |
||
+ | <p> |
||
+ | <b>Main Text 1:</b> |
||
+ | </p> |
||
+ | </td> |
||
+ | </tr> |
||
+ | |||
+ | <!-- Answer evaluation section --> |
||
+ | |||
+ | <tr valign="top"> |
||
+ | <td style="background-color:#eeddff;border:black 1px dashed;"> |
||
+ | <pre> |
||
+ | $showPartialCorrectAnswers=1; |
||
+ | |||
+ | ANS( $answer1->cmp(ordered=>1) ); |
||
+ | </pre> |
||
+ | <td style="background-color:#eeccff;padding:7px;"> |
||
+ | <p> |
||
+ | <b>Answer Evaluation 1:</b> |
||
+ | </p> |
||
+ | </td> |
||
+ | </tr> |
||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | <!-- Setup section --> |
||
+ | |||
+ | <tr valign="top"> |
||
+ | <td style="background-color:#ffffdd;border:black 1px dashed;"> |
||
+ | <pre> |
||
+ | Context("Numeric"); |
||
+ | Context()->variables->are(t=>"Real"); |
||
+ | Context()->flags->set( |
||
+ | limits=>[-5,5], |
||
+ | num_points=>10, |
||
+ | ); |
||
+ | parserFunction("u(t)" => "1.5*sin(e*t)+2*pi/e"); |
||
+ | |||
+ | |||
+ | $answer2 = Formula("5 u(t-3)"); |
||
+ | </pre> |
||
+ | </td> |
||
+ | <td style="background-color:#ffffcc;padding:7px;"> |
||
+ | <p> |
||
+ | <b>Setup 2:</b> |
||
+ | We add the (Legacy) step function to the context with the name <code>step</code>. The function <code>step(t)</code> takes the value 1 when t > 0, and the value 0 when t ≤ 0. Using <code>parserFunction.pl</code>, we add another function named <code>u(x)</code> to the context. The reason for adding these two functions to the context is that |
||
+ | |||
+ | * <code>step</code>, which is the Heaviside function, will be used when the answer is a number |
||
+ | * <code>u</code> will be used when the answer is a function |
||
+ | </p> |
||
+ | <p> |
||
+ | Since answers are checked numerically by comparing the student answer to the correct answer at several points in the domain (the default is 5 points) in an interval (the default is [-1,1]), the function <code>step</code> is not very robust when checking answers. For example, if a student types in the answer <code>step(t-0.1)</code> and the correct answer is <code>step(t)</code>, there is a good chance that the student's answer will be marked correct, since the probability that a test point was chosen in the interval <code>(0,0.1)</code> is much less than 100%. Also, if the correct answer were <code>step(t-5)</code>, then a student could enter the answer <code>0</code> and be marked correct because the correct answer is identically zero on the interval <code>[-1,1]</code>. |
||
+ | </p> |
||
+ | <p> |
||
+ | Notice that the function <code>u(t)</code> is never zero, is not constant, is differentiable, and takes moderately sized values, which makes its answer checking very robust. Also, notice that the formula for <code>u(t)</code> is not something students are likely to input as an answer out of nowhere. The function <code>u(t)</code> is great as a named function that stands in for the Heaviside function when the answer is a function. However, if the answer is a number obtained by evaluating the Heaviside function, then <code>step(t)</code> should be used instead of <code>u(t)</code> for obvious reasons. |
||
+ | </p> |
||
+ | <p> |
||
+ | Note: Currently, functions that are added to the context do not work with <code>test_points</code>, but they do work with changes to the domain <code>limits=>[a,b]</code> and the number of points <code>num_points=>c</code> set using Context flags. |
||
+ | </p> |
||
+ | </td> |
||
+ | </tr> |
||
+ | |||
+ | <!-- Main text section --> |
||
+ | |||
+ | <tr valign="top"> |
||
+ | <td style="background-color:#ffdddd;border:black 1px dashed;"> |
||
+ | <pre> |
||
+ | Context()->texStrings; |
||
+ | BEGIN_TEXT |
||
$BR |
$BR |
||
$BR |
$BR |
||
− | (b) Enter the function \( $ |
+ | (b) Enter the function \( $ftex \). |
$BR |
$BR |
||
\{ ans_rule(20) \} |
\{ ans_rule(20) \} |
||
Line 138: | Line 214: | ||
<td style="background-color:#ffcccc;padding:7px;"> |
<td style="background-color:#ffcccc;padding:7px;"> |
||
<p> |
<p> |
||
− | <b>Main Text:</b> |
+ | <b>Main Text 2:</b> |
</p> |
</p> |
||
</td> |
</td> |
||
Line 148: | Line 224: | ||
<td style="background-color:#eeddff;border:black 1px dashed;"> |
<td style="background-color:#eeddff;border:black 1px dashed;"> |
||
<pre> |
<pre> |
||
− | $showPartialCorrectAnswers=1; |
||
− | |||
− | ANS( $answer1->cmp(ordered=>1) ); |
||
− | |||
ANS( $answer2->cmp() ); |
ANS( $answer2->cmp() ); |
||
</pre> |
</pre> |
||
<td style="background-color:#eeccff;padding:7px;"> |
<td style="background-color:#eeccff;padding:7px;"> |
||
<p> |
<p> |
||
− | <b>Answer Evaluation:</b> |
+ | <b>Answer Evaluation 2:</b> |
</p> |
</p> |
||
</td> |
</td> |
||
</tr> |
</tr> |
||
+ | |||
+ | |||
+ | |||
<!-- Solution section --> |
<!-- Solution section --> |
Revision as of 02:25, 6 December 2010
Using the Heaviside Step Function
This PG code shows how to add a the Heaviside step function step(x)
, which takes the value 1 if x > 0, and the value 0 if x ≤ 0, to the context. It also shows how to add a named function u(x)
to the context that has a reliable answer checker and can stand in for the Heaviside step function when the student answer is a function.
- Download file: File:HeavisideStep1.txt (change the file extension from txt to pg when you save it)
- File location in NPL:
FortLewis/Authoring/Templates/DiffEq/HeavisideStep1.pg
PG problem file | Explanation |
---|---|
Problem tagging: |
|
DOCUMENT(); loadMacros( "PGstandard.pl", "MathObjects.pl", "AnswerFormatHelp.pl", "parserFunction.pl", ); TEXT(beginproblem()); |
Initialization:
We load |
$ftex = "5 u(t-3)"; Context("Numeric"); Context()->variables->are(t=>"Real"); Context()->functions->add( step => { class => 'Parser::Legacy::Numeric', perl => 'Parser::Legacy::Numeric::do_step' }, ); $f = Formula("5*step(t-3)"); $answer1 = List($f->eval(t=>2),$f->eval(t=>3),$f->eval(t=>4)); |
Setup 1:
We add the (Legacy) step function to the context with the name
Since answers are checked numerically by comparing the student answer to the correct answer at several points in the domain (the default is 5 points) in an interval (the default is [-1,1]), the function
Notice that the function
Note: Currently, functions that are added to the context do not work with |
Context()->texStrings; BEGIN_TEXT Let \( u(t) \) be the Heaviside step function defined by \( \displaystyle u(t) = \left\lbrace \begin{array}{lcl} 0 && \mbox{ if } x > 0, \\ 1 && \mbox{ if } x \leq 0. \end{array} \right. \) $BR $BR (a) Evaluate the function \( $ftex \) when \( t \) is 2, 3, and 4 and enter your answer as a comma separated list. $BR \{ ans_rule(20) \} \{ AnswerFormatHelp("numbers") \} END_TEXT Context()->normalStrings; |
Main Text 1: |
$showPartialCorrectAnswers=1; ANS( $answer1->cmp(ordered=>1) ); |
Answer Evaluation 1: |
Context("Numeric"); Context()->variables->are(t=>"Real"); Context()->flags->set( limits=>[-5,5], num_points=>10, ); parserFunction("u(t)" => "1.5*sin(e*t)+2*pi/e"); $answer2 = Formula("5 u(t-3)"); |
Setup 2:
We add the (Legacy) step function to the context with the name
Since answers are checked numerically by comparing the student answer to the correct answer at several points in the domain (the default is 5 points) in an interval (the default is [-1,1]), the function
Notice that the function
Note: Currently, functions that are added to the context do not work with |
Context()->texStrings; BEGIN_TEXT $BR $BR (b) Enter the function \( $ftex \). $BR \{ ans_rule(20) \} \{ AnswerFormatHelp("formulas") \} END_TEXT Context()->normalStrings; |
Main Text 2: |
ANS( $answer2->cmp() ); |
Answer Evaluation 2: |
Context()->texStrings; BEGIN_SOLUTION ${PAR}SOLUTION:${PAR} Solution explanation goes here. END_SOLUTION Context()->normalStrings; COMMENT('MathObject version.'); ENDDOCUMENT(); |
Solution: |