[LON-CAPA-users] Having an equation or a range as a response
Seema Ali
sali at vsb.bc.ca
Sun Jan 22 00:05:09 EST 2012
Gerd,
I tested tried it out and it looks good. Where can I get a list of Maxima questions that Lon Capa uses? I listed the test cases that I used:
x=0 (for these I forced 0 to be a solution to try it out)
0=x
2*x = 10
10 = 2*x
x=5
5=x
2x+9=19
19=2x+9
y=4*x
x = 0.25*y
4x -y = 0
I probably didn't have to test out the equations that are "mirror" images (along the equal sing) of a successful equation, but I thought I'd do it anyways, since I am not familiar with trigsimp and trigreduce.
Thanks this is awesome!
-----Original Message-----
From: lon-capa-users-bounces at mail.lon-capa.org on behalf of Gerd Kortemeyer
Sent: Sat 1/21/2012 7:52 PM
To: Discussion list for LON-CAPA users
Subject: Re: [LON-CAPA-users] Having an equation or a range as a response
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'; }
return 'INCORRECT';</answer>
<textline readonly="no" />
</customresponse>
</problem>
_______________________________________________
LON-CAPA-users mailing list
LON-CAPA-users at mail.lon-capa.org
http://mail.lon-capa.org/mailman/listinfo/lon-capa-users
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.lon-capa.org/pipermail/lon-capa-users/attachments/20120121/3cc469ae/attachment-0001.html>
More information about the LON-CAPA-users
mailing list