Domain and Range of a Function

Domain and range of a function using inequalities

Complete Code

Download file: DomainRange.pg

POD for Macro Files

PG problem file

Explanation

DOCUMENT();

loadMacros('PGstandard.pl', 'PGML.pl', 'contextInequalities.pl', 'PGcourse.pl');

Preamble

The contextInequalities.pl macro is used for inequality answers.

$a = random(1, 6);

Context('Inequalities-Only')->variables->are(x => 'Real');
Context()->flags->set(formatStudentAnswer => 'parsed');

$domain = Compute("x >= $a");

Context('Inequalities-Only')->variables->are(y => 'Real');
Context()->flags->set(formatStudentAnswer => 'parsed');

$range = Compute('y >= 0');

# Interval version of the same domain and range.
Context('Interval');
$domain_interval = Compute("[$a, inf)");
$range_interval  = Compute('[0, inf)');

Setup

In addition to showing how to use the contextInequalities.pl macro, this example problem demonstrates how different contexts can be used for different answers in a problem.

First, Context('Inequalities-Only')->variables->are(x => 'Real') is called, and this creates a new context instance. This instance only has the variable x. Note that calling ->variables->are(x => 'Real') for this instance is actually unnecessary since x is the only variable in the context by default. It is only shown here for emphasis. The $domain is computed in this context.

Next, Context('Inequalities-Only')->variables->are(y => 'Real') is called, and this creates another context instance. This instance only has the variable y. The $range is computed in this context.

Note that the “Inequalities-Only” requires students to enter their answer using inequalities. The more general “Inequalities” context provided in the contextInequalities.pl macro, also allows answers to be entered using interval notation. For more details, please see contextInequalities.pl.

Setting the context flag formatStudentAnswer => 'parsed' insists that the parsed student answers be displayed and no further reduction or evaluation be done. Generally this means the student answer is displayed much as it is entered. In particular in this instance it prevents the student’s answer from being reduced to a decimal.

For the last part, the “Interval” context is used instead. This context is changed to by calling Context('Interval'). Note that inf is built-in for infinite intervals.

BEGIN_PGML
Suppose [`f(x) = \sqrt{x - [$a]}`].

Enter inequalities for the domain and range of [`f`].

Domain: [_]{$domain}{15}

Range: [_]{$range}{15}

Use interval notation to give the domain and range of [`f`].

Domain: [_]{$domain_interval}{15}

Range: [_]{$range_interval}{15}
END_PGML

Statement

This is the problem statement in PGML.
BEGIN_PGML_SOLUTION
Solution explanation goes here.
END_PGML_SOLUTION

ENDDOCUMENT();

Solution

A solution should be provided here.