WeBWorK Problems

Variable limits set to a disjoint domain?

Variable limits set to a disjoint domain?

by Paul Seeburger -
Number of replies: 3

Is it possible to set a variable's limits to a disjoint domain?

For example, I want to set the limits of x to be (-inf, -1] U [1, inf) for the function y = arcsec (x).

I see that I can set domain for a single interval easily using:

Context()->variables->set(x=>{limits=>[$lowerBound, $upperBound]});

Any suggestions?

Thanks!

In reply to Paul Seeburger

Re: Variable limits set to a disjoint domain?

by Davide Cervone -
There is no support for domains other than single intervals at the moment. MathObjects will discard test points that are not in the domain (up to a certain limit), so you could use [-10,10], which would make it less likely (though not impossible) to fail to find enough test points by the time that limit is reached.
In reply to Davide Cervone

Re: Variable limits set to a disjoint domain?

by Paul Seeburger -

Thanks, Davide!

I can see how that would work.

Another way I figured out to accomplish my goal was to set the limits for x with:

Context()->variables->set(x=>{limits=>[$bound, 10]});

Then I added test points to the function holding the problem answer from the negative part of the domain with:

$afunc->{test_at} = [-$bound, -$bound*2, -$bound*10];

This seemed to work well for my goal of checking an antiderivative with arcsec (|u|/a) in it.

The variable $bound was determined from the random variables in u and a.

Paul

In reply to Paul Seeburger

Re: Variable limits set to a disjoint domain?

by Alex Jordan -
You can also explicitly declare test points to be used for a Formula comparison. In this case, you could define explicit random test points in the domain you need and then set them as the test points with something like
$myFormula = Formula("arcsec(x)");
for my $i (0..4) {$p[$i] = random(-1,1,2) * random(1,2,0.001);};
$myFormula->{test_points} = ~~@p;
# or if that last line doesn't work:
# $myFormula->{test_points} = [[$p[0]],[$p[1]],[$p[2]],[$p[3]],[$p[4]]];
Of course you can choose to use more test points if you want to. Sorry if my code doesn't work - I did not test it, but hopefully you get the idea.