Difference between revisions of "TrigFunctionsDegrees1"

From WeBWorK_wiki
Jump to navigation Jump to search
(12 intermediate revisions by 6 users not shown)
Line 1: Line 1:
<h2>Trig Functions in Degrees</h2>
+
<h2>Trigonometric Functions in Degrees</h2>
   
<p style="background-color:#eeeeee;border:black solid 1px;padding:3px;">
 
  +
[[File:TrigDegrees.png|300px|thumb|right|Click to enlarge]]
This PG code shows how to redefine trigonometric functions so they evaluate in degrees rather than radians.
 
  +
<p style="background-color:#f9f9f9;border:black solid 1px;padding:3px;">
<ul>
 
  +
This PG code shows how to use the context TrigDegrees to redefine trigonometric functions so they evaluate in degrees rather than radians.
<li>Download file: [[File:TrigFunctionsDegrees1.txt]] (change the file extension from txt to pg when you save it)</li>
 
<li>File location in NPL: <code>NationalProblemLibrary/FortLewis/Authoring/Templates/Trig/TrigFunctionsDegrees1.pg</code></li>
 
</ul>
 
 
</p>
 
</p>
  +
* File location in OPL: https://github.com/openwebwork/webwork-open-problem-library/tree/master/Contrib/ChamplainSaintLambert/Titcombe/TrigDegrees.pg <!--[https://github.com/openwebwork/webwork-open-problem-library/FIXPATH...TrigDegrees.pg TrigDegrees.pg] -->
  +
* PGML file location in OPL: https://github.com/openwebwork/webwork-open-problem-library/tree/master/Contrib/ChamplainSaintLambert/Titcombe/TrigDegreesPGML.pg <!--[https://github.com/openwebwork/webwork-open-problem-library/FIXPATHtopgml...TrigDegreesPGML.pg TrigDegrees.pg] -->
   
  +
<br clear="all" />
 
<p style="text-align:center;">
 
<p style="text-align:center;">
 
[[SubjectAreaTemplates|Templates by Subject Area]]
 
[[SubjectAreaTemplates|Templates by Subject Area]]
Line 40: Line 40:
 
<pre>
 
<pre>
 
DOCUMENT();
 
DOCUMENT();
  +
 
loadMacros(
 
loadMacros(
"PGstandard.pl",
+
"PGstandard.pl",
"MathObjects.pl",
+
"MathObjects.pl",
  +
"AnswerFormatHelp.pl",
  +
"contextTrigDegrees.pl",
  +
"PGcourse.pl",
 
);
 
);
  +
 
TEXT(beginproblem());
 
TEXT(beginproblem());
 
</pre>
 
</pre>
Line 50: Line 52:
 
<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 60: Line 62:
 
<td style="background-color:#ffffdd;border:black 1px dashed;">
 
<td style="background-color:#ffffdd;border:black 1px dashed;">
 
<pre>
 
<pre>
Context("Numeric");
+
Context("TrigDegrees");
 
##############################################
 
# Begin trig functions in degrees
 
 
Context()->functions->remove("cos");
 
package NewFunc;
 
# this next line makes the function a
 
# function from reals to reals
 
our @ISA = qw(Parser::Function::numeric);
 
sub cos {
 
shift; my $x = shift;
 
return CORE::cos($x*3.14159265358979/180);
 
}
 
package main;
 
# Make it work on formulas as well as numbers
 
# if uncommented, this next line will generate error messages
 
#sub cos {Parser::Function->call('cos',@_)}
 
# Add the new functions to the Context
 
Context()->functions->add( cos => {class => 'NewFunc', TeX => '\cos'}, );
 
 
 
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::sin($x*3.14159265358979/180);
 
}
 
package main;
 
# Make it work on formulas as well as numbers
 
# if uncommented, this next line will generate error messages
 
#sub sin {Parser::Function->call('sin',@_)}
 
# Add the new functions to the Context
 
Context()->functions->add( sin => {class => 'NewFunc', TeX => '\sin'}, );
 
 
 
Context()->functions->remove("tan");
 
package NewFunc;
 
# this next line makes the function a
 
# function from reals to reals
 
our @ISA = qw(Parser::Function::numeric);
 
sub tan {
 
shift; my $x = shift;
 
return CORE::sin($x*3.14159265358979/180)/CORE::cos($x*3.14159265358979/180);
 
}
 
package main;
 
# Make it work on formulas as well as numbers
 
sub tan {Parser::Function->call('tan',@_)}
 
# Add the new functions to the Context
 
Context()->functions->add( tan => {class => 'NewFunc', TeX => '\tan'}, );
 
 
 
