WeBWorK Problems

Vector answer with variables

Vector answer with variables

by Sean Fitzpatrick -
Number of replies: 5

I've been looking for an example or documentation on how to have a quesiton where the answer is a vector with variable entries, but so far I haven't been successful.

The context in my case is linear transformations. I want students to find a formula for a linear transformation from R2 to R2, and I want to format the problem like T(x,y) = __________________

rather than T(x,y) = (_____x + _____y, _____x + _____y)

and have students enter an answer like (3x+2y, -x+4y). The vector math object doesn't seem to like entries that are formulas.

In reply to Sean Fitzpatrick

Re: Vector answer with variables

by Sean Fitzpatrick -

I tried to do something like the following:

Context()->variables->add(y => "Real");

$ans1 = Formula(2*x+3*y);
$ans2 = Formula(-4*x+5*y);
$ans = Vector($ans1,$ans1);


This gives me the error message: 

Can't locate object method "weaken" via package "main" at [PG]/lib/Parser/List.pm line 67
   from within main::Vector
In reply to Sean Fitzpatrick

Re: Vector answer with variables

by Glenn Rice -

You will need to use the Vector context.  Note that the variable "y" is already in the Vector context, so there will be no need to add that.  Also, you need to quotes on the Formula arguments.  It should be

Context('Vector');

$ans1 = Formula('2x + 3y');
$ans2 = Formula('-4x + 5y');
$ans = Vector($ans1, $ans2);

In reply to Glenn Rice

Re: Vector answer with variables

by Sean Fitzpatrick -
Thanks. That works. The only remaining issue is that students have to use angle brackets to enter their answer, rather than parentheses.
Not ideal, but I can add an instruction.