# DomainRange1

## Domain and Range of a Function

Click to enlarge

This PG code shows how to evaluate answers that are inequalities which use different variables.

PG problem file Explanation

Problem tagging:

DOCUMENT();

"PGstandard.pl",
"MathObjects.pl",
"contextInequalities.pl",
);

TEXT(beginproblem());

Context("Numeric");

\$f = Compute("sqrt(x-4)");

Context("Inequalities-Only")->variables->are(x=>"Real");

\$domain = Compute("x >= 4");

Setup 1: We specify the context in a way that requires students to enter their answer using inequalities and the variable x. If we had used Context("Inequalities") instead, then students would also be able to enter answers using interval notation. For more details, please see contextInequalities.pl.html

We use formatStudentAnswer=>'parsed' and Compute() so that the student's answer are left as fractions rather than reduced to decimals.

Context()->texStrings;
BEGIN_TEXT
Suppose \( f(x) = \$f \).  Enter inequalities for the
domain and range of \( f \).
\$BR
\$BR
Domain:
\{ ans_rule(20) \}
\$BR
END_TEXT
Context()->normalStrings;

Main Text 1:

ANS( \$domain->cmp() );

Context("Inequalities-Only")->variables->are(y=>"Real");

\$range  = Compute("y >= 0");

Setup 2: We must reset the context and the variable so that students must enter the variable y in their answer.

Context()->texStrings;
BEGIN_TEXT
Range:\$SPACE\$SPACE
\{ ans_rule(20) \}
END_TEXT
Context()->normalStrings;

Main Text 2:

ANS( \$range ->cmp() );

Context()->texStrings;
BEGIN_SOLUTION
\${PAR}SOLUTION:\${PAR}
Solution explanation goes here.
END_SOLUTION
Context()->normalStrings;

COMMENT('MathObject version.');

ENDDOCUMENT();

Solution: