From: Mike G. v. a. <we...@ma...> - 2007-10-29 02:41:46
|
Log Message: ----------- Modifications PGgraphicsmacros.pl suggested by Davide Cervone. 1. Don't load MathObjects (since this causes conflicts if the webwork question also uses Matrices as well as GraphObjects). (This incompatibility is itself a bug, but not one we can solve immediately.) 2. Make sure that the variable is defined by defining the new rule in a local context and insuring that the variable is defined. (Unfortunately we don't have the original Formula, just the normalString created by the Formula so we won't be able to guarantee the same context that created the original Formula. However we can get the current context and add the independent variable if it is missing.) 3. Evaluate using Parser::Evaluate so that the errors are trapped if the input is not in the domain of definition of the function. ------- A reasonable next step would be to define plot_formula with syntax something like plot_formula($formula, domain=>[0,10],color=>'red',weight=>2) which could take further advantage of the MathObjects paradigm, but we'll probably have to find a more robust solution to the Matrix confusion at the same time. --Mike Modified Files: -------------- pg/macros: PGgraphmacros.pl Revision Data ------------- Index: PGgraphmacros.pl =================================================================== RCS file: /webwork/cvs/system/pg/macros/PGgraphmacros.pl,v retrieving revision 1.8 retrieving revision 1.9 diff -Lmacros/PGgraphmacros.pl -Lmacros/PGgraphmacros.pl -u -r1.8 -r1.9 --- macros/PGgraphmacros.pl +++ macros/PGgraphmacros.pl @@ -47,7 +47,9 @@ # 'axes' ######################################################### -loadMacros("MathObjects.pl"); # need this to handle problems that don't otherwise use MathObjects +#loadMacros("MathObjects.pl"); # avoid loading the entire package + # of MathObjects since that can mess up + # problems that don't use MathObjects but use Matrices. my %images_created = (); # this keeps track of the base names of the images created during this session. # We tack on @@ -317,8 +319,15 @@ } else { $weight =2; } - my $subRef = Formula($rule)->perlFunction(undef,[$var]); - # my $subRef = string_to_sub($rule,$var); + # a workaround to call Parser code without loading MathObjects. + my $localContext= Parser::Context->current(\%main::context)->copy; + $localContext->variables->add($var=>'Real') unless $localContext->variables->get($var); + my $formula = Value->Package("Formula()")->new($localContext,$rule); + my $subRef = sub {my $x=shift; Parser::Evaluate($formula, $var=>$x)}; + #traps errors when + # graph domain is larger than the function's domain. + + #my $subRef = string_to_sub($rule,$var); my $funRef = new Fun($subRef,$graph); $funRef->color($color); $funRef->weight($weight); |