--- loncom/homework/functionplotresponse.pm 2011/09/28 23:33:52 1.64 +++ loncom/homework/functionplotresponse.pm 2011/10/13 01:54:12 1.65 @@ -1,7 +1,7 @@ # LearningOnline Network with CAPA # option list style responses # -# $Id: functionplotresponse.pm,v 1.64 2011/09/28 23:33:52 www Exp $ +# $Id: functionplotresponse.pm,v 1.65 2011/10/13 01:54:12 www Exp $ # # Copyright Michigan State University Board of Trustees # @@ -31,6 +31,7 @@ use strict; use Apache::response(); use Apache::lonlocal; use Apache::lonnet; +use Apache::run; BEGIN { &Apache::lonxml::register('Apache::functionplotresponse',('functionplotresponse','backgroundplot','spline', @@ -563,7 +564,7 @@ sub start_functionplotrule { ['lt','less than'], ['le','less than or equal']],$token). $result.= &Apache::edit::select_or_text_arg('Value:','value', - [['undef','not defined']],$token,'8'). + [['undef','not defined']],$token,'30'). &Apache::edit::text_arg('Percent error:','percenterror', $token,'8'). &Apache::edit::end_row(); @@ -979,15 +980,49 @@ sub actualval { my ($i,$xmin,$xmax)=@_; return $xmin+$i/400.*($xmax-$xmin); } + +sub fpr_f { + my ($arg)=@_; + return $Apache::functionplotresponse::func[&array_index($Apache::functionplotresponse::fpr_xmin, + $Apache::functionplotresponse::fpr_xmax, + $arg)]; +} + +sub fpr_dfdx { + my ($arg)=@_; + return $Apache::functionplotresponse::dfuncdx[&array_index($Apache::functionplotresponse::fpr_xmin, + $Apache::functionplotresponse::fpr_xmax, + $arg)]; +} + +sub fpr_d2fdx2 { + my ($arg)=@_; + return $Apache::functionplotresponse::d2funcdx2[&array_index($Apache::functionplotresponse::fpr_xmin, + $Apache::functionplotresponse::fpr_xmax, + $arg)]; +} sub functionplotrulecheck { - my ($rule,$xmin,$xmax,$ymin,$ymax)=@_; + my ($rule,$xmin,$xmax,$ymin,$ymax,$safeeval)=@_; my ($label,$derivative,$xinitial,$xinitiallabel,$xfinal,$xfinallabel,$minimumlength,$maximumlength,$relationship,$value,$percent) =split(/\:/,$rule); $percent=($percent>0?$percent:5); &addlog("================="); &addlog("Rule $label for ".($derivative<0?'integral':('function itself','first derivative','second derivative')[$derivative])." $relationship $value"); +# +# Evaluate the value +# + if ($value=~/\D/) { + $Apache::functionplotresponse::fpr_xmin=$xmin; + $Apache::functionplotresponse::fpr_xmax=$xmax; + $value=&Apache::run::run($value,$safeeval); + &addlog("Value evaluated to $value"); + } + +# +# Minimum and maximum lengths of the interval +# if ((defined($minimumlength)) || (defined($maximumlength))) { &addlog("Minimumlength $minimumlength Maximumlength $maximumlength"); } @@ -1186,7 +1221,7 @@ sub end_functionplotruleset { # We have a function that we can actually grade, go through the spline rules. foreach my $rule (@Apache::functionplotresponse::functionplotrules) { - unless (&functionplotrulecheck($rule,$xmin,$xmax,$ymin,$ymax)) { + unless (&functionplotrulecheck($rule,$xmin,$xmax,$ymin,$ymax,$safeeval)) { $ad='INCORRECT'; last; }