[LON-CAPA-users] Does formula response support inequalities?
Itay Furman
itayf at nospammail.net
Sat Mar 29 13:55:59 EDT 2014
On Sat, 29 Mar 2014, Gerd Kortemeyer wrote:
> Date: Sat, 29 Mar 2014 11:59:48 -0400
> From: Gerd Kortemeyer <korte at lite.msu.edu>
> To: Itay Furman <itayf at nospammail.net>,
> Discussion list for LON-CAPA users <lon-capa-users at mail.lon-capa.org>
> Subject: Re: [LON-CAPA-users] Does formula response support inequalities?
>
> Hi,
>
> On Mar 29, 2014, at 11:37 AM, Itay Furman <itayf at nospammail.net> wrote:
>
>>
>> Consider a certain physical in which stable equilibrium exists if
>> 2*k*l^2 - mgL > 0,
>> where k,l,m,g, and L, are parameters.
>>
>> I would like to challenge my students with a problem for which the
>> answer would be the above symbolic inequality.
>>
>> However, as I understand I _cannot_ use formula response for that purpose; is this correct? or did I miss something?
>> [snip]
>
> No, formularesponse will not do this. But you can use customresponse or mathresponse.
>
> With mathresponse, you can do whatever you like with the student expression inside of MAXIMA CAS.
>
> With customresponse, you can do whatever you like with the student expression inside of a Perl environment. From there, you can call MAXIMA if needed using &cas(‘maxima’,…).
>
> You probably want to accept “2*k*l^2>m*g*L” as correct, so I would in customresponse:
>
Thank you for the detailed response.
This is exactly what I wished for.
I am impressed by the breadth and flexibility of the Lon-Capa system.
Best regards,
Itay
> <problem>
>
>
> <startouttext />
> In which case do you have stable equilibrium?
> <endouttext />
>
> <customresponse answerdisplay="2*k*l^2 - m*g*L > 0">
>
> <answer type="loncapa/perl"># Get left and right side of (in)equality
> ($left,$sign,$right)=($submission=~/^(.*)([\>\<\=])(.*)$/);
> # If it's not an (in)equality, forget it
> unless ($sign) { return 'BAD_FORMULA'; }
> # If it's an equality, it's wrong
> if ($sign eq '=') { return 'INCORRECT'; }
> # If it's "smaller than", invert
> if ($sign eq '<') { $inter=$left; $left=$right; $right=$inter; }
> # Okay, so now we have $left>$right
> # And compare to the expression we want
> my $diff=&cas('maxima',"$left-($right)-(2*k*l^2-m*g*L)");
> if ($diff=~/^Error/) { return 'BAD_FORMULA'; }
> if ($diff==0) { return 'EXACT_ANS'; }
> return 'INCORRECT';</answer>
>
> <textline readonly="no" spellcheck="none" />
> </customresponse>
>
> </problem>
>
>
> - Gerd.
More information about the LON-CAPA-users
mailing list