FunctionDecomposition1

From WeBWorK_wiki
Jump to navigation Jump to search
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


Function Decomposition

Click to enlarge

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



Templates by Subject Area

PG problem file Explanation

Problem tagging data

Problem tagging:

DOCUMENT();

loadMacros(
  'PGstandard.pl',
  'MathObjects.pl',
  'answerComposition.pl',
  'PGML.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->add(u=>"Real");

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

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

Setup:

BEGIN_PGML
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) `].

+ [` f(u) = `] [_______________]

+ [` g(x) = `]  [_______________]

[@ helpLink('formula') @]*
END_PGML

Main Text:

$showPartialCorrectAnswers = 1;

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

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.

BEGIN_PGML_SOLUTION
Solution explanation goes here.
END_PGML_SOLUTION

ENDDOCUMENT();

Solution:

Templates by Subject Area