WeBWorK Main Forum

two-letter variables?

two-letter variables?

by Michael Miller -
Number of replies: 5
I'd like to require that my students enter the "dx" when they write integrals. The code
ANS(fun_cmp("sqrt(1+4x^2) dx", vars=>['x','dx']));
results in the warning "Use of uninitialized value in concatenation (.) or string at line 733 of (eval 983)", but seems to work properly. The problem appears to be the dx.

1) Is there really a problem? If so, can I fix it? If not, can I eliminate the warning message (so I won't have all my students asking me about it?)

In reply to Michael Miller

Re: two-letter variables?

by Gavin LaRose -
Hi Michael,

What version of WeBWorK are you running? I know that MathObjects were changed to allow two character variables at some point along the line, which I think corrected this behavior. In particular, when I try

ANS(fun_cmp("x dx", vars=>['x','dx']);

on my system, I don't get any errors (I'm running a version of WeBWorK slightly past 2.4.1).

I also have problems that accomplish the same thing that explicitly use MathObjects and set the variables in the Context of the problem, e.g.,

Context()->variables->are(x=>'Real', dx=>'Real');
...
ANS( Compute("x dx")->cmp() );

Gavin
In reply to Gavin LaRose

Re: two-letter variables?

by Michael Miller -
My course is hosted on hosted2.webwork.rochester.edu, so my version of WeBWorK is whatever's running there - I'm not sure how to determine that.

To be completely clear: the following code produces the warning message "Use of uninitialized value in concatenation (.) or string at line 733 of (eval 999)", and this message disappears if dx is replaced by y.

DOCUMENT();
ANS(fun_cmp("dx", vars => ['dx']));
ENDDOCUMENT();
In reply to Michael Miller

Re: two-letter variables?

by Michael Gage -
Hi,

I can confirm that on hosted2

ANS(fun_cmp("dx", vars=>['dx']));
# doesn't work


# but this does:
Context()->variables->add('dx'=>'Real');
$f=Formula("dx");
ANS($f->cmp);

I don't know why yet. I'm out of town for another two days but I'll look in to it when I get back unless someone beats me to it.



-- Mike


In reply to Michael Miller

Re: two-letter variables?

by Davide Cervone -
OK, the problem was in the conversion from the traditional answer checkers to the internal MathObjects-based answer checkers. Changes to the MathObjects library over the summer made the handling of multi-letter variables easier, and some code in fun_cmp() obsolete. In the past, multi-letter variables were harder to add to the context, and had to be handled in a special way. Now, however, they work just like single-character variables. The special handling that was being done in fun_cmp() is no longer needed, and was the source of the error you were seeing.

I have fixed the problem in the pg CVS repository, and you should be able to update to the current version without problems. The changed file is PGfunctionevaluators.pl.

Davide
In reply to Davide Cervone

Re: two-letter variables?

by Michael Gage -
I've updated the pg code on hosted2. Thank you Davide. and thank you Mike for bringing this to our attention.

--Mike