# [LON-CAPA-users] Having an equation or a range as a response

Gerd Kortemeyer korte at lite.msu.edu
Sat Jan 21 22:52:55 EST 2012

Hi,

On Jan 20, 2012, at 1:49 PM, Seema Ali wrote:

> I'm also super new to Maxima, but can it factor out constants from an expression?  Or could you create a fraction between the left and right side, reduce it and then see if it is the simplified version? Of course being carfeul not to divide by zero.

I think I got it, please test. If this is good, I might turn it into a template and/or a new responsetype.

Gotta love MAXIMA :-)

- Gerd.

<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)=@_; # var is the variable given # value is the expected value of$var, $var=$value
# equation is the equation to be tested
$expressiona='trigsimp(trigreduce(['.$var.'='.$value.']))';$expressionb='trigsimp(trigreduce(solve('.$equation.','.$var.')))';
$reply=&cas('maxima','is(equal('.$expressiona.','.$expressionb.'))'); if ($reply=~/^Error\:/) { return $reply; } if ($reply=~/true/) { 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);
if ($first=~/^Error/) { return 'BAD_FORMULA'; } if ($first=~/true/) { return 'EXACT_ANS'; }

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