Context()->functions->remove("sec");
 
package NewFunc;
 
# this next line makes the function a
 
# function from reals to reals
 
our @ISA = qw(Parser::Function::numeric);
 
sub sec {
 
shift; my $x = shift;
 
return 1.0/CORE::cos($x*3.14159265358979/180);
 
}
 
package main;
 
# Make it work on formulas as well as numbers
 
sub sec {Parser::Function->call('sec',@_)}
 
# Add the new functions to the Context
 
Context()->functions->add( sec => {class => 'NewFunc', TeX => '\sec'}, );
 
 
 
Context()->functions->remove("csc");
 
package NewFunc;
 
# this next line makes the function a
 
# function from reals to reals
 
our @ISA = qw(Parser::Function::numeric);
 
sub csc {
 
shift; my $x = shift;
 
return 1.0/CORE::sin($x*3.14159265358979/180);
 
}
 
package main;
 
# Make it work on formulas as well as numbers
 
sub csc {Parser::Function->call('csc',@_)}
 
# Add the new functions to the Context
 
Context()->functions->add( csc => {class => 'NewFunc', TeX => '\csc'}, );
 
 
 
Context()->functions->remove("cot");
 
package NewFunc;
 
# this next line makes the function a
 
# function from reals to reals
 
our @ISA = qw(Parser::Function::numeric);
 
sub cot {
 
shift; my $x = shift;
 
return CORE::cos($x*3.14159265358979/180)/CORE::sin($x*3.14159265358979/180);
 
}
 
package main;
 
# Make it work on formulas as well as numbers
 
sub cot {Parser::Function->call('cot',@_)}
 
# Add the new functions to the Context
 
Context()->functions->add( cot => {class => 'NewFunc', TeX => '\cot'}, );
 
 
 
 
#sub asin {CORE::atan2($_[1],CORE::sqrt(1-$_[1]*$_[1]))}
 
#sub acos {CORE::atan2(CORE::sqrt(1-$_[1]*$_[1]),$_[1])}
 
#sub atan {CORE::atan2($_[1],1)}
 
#sub acot {CORE::atan2(1,$_[1])}
 
#sub asec {acos($_[0],1.0/$_[1])}
 
#sub acsc {asin($_[0],1.0/$_[1])}
 
 
 
Context()->functions->remove("acos");
 
package NewFunc;
 
# this next line makes the function a
 
# function from reals to reals
 
our @ISA = qw(Parser::Function::numeric);
 
sub acos {CORE::atan2(CORE::sqrt(1-$_[1]*$_[1]),$_[1])*180/3.14159265358979}
 
package main;
 
# Make it work on formulas as well as numbers
 
sub acos {Parser::Function->call('acos',@_)}
 
# Add the new functions to the Context
 
Context()->functions->add( acos => {class => 'NewFunc', TeX => '\arccos'}, );
 
 
 
Context()->functions->remove("asin");
 
package NewFunc;
 
# this next line makes the function a
 
# function from reals to reals
 
our @ISA = qw(Parser::Function::numeric);
 
sub asin {CORE::atan2($_[1],CORE::sqrt(1-$_[1]*$_[1]))*180/3.14159265358979}
 
package main;
 
# Make it work on formulas as well as numbers
 
sub asin {Parser::Function->call('asin',@_)}
 
# Add the new functions to the Context
 
Context()->functions->add( asin => {class => 'NewFunc', TeX => '\arcsin'}, );
 
 
 
Context()->functions->remove("atan");
 
package NewFunc;
 
# this next line makes the function a
 
# function from reals to reals
 
our @ISA = qw(Parser::Function::numeric);
 
sub atan {CORE::atan2($_[1],1)*180/3.14159265358979}
 
package main;
 
# Make it work on formulas as well as numbers
 
sub atan {Parser::Function->call('atan',@_)}
 
# Add the new functions to the Context
 
Context()->functions->add( atan => {class => 'NewFunc', TeX => '\arctan'}, );
 
 
 
Context()->functions->remove("asec");
 
package NewFunc;
 
# this next line makes the function a
 
# function from reals to reals
 
our @ISA = qw(Parser::Function::numeric);
 
sub asec {CORE::atan2($_[1],CORE::sqrt(1-$_[1]*$_[1]))*180/3.14159265358979}
 
#sub asec {acos($_[0],1.0/$_[1])}
 
package main;
 
# Make it work on formulas as well as numbers
 
sub asec {Parser::Function->call('asec',@_)}
 
# Add the new functions to the Context
 
