[LON-CAPA-users] How to write a custom response problem with vector I/O?
Justin Gray
jgray at math.sfu.ca
Fri Oct 23 16:36:47 EDT 2020
I'm afraid I do not have an answer to your question, but have you
considered coding this problem as a mathresponse problem?
Best regards,
Justin
--
*Justin Gray*
Senior Lecturer | Department of Mathematics
Simon Fraser University | SCK 10531
8888 University Dr., Burnaby, B.C. V5A 1S6
Canada
Simon Fraser University is located on the Unceded Coast Salish Territories
of the xʷməθkʷəy̓əm (Musqueam), Səl̓ílwətaʔ/Selilwitulh (Tsleil-Waututh),
Kwikwitlem, and Skwxwú7mesh Úxwumixw (Squamish) Peoples
On Fri, Oct 23, 2020 at 1:18 PM Itay <itayf at nospammail.net> wrote:
> Hi
>
> I am trying to develop a custom response problem in which the student
> submission is a vector.
> A minimal example is provided below.
> Regardless of what I typed in the either of the two input fields I get the
> response:
> 'This question expects a numeric answer.'
>
> Please advise what am I doing wrong?
>
> Thanks in advance.
> Itay
>
>
> <problem> <!-- begin minimal -->
> <script type="loncapa/perl">
> $ax = &random(1.0, 10, 0.1); # Coordinates of \vec{a}
> $ay = &random(1.0, 10, 0.1);
> </script>
>
> <startouttext />
> Consider a vector <m eval="on">\( \vec{a} = $ax\hat{x} + $ay\hat{y}
> \)</m>'.
> Provide a vector <m>\( \vec{b} \)</m>, orthogonal to <m>\( \vec{a}
> \)</m>.
> <br />
> <endouttext />
>
> <customresponse id="dotProd">
> <answer type="loncapa/perl">
> for ($i=0; $i<2; $i++) { # Test input sanity.
> if ($submission[i] =~ /^\d+\s+\w+$/) { return 'UNIT_NOTNEEDED'; }
> if ($submission[i] !~ /^[\d\.]+$/) { return 'WANTED_NUMERIC'; }
> }
>
> # Is submission correct?
> $dotProd = $ax * $submission[0] + $ay * $submission[1];
> if (abs($dotProd) < 1.0e-3) { return 'APPROX_ANS'; } # Can't expect
> EXACT_ANS.
> return 'INCORRECT';
> </answer>
>
> <startouttext /><m>\( b_x = \)</m><endouttext />
> <textline size="10" readonly="no" spellcheck="none" />
> <startouttext /><br /><endouttext />
>
> <startouttext /><m>\( b_y = \)</m><endouttext />
> <textline size="10" readonly="no" spellcheck="none" />
> <startouttext /><br /><endouttext />
> </customresponse>
> </problem> <!-- end minimal -->
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.lon-capa.org/pipermail/lon-capa-users/attachments/20201023/8ee58298/attachment-0001.html>
More information about the LON-CAPA-users
mailing list