TrigFunctionsDegrees1: Difference between revisions
No edit summary |
(Modified to show the use of the TrigDegrees context.) |
||
Line 1: | Line 1: | ||
<h2> | <h2>Trigonometric Functions in Degrees</h2> | ||
[[File: | [[File:TrigDegrees.png|300px|thumb|right|Click to enlarge]] | ||
<p style="background-color:#f9f9f9;border:black solid 1px;padding:3px;"> | <p style="background-color:#f9f9f9;border:black solid 1px;padding:3px;"> | ||
This PG code shows how to redefine trigonometric functions so they evaluate in degrees rather than radians. | This PG code shows how to use the context TrigDegrees to redefine trigonometric functions so they evaluate in degrees rather than radians. | ||
</p> | </p> | ||
* File location in OPL: [https://github.com/openwebwork/webwork-open-problem-library/ | * File location in OPL: path to come <!--[https://github.com/openwebwork/webwork-open-problem-library/FIXPATH...TrigDegrees.pg TrigDegrees.pg] --> | ||
* PGML file location in OPL: path to come <!--[https://github.com/openwebwork/webwork-open-problem-library/FIXPATHtopgml...TrigDegreesPGML.pg TrigDegrees.pg] --> | |||
<br clear="all" /> | <br clear="all" /> | ||
Line 42: | Line 42: | ||
loadMacros( | loadMacros( | ||
"PGstandard.pl", | "PGstandard.pl", | ||
"MathObjects.pl", | "MathObjects.pl", | ||
"AnswerFormatHelp.pl", | "AnswerFormatHelp.pl", | ||
"contextTrigDegrees.pl", | |||
"PGcourse.pl", | |||
); | ); | ||
Line 53: | Line 55: | ||
<p> | <p> | ||
<b>Initialization:</b> | <b>Initialization:</b> | ||
We need to use MathObjects answer evaluators. | We need to use MathObjects answer evaluators and to load the contextTrigDegrees macro. | ||
</p> | </p> | ||
</td> | </td> | ||
Line 63: | Line 65: | ||
<td style="background-color:#ffffdd;border:black 1px dashed;"> | <td style="background-color:#ffffdd;border:black 1px dashed;"> | ||
<pre> | <pre> | ||
Context(" | Context("TrigDegrees"); | ||
$ans1 = Compute("sin(30)"); | |||
$ans2 = Compute("arcsin(0.5)"); | |||
</pre> | </pre> | ||
Line 264: | Line 75: | ||
<p> | <p> | ||
<b>Setup:</b> | <b>Setup:</b> | ||
WeBWorK | To override the WeBWorK default of evaluating trig functions in radians, use the TrigDegrees context, which redefines the standard trig functions to be in degrees, both in any formulas that appear later in the PG code and in any formulas that students | ||
in any formulas that appear later in the PG code and in any formulas that students | |||
enter in answer blanks. | enter in answer blanks. | ||
</p> | </p> | ||
<p> | <p> | ||
These redefined functions allow students to enter inverse functions using syntax such as | These redefined functions allow students to enter inverse functions using syntax such as | ||
<code>atan(x)</code> | <code>atan(x)</code>, or <code>arctan(x)</code>, or <code>tan^(-1)(x)</code>. | ||
You may want to | You may want to mention the syntax options in the main text section of the problem. | ||
</p> | </p> | ||
</td> | </td> | ||
Line 293: | Line 100: | ||
\{ ans_rule(20) \} | \{ ans_rule(20) \} | ||
\{ AnswerFormatHelp("formulas") \} | \{ AnswerFormatHelp("formulas") \} | ||
$ | $PAR | ||
Remark: Enter \( \arcsin(x) \) as arcsin(x), or | |||
asin(x), or sin^(-1)(x). | |||
END_TEXT | END_TEXT | ||
Context()->normalStrings; | Context()->normalStrings; | ||
Line 314: | Line 121: | ||
$showPartialCorrectAnswers = 1; | $showPartialCorrectAnswers = 1; | ||
ANS( | ANS( $ans1->cmp() ); | ||
ANS( | ANS( $ans2->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:</b> | ||
The answers are 0.5 and 30 (computed in degrees in the Setup section). | |||
</p> | </p> | ||
</td> | </td> | ||
Line 339: | Line 146: | ||
Context()->normalStrings; | Context()->normalStrings; | ||
COMMENT(" | COMMENT("Redefines trig functions to be in degrees (not radians)."); | ||
ENDDOCUMENT(); | ENDDOCUMENT(); | ||
Line 345: | Line 152: | ||
<td style="background-color:#ddddff;padding:7px;"> | <td style="background-color:#ddddff;padding:7px;"> | ||
<p> | <p> | ||
<b>Solution:</b> | <b>Solution:</b> Before ENDDOCUMENT, we should include a comment that warns other instructors that trig functions are in degrees instead of radians. | ||
</p> | </p> | ||
</td> | </td> |
Revision as of 20:28, 22 July 2021
Trigonometric Functions in Degrees

This PG code shows how to use the context TrigDegrees to redefine trigonometric functions so they evaluate in degrees rather than radians.
- File location in OPL: path to come
- PGML file location in OPL: path to come
PG problem file | Explanation |
---|---|
Problem tagging: |
|
DOCUMENT(); loadMacros( "PGstandard.pl", "MathObjects.pl", "AnswerFormatHelp.pl", "contextTrigDegrees.pl", "PGcourse.pl", ); TEXT(beginproblem()); |
Initialization: We need to use MathObjects answer evaluators and to load the contextTrigDegrees macro. |
Context("TrigDegrees"); $ans1 = Compute("sin(30)"); $ans2 = Compute("arcsin(0.5)"); |
Setup: To override the WeBWorK default of evaluating trig functions in radians, use the TrigDegrees context, which redefines the standard trig functions to be in degrees, both in any formulas that appear later in the PG code and in any formulas that students enter in answer blanks.
These redefined functions allow students to enter inverse functions using syntax such as
|
Context()->texStrings; BEGIN_TEXT Enter \( \sin(30) \): \{ ans_rule(20) \} \{ AnswerFormatHelp("formulas") \} $BR Enter \( \arcsin(1/2) \): \{ ans_rule(20) \} \{ AnswerFormatHelp("formulas") \} $PAR Remark: Enter \( \arcsin(x) \) as arcsin(x), or asin(x), or sin^(-1)(x). END_TEXT Context()->normalStrings; |
Main Text: The problem text section of the file is as we'd expect. |
$showPartialCorrectAnswers = 1; ANS( $ans1->cmp() ); ANS( $ans2->cmp() ); |
Answer Evaluation: The answers are 0.5 and 30 (computed in degrees in the Setup section). |
Context()->texStrings; BEGIN_SOLUTION ${PAR}SOLUTION:${PAR} Solution explanation goes here. END_SOLUTION Context()->normalStrings; COMMENT("Redefines trig functions to be in degrees (not radians)."); ENDDOCUMENT(); |
Solution: Before ENDDOCUMENT, we should include a comment that warns other instructors that trig functions are in degrees instead of radians. |