WeBWorK Problems

context for polar coordinates

context for polar coordinates

by Alex Jordan -
Number of replies: 6
Is there a context for polar coordinates? I looked in pg/macros, but didn't find anything. Maybe somewhere in one of the OPL donors macro libraries?

I'm writing questions for a book where the syntax is P(r, theta). I know that (r; theta) is a common syntax. Are there others?

I think the complete list of conditions for checking equality would be that P(r,t) = P(s,u) when:
  • r=s=0
  • r=s and t,u differ by an even multiple of pi
  • r=-s and t,u differ by an odd multiple of pi



In reply to Alex Jordan

Re: context for polar coordinates

by Alex Jordan -
Perhaps it would be more efficient to compare two such points by converting each to Cartesian first.
In reply to Alex Jordan

Re: context for polar coordinates

by Alex Jordan -
I have written a custom checker based on converting such polar coordinates to Cartesian coordinates and then comparing. But I wanted to be consistent with the book's notation for polar coordinates, which is P(r, theta). I attempted to make 'P(' the open delimiter for a Point, but such expressions insisted on interpreting the 'P' as a variable (which of course was not recognized as part of the context.)

So at present I have a hack in place where I have made 'P' equivalent to '+' as a unary operator. So students can enter P(1,pi) and really it's the same thing as if they entered (1, pi), and both might be counted as correct. This is a hack, and I think I still really want to make 'P(' the opening delimiter for a special kind of Point. Then we could have things like P(1, pi/4) mean the same as (sqrt(2)/2, sqrt(2)/2). (So, be flexible as to whether the location was specified in polar coordinates or Cartesian coordinates.)

But I've had no success thus far.
In reply to Alex Jordan

Re: context for polar coordinates

by Paul Pearson -
Hi Alex,

Here's an alternate idea.  Use the Complex context, add a function to the context ( http://webwork.maa.org/wiki/AddingFunctions ) defined by 

parserFunction("P(r,t)" => "r*e^(i*t)");

and set a Context flag so that the student answer gets displayed in the feedback in the form P(r,t) instead of as a complex number.  There's a minimal working example below my signature.

Best regards,

Paul Pearson

############################

DOCUMENT();        

loadMacros(
"PGstandard.pl",
"MathObjects.pl",
"PGML.pl",
"parserFunction.pl",
);
TEXT(beginproblem());

Context("Complex")->variables->are(r=>'Real', t=>'Real');
Context()->flags->set(formatStudentAnswer => "reduced");
parserFunction("P(r,t)" => "r*e^(i*t)");

$a = Compute("P(2,pi/4)");

BEGIN_PGML
[` P(2,\pi/4) =`] [__________]{$a}
END_PGML

ENDDOCUMENT();        
In reply to Paul Pearson

Re: context for polar coordinates

by Alex Jordan -
Paul, this is interesting. Is there a way that you know of for the Complex context to interpret Compute("(1,2)") as 1+2i? If that were part of the set up as well, then it would be a context where, say, "P(1, pi/4)" and "(sqrt(2)/2, sqrt(2)/2)" mean the same thing.
In reply to Alex Jordan

Re: context for polar coordinates

by Paul Pearson -
Hi Alex,

Having the Complex context interpret Compute("(1,2)") as 1+2i sounds like a parser issue that I have not looked into before.  If you can demonstrate a need for this functionality, then maybe you could get one of the people who have written contexts and parsers before to help you out.

I don't know that there's a large enough demand for a context that would interpret (r,theta) = P(1,pi/4) and (x,y) = (sqrt(2)/2,sqrt(2)/2) as equivalent answers.  It seems like a feature that would be better implemented using a custom answer checker implemented written directly in the small number of individual pg problems that need it.

Best regards,

Paul Pearson
In reply to Paul Pearson

Re: context for polar coordinates

by Alex Jordan -
I think what I want is a context where you could ask questions like "Where does this curve cross that curve?" with the curves specified in some combination of:
y=f(x), r=f(theta), and {x=f(t), y=g(t)}
(My immediate questions to code have two equations in polar form.)

Some students gravitate toward answers like
Cartesian-(1,1)
even when the two curves were expressed in polar and others would answer with
Polar-(sqrt(2), pi/4)

I have no problem with this flexibility for these questions, and it would be nice to program in that flexibility. I'm thinking that I need a new kind of MathObject: Polar. It would be analogous to Point, but have different delimiters and/or separators. Perhaps P(r,t) would be the default or perhaps (r;t). The comparison operator == would be usable between a Polar and a 2D Point. (And maybe the notion of Polar should extend to Spherical.)

This is what I was trying to do, and I though I understood how to get started. But I could not get 'P(' to be parsed as an open delimiter. I think the '(' was always being intercepted first and interpreted as a delimiter, and then 'P' was always an unrecognized variable.

I'll clean up my progress and try to post sample code for anyone interested.