Difference between revisions of "ComposingFunctions"

From WeBWorK_wiki
Jump to navigation Jump to search
(New page: <h2>Composing Functions</h2> <!-- Header for these sections -- no modification needed --> <p style="background-color:#eeeeee;border:black solid 1px;padding:3px;"> <em>This PG code sho...)
 
 
(4 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/problem-techniques/ComposingFunctions.html a newer version of this problem]</p>
 
<h2>Composing Functions</h2>
 
<h2>Composing Functions</h2>
   
Line 104: Line 107:
 
<p>
 
<p>
 
<b>Answer Evaluation:</b>
 
<b>Answer Evaluation:</b>
We use the <code>COMPOSITION_ANS()</code> routine to evaluate both answer blanks.
+
We use the <code>COMPOSITION_ANS()</code> routine to evaluate both answer blanks. It is possible to use the same variable for both answer blanks. See [http://webwork.maa.org/pod/pg/macros/answerComposition.html answerComposition.pl] for more options and details.
 
</p>
 
</p>
 
</td>
 
</td>
Line 120: Line 123:
   
 
<ul>
 
<ul>
<li>POD documentation: [http://webwork.maa.org/doc/cvs/pg_CURRENT/macros/answerComposition.pl.html answerComposition.pl.html]</li>
+
<li>POD documentation: [http://webwork.maa.org/pod/pg/macros/answerComposition.html answerComposition.pl]</li>
<li>PG macro: [http://cvs.webwork.rochester.edu/viewcvs.cgi/pg/macros/answerComposition.pl answerComposition.pl]</li>
+
<li>PG macro: [http://webwork.maa.org/viewvc/system/trunk/pg/macros/answerComposition.pl?view=log answerComposition.pl]</li>
 
</ul>
 
</ul>

Latest revision as of 09:11, 28 June 2023

This article has been retained as a historical document. It is not up-to-date and the formatting may be lacking. Use the information herein with caution.

This problem has been replaced with a newer version of this problem

Composing Functions


This PG code shows how to check student answers that are a composition of functions.

Problem Techniques Index

PG problem file Explanation
DOCUMENT();
loadMacros(
"PGstandard.pl",
"MathObjects.pl",
"answerComposition.pl",
"PGcourse.pl",
);
TEXT(beginproblem()); 

Initialization: We need to include the macros file answerComposition.pl, which provides an answer checker that determines if two functions compose to form a given function. This can be used in problems where you ask a student to break a given function into a composition of two simpler functions, neither of which is allowed to be the identity function..

Context("Numeric");
Context()->variables->are(x=>"Real",y=>"Real",u=>"Real");

$a = random(2,9,1);

$f = Formula("sqrt(u)");
$g = Formula("x^2+$a");

Setup: Everything is as usual.

Context()->texStrings;
BEGIN_TEXT
Express the function \( y = \sqrt{ x^2 + $a } \) 
as a composition \( y = f(g(x)) \) of two simpler
functions \( y = f(u) \) and \( u = g(x) \).
$BR
$BR
\( f(u) \) = \{ ans_rule(20) \}
$BR
\( g(x) \) = \{ ans_rule(20) \}
END_TEXT
Context()->normalStrings;

Main Text: The text section is as we'd expect.

$showPartialCorrectAnswers = 1;

COMPOSITION_ANS( $f, $g, vars=>['u','x'], showVariableHints=>1);

ENDDOCUMENT();

Answer Evaluation: We use the COMPOSITION_ANS() routine to evaluate both answer blanks. It is possible to use the same variable for both answer blanks. See answerComposition.pl for more options and details.

Problem Techniques Index