[LON-CAPA-cvs] cvs: loncom /homework/templates custom_equation.problem custom_equation.problem.meta doc/loncapafiles loncapafiles.lpml

www www at source.lon-capa.org
Tue Jan 24 19:59:03 EST 2012


www		Wed Jan 25 00:59:03 2012 EDT

  Added files:                 
    /loncom/homework/templates	custom_equation.problem 
                              	custom_equation.problem.meta 

  Modified files:              
    /doc/loncapafiles	loncapafiles.lpml 
  Log:
  Bug #6550: testing equations
  
  
Index: doc/loncapafiles/loncapafiles.lpml
diff -u doc/loncapafiles/loncapafiles.lpml:1.782 doc/loncapafiles/loncapafiles.lpml:1.783
--- doc/loncapafiles/loncapafiles.lpml:1.782	Tue Jan 10 20:05:59 2012
+++ doc/loncapafiles/loncapafiles.lpml	Wed Jan 25 00:58:53 2012
@@ -2,7 +2,7 @@
  "http://lpml.sourceforge.net/DTD/lpml.dtd">
 <!-- loncapafiles.lpml -->
 
-<!-- $Id: loncapafiles.lpml,v 1.782 2012/01/10 20:05:59 www Exp $ -->
+<!-- $Id: loncapafiles.lpml,v 1.783 2012/01/25 00:58:53 www Exp $ -->
 
 <!--
 
@@ -1376,6 +1376,8 @@
 optional_criteria.task.meta;
 ClickImageExample.problem;
 ClickImageExample.problem.meta;
+custom_equation.problem;
+custom_equation.problem.meta;
 customhints.problem;
 customhints.problem.meta;
 custompartial.problem;

Index: loncom/homework/templates/custom_equation.problem
+++ loncom/homework/templates/custom_equation.problem
<problem>
<script type="loncapa/perl">
$a=&random(3,8,1);
$b=$a+&random(2,5,1);
$sample="x=$b or y=$a*x would be correct";

sub compareequations {
    my ($var,$value,$equation,$real,$lenient)=@_;
# var is the variable given
# value is the expected value of $var, $var=$value
# equation is the equation to be tested
# real: if set, operate only in the real realm
# lenient: if set, give credit even if the correct answer is only one of the possible answers, e.g., x^2=9 is "correct" if x=3 is expected
    $correctanswer=&cas('maxima','trigsimp(trigreduce('.$var.'='.$value.'))');
    if ($correctanswer=~/^Error\:/) { return $correctanswer; }
    $solution=&cas('maxima','trigsimp(trigreduce(solve('.$equation.','.$var.')))');
    if ($solution=~/^Error\:/) { return $solution; }
    $solution=~s/^\[//;
    $solution=~s/\]$//;
    $total=0;
    $found=0;
    foreach my $thissolution (split(/\s*\,\s*/,$solution)) {
         if (($real) && ($thissolution=~/\%i/)) { next; }
         $total++;
         if ($thissolution eq $correctanswer) { $found=1; }
    }
    if ((!$lenient) && ($total>1)) { return 'false'; }
    if ($found) { return 'true'; }
    return 'false';
}
</script>

<startouttext />
Given an equation for an asymptote of <m eval="on">\[y=$a\cdot x+\frac{1}{x-$b}\]</m>
<endouttext />

<customresponse answerdisplay="$sample">

<answer type="loncapa/perl">$first=&compareequations('y',"$a*x",$submission,1);
if ($first=~/^Error/) { return 'BAD_FORMULA'; }
if ($first=~/true/) { return 'EXACT_ANS'; }

$second=&compareequations('x',$b,$submission,1);
if ($second=~/^Error/) { return 'BAD_FORMULA'; }
if ($second=~/true/) { return 'EXACT_ANS'; }

return 'INCORRECT';</answer>

    <textline readonly="no" />
</customresponse>

</problem>

Index: loncom/homework/templates/custom_equation.problem.meta
+++ loncom/homework/templates/custom_equation.problem.meta
<title>Custom Response Response comparing Equations using Computer Algebra System</title>
<category>Algebraic Response Problems</category>
<help>Custom_Response_Problems</help>




More information about the LON-CAPA-cvs mailing list