Context()->functions->add( asec => {class => 'NewFunc', TeX => '\arcsec'}, );
 
 
 
Context()->functions->remove("acsc");
 
package NewFunc;
 
# this next line makes the function a
 
# function from reals to reals
 
our @ISA = qw(Parser::Function::numeric);
 
sub acsc {CORE::atan2(CORE::sqrt(1-$_[1]*$_[1]),$_[1])*180/3.14159265358979}
 
#sub acsc {asin($_[0],1.0/$_[1])}
 
package main;
 
# Make it work on formulas as well as numbers
 
sub acsc {Parser::Function->call('acsc',@_)}
 
# Add the new functions to the Context
 
Context()->functions->add( acsc => {class => 'NewFunc', TeX => '\arccsc'}, );
 
 
 
Context()->functions->remove("acot");
 
package NewFunc;
 
# this next line makes the function a
 
# function from reals to reals
 
our @ISA = qw(Parser::Function::numeric);
 
sub acot {CORE::atan2(1,$_[1])*180/3.14159265358979}
 
package main;
 
# Make it work on formulas as well as numbers
 
sub acot {Parser::Function->call('acot',@_)}
 
# Add the new functions to the Context
 
Context()->functions->add( acot => {class => 'NewFunc', TeX => '\arccot'}, );
 
 
 
# End trig functions in degrees
 
###################################################
 
   
  +
$ans1 = Compute("sin(30)");
  +
$ans2 = Compute("arcsin(0.5)");
   
 
</pre>
 
</pre>
Line 68: Line 72:
 
<p>
 
<p>
 
<b>Setup:</b>
 
<b>Setup:</b>
WeBWorK's default is to evaluate trig functions in radians. Radians ought to
 
  +
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
be used whenever possible. Sometimes, degrees are unavoidable (e.g., when
 
your students are first learning trig and haven't yet been taught radians).
 
The code in this section 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.
 
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> and <code>arctan(x)</code>, but not <code>tan^(-1)(x)</code>.
+
<code>atan(x)</code>, or <code>arctan(x)</code>, or <code>tan^(-1)(x)</code>.
You may want to warn your students about this caveat in the main text section of the problem.
+
You may want to mention the syntax options in the main text section of the problem.
 
</p>
 
</p>
 
</td>
 
</td>
Line 90: Line 90:
 
Context()->texStrings;
 
Context()->texStrings;
 
BEGIN_TEXT
 
BEGIN_TEXT
Enter \( \sin(30) \): \{ ans_rule(20) \}
+
Enter \( \sin(30) \):
$BR
+
\{ ans_rule(20) \}
Enter \( \arcsin(1/2) \): \{ ans_rule(20) \}
+
\{ AnswerFormatHelp("formulas") \}
 
$BR
 
$BR
Caution: Enter \( \arcsin(x) \) as \( \arcsin(x) \) or
+
Enter \( \arcsin(1/2) \):
\( \mathrm{asin}(x) \), but not \( \sin^{-1}(x) \).
+
\{ ans_rule(20) \}
  +
\{ 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 114: Line 114:
 
$showPartialCorrectAnswers = 1;
 
$showPartialCorrectAnswers = 1;
   
ANS( Real(0.5)->cmp() );
+
ANS( $ans1->cmp() );
ANS( Compute("pi/6")->cmp() );
+
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>
As is the answer. We should include a comment that warns other instructors that trig functions are in degrees instead of radians.
 
  +
The answers are 0.5 and 30 (computed in degrees in the Setup section).
 
</p>
 
</p>
 
</td>
 
</td>
Line 139: Line 139:
 
Context()->normalStrings;
 
Context()->normalStrings;
   
COMMENT("MathObject version. Redefines trig functions to be in degrees (not radians).");
+
COMMENT("Redefines trig functions to be in degrees (not radians).");
   
 
ENDDOCUMENT();
 
ENDDOCUMENT();
Line 145: Line 145:
 
<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>
Line 158: Line 158:
   
 
[[Category:Top]]
 
[[Category:Top]]
[[Category:Authors]]
+
[[Category:Sample Problems]]
  +
[[Category:Subject Area Templates]]
  +
[[Category:Problem Techniques]]

Revision as of 12:57, 24 July 2021

Trigonometric Functions in Degrees

Click to enlarge

This PG code shows how to use the context TrigDegrees to redefine trigonometric functions so they evaluate in degrees rather than radians.


Templates by Subject Area

PG problem file Explanation

Problem tagging data

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 atan(x), or arctan(x), or tan^(-1)(x). You may want to mention the syntax options in the main text section of the problem.

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.


Templates by Subject Area