WeBWorK Main Forum

Any caveats regarding the range of x and y when using the ImplicitEquation context?

Any caveats regarding the range of x and y when using the ImplicitEquation context?

by Christian Seberino -
Number of replies: 3
I've noticed strange errors when the ranges of x and y below are changed to 
[-1,1].  In that case I get this...


Error parsing answer: 'plicitEquation' is not defined in this context; see position 3 of formula

I thought the ranges of x and y were not so important but apparently there
are certain caveats to be aware of?

cs



DOCUMENT(); 
loadMacros( 
  "MathObjects.pl", 
  "PGstandard.pl", 
  "PGML.pl", 
  "PGcourse.pl", 
  "parserNumberWithUnits.pl", 
  "contextArbitraryString.pl", 
  "parserMultiAnswer.pl", 
  "parserPopUp.pl", 
  "contextInequalities.pl", 
  "parserImplicitEquation.pl", 
  "PGgraphmacros.pl", 
); 
TEXT(beginproblem()); 
$showPartialCorrectAnswers = 1; 
###################################################################### 
 
Context("ImplicitEquation"); 
Context()->variables->set( 
x=>{limits=>[-8,8]}, 
y=>{limits=>[-8,8]} 
); 
 
BEGIN_PGML 
What is the equation for a circle with its center at (4, 2) 
throught the point (3, 2)? 
 
[________________________]{ImplicitEquation("(x-4)^2 + (y-2)^2=1", 
                                   tolerance=>0.0001)} 
END_PGML 
 
###################################################################### 
ENDDOCUMENT(); 

In reply to Christian Seberino

Re: Any caveats regarding the range of x and y when using the ImplicitEquation context?

by Davide Cervone -
The ImplicitEquation object requires the variable limits to include points that are solutions to the equation. This is from the documentation for parserImplicitEquation.pl:

The method used to locate the solutions of A=B is by finding zeros of A-B, and it requires this function to take on both positive and negative values (that is, it can only find transverse intersections of the surface A-B=0 and the plane at height 0). ... In order to locate the zeros, you may need to change the limits so that they include regions where the function is both positive and negative

Your equation is a circle of radius 1 centered at (4,2), so when the limits are [-8,8], this does include the circle, whereas the limits [-1,1] do not, so these limits are not appropriate for use with this equation.

You should get a message about not being able to find solutions within the given limits, but I think the use of PGML has obscured that. My recommendation would be to create the MathObject outside of PGML, as in the following:

    Context("ImplicitEquation"); 
    
    $circle = ImplicitEquation("(x-4)^2 + (y-2)^2=1",
         tolerance=>0.0001, limits=>[0,8]);
     
    BEGIN_PGML 
    What is the equation for a circle with its center at (4, 2) 
    throught the point (3, 2)? 
     
    [________________________]{$circle}
    END_PGML 

This will make sure you get any error messages from the creation of the implicit equation.

In reply to Davide Cervone

Re: Any caveats regarding the range of x and y when using the ImplicitEquation context?

by Christian Seberino -
Ah thanks that makes sense.  Would this "lazy" solution be a good idea?.....

You said the interval needs to include certain things.  What if I defaulted to a huge interval that was sure to work in 99% of the cases?

e.g. 

Context()->variables->set(
x=>{limits=>[-1000,1000]},
y=>{limits=>[-1000,1000]}
);

cs
In reply to Christian Seberino

Re: Any caveats regarding the range of x and y when using the ImplicitEquation context?

by Davide Cervone -
This is probably not a good idea. The ImplicitEquation object locates solutions by picking pairs of points (randomly within the limits) that have opposite signs, and doing bisection to find a zero in between. The closer you are to a zero to start with, the quicker you will find the zero. Setting the limits to [-1000,1000] would mean you are likely far from the actual zero to start with and so would have to do lots of bisection steps. Also, the bisection algorithm cuts off after 40 iterations, and with a potential distance of 2000sqrt(2) , that means you could cut off with the bisection interval still wider than 70 units, which doesn't give very good resolution for a problem like yours.

In my experience, three are no magic bullets for numeric problems like this, so you do have to spend some time thinking about the proper settings of the parameters. That can be complicated by randomization within the problem, but you can make the limits depend on the values in the problem, so you should be able to do better than using something like [-1000,1000].