Formula Test Points

Shows how to test a formula at a given set of points.

Complete Code

Download file: FormulaTestPoints.pg

PG problem file

Explanation

DOCUMENT();

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

Preamble

These standard macros need to be loaded.
Context()->variables->set(x => { limits => [ -1, 1 ] });

# Alternately
Context()->flags->set(limits => [ 2, 5 ]);

$f = Compute('sqrt(x+1)');

## Or, setting the limits only for the given
##    formula, we don't need to reset the Context,
##    and just include
# $func = Compute('sqrt(x-1)');
# $func->{limits} = [2,5];

$g = Compute("sqrt(x^2 - 4)");
$g->{test_points} = [ [-3], [-2], [2], [3], [4] ];

Setup

The first line sets the limits of evaluation for any problem in the context to [-1,1].

Alternatively, the limits on the context can be set with

Context()->flags->set(limits=>[2,5]);

For the points for $g, note that the domain of $g is all values outside of the interval (-2,2). One way to handle this would be to set the limits for the function to be outside this interval. Alteratively, as shown, the points are set with the test_points field to be a set of points that don’t include (-2,2).

BEGIN_PGML
Enter [`[$f]`] [___]{$f}

Enter [`[$g]`] [___]{$g}
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.