Difference between revisions of "HeavisideStep1"
(add historical tag and give links to newer problems.) |
|||
(7 intermediate revisions by 3 users not shown) | |||
Line 1: | Line 1: | ||
+ | {{historical}} |
||
+ | |||
+ | <p style="font-size: 120%;font-weight:bold">This problem has been replaced with [https://openwebwork.github.io/pg-docs/sample-problems/DiffEq/HeavisideStep.html a newer version of this problem]</p> |
||
+ | |||
<h2>Using the Heaviside Step Function</h2> |
<h2>Using the Heaviside Step Function</h2> |
||
Line 5: | Line 9: | ||
This PG code shows how to add a the Heaviside step function <code>step(x)</code>, 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 <code>u(x)</code> 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. |
This PG code shows how to add a the Heaviside step function <code>step(x)</code>, 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 <code>u(x)</code> 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. |
||
</p> |
</p> |
||
− | * Download file: [[File:HeavisideStep1.txt]] (change the file extension from txt to pg when you save it) |
||
+ | * File location in OPL: [https://github.com/openwebwork/webwork-open-problem-library/blob/master/OpenProblemLibrary/FortLewis/Authoring/Templates/DiffEq/HeavisideStep1.pg FortLewis/Authoring/Templates/DiffEq/HeavisideStep1.pg] |
||
− | * File location in NPL: <code>FortLewis/Authoring/Templates/DiffEq/HeavisideStep1.pg</code> |
||
+ | * PGML location in OPL: [https://github.com/openwebwork/webwork-open-problem-library/blob/master/OpenProblemLibrary/FortLewis/Authoring/Templates/DiffEq/HeavisideStep1_PGML.pg FortLewis/Authoring/Templates/DiffEq/HeavisideStep1_PGML.pg] |
||
<br clear="all" /> |
<br clear="all" /> |
||
Line 56: | Line 60: | ||
<b>Initialization:</b> |
<b>Initialization:</b> |
||
We load <code>parserFunction.pl</code> to make adding a named function to the context easier. |
We load <code>parserFunction.pl</code> to make adding a named function to the context easier. |
||
+ | Please see the POD documentation [http://webwork.maa.org/pod/pg/macros/parserFunction.html parserFunction.pl]. |
||
</p> |
</p> |
||
</td> |
</td> |
||
Line 170: | Line 175: | ||
$answer2 = $f->with( |
$answer2 = $f->with( |
||
limits=>[$a-5,$a+5], |
limits=>[$a-5,$a+5], |
||
− | test_at => [[$a-1],[$a |
+ | test_at => [[$a-1],[$a],[$a+0.0000001],[$a+1]], |
num_points=>10, |
num_points=>10, |
||
); |
); |
||
Line 192: | Line 197: | ||
In part (b), since the students never actually see the values of the function <code>u(t)</code>, we could have defined the function as |
In part (b), since the students never actually see the values of the function <code>u(t)</code>, we could have defined the function as |
||
<pre> |
<pre> |
||
− | parserFunction("u(t)" = |
+ | parserFunction("u(t)" => |
"1.5 * sin(e*t) + 5*pi/3 + arctan(t)" |
"1.5 * sin(e*t) + 5*pi/3 + arctan(t)" |
||
); |
); |
||
Line 248: | Line 253: | ||
Context()->texStrings; |
Context()->texStrings; |
||
BEGIN_SOLUTION |
BEGIN_SOLUTION |
||
− | ${PAR}SOLUTION:${PAR} |
||
Solution explanation goes here. |
Solution explanation goes here. |
||
END_SOLUTION |
END_SOLUTION |
||
Line 271: | Line 275: | ||
[[Category:Top]] |
[[Category:Top]] |
||
− | [[Category: |
+ | [[Category:Sample Problems]] |
+ | [[Category:Subject Area Templates]] |
Latest revision as of 05:27, 18 July 2023
This problem has been replaced with a newer version of this problem
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.
- File location in OPL: FortLewis/Authoring/Templates/DiffEq/HeavisideStep1.pg
- PGML location in OPL: FortLewis/Authoring/Templates/DiffEq/HeavisideStep1_PGML.pg
PG problem file | Explanation |
---|---|
Problem tagging: |
|
DOCUMENT(); loadMacros( "PGstandard.pl", "MathObjects.pl", "AnswerFormatHelp.pl", "parserFunction.pl", ); TEXT(beginproblem()); |
Initialization:
We load |
Context("Numeric"); Context()->variables->are(t=>"Real"); Context()->functions->add( step => { class => 'Parser::Legacy::Numeric', perl => 'Parser::Legacy::Numeric::do_step' }, ); $a = 3; $ftex = "5 u(t-$a)"; $fstep = Formula("5*step(t-$a)"); $answer1 = List($fstep->eval(t=>2),$fstep->eval(t=>3),$fstep->eval(t=>4)); |
Setup 1:
We add the step function to the context with the name For more details on adding the Heaviside function to the context, see the forum discussion on the Heaviside step function |
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 \leq 0, \\ 1 && \mbox{ if } x > 0. \end{array} \right. \) $BR $BR (a) Evaluate the function \( $ftex \) when \( t \) is \(2\), \(3\), and \(4\) and enter your answers 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()->functions->add( step => { class => 'Parser::Legacy::Numeric', perl => 'Parser::Legacy::Numeric::do_step' }, ); parserFunction("u(t)" => "step(t)"); $f = Formula("5 u(t-$a)"); $answer2 = $f->with( limits=>[$a-5,$a+5], test_at => [[$a-1],[$a],[$a+0.0000001],[$a+1]], num_points=>10, ); |
Setup 2:
We reset the context using
Using a different method for adding functions to the context, we add the named function
Since answers are checked numerically by comparing the student answer to the correct answer at several randomly points in the domain (the default is 5 points) in an interval (the default is [-1,1]), the function
To make the answer checking robust, in
In part (b), since the students never actually see the values of the function parserFunction("u(t)" => "1.5 * sin(e*t) + 5*pi/3 + arctan(t)" ); If we had defined |
Context()->texStrings; BEGIN_TEXT $BR $BR (b) Suppose the answer is 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 Solution explanation goes here. END_SOLUTION Context()->normalStrings; COMMENT('MathObject version.'); ENDDOCUMENT(); |
Solution: |