Subject: [LON-CAPA-dev] How does formularesponse work

From: Peter Riegler <[email-masked]>
Date: Tue, 22 May 2007 11:20:25 +0200

Hi,

we have a problem using formula response here, which brings up the 
question how it works internally. Unfortunately, I am not really capable 
of understanding what is going on in caparesponse.pm.

So far, my idea of formularesponse has been that it runs nested 
for-loops w.r.t. the sampling variables. For instance,

<formularesponse samples="x,y@-3,-3,;2,2#4" answer="$answer" id="11">

should result in something like

for each x value
    for each y value
        check whether $answer evaluated at x and y equals
		response evaluated at x an y
        if not break out of the for loops and return false
    end
end

However, we experience that
answer = sin(x)
response = sin(y)
evaluates to true in formularesponse IF you use the same sampling points 
for x and y.

I will attach a loncapa problem below. The text is German. The task is 
simply to give the integral including integration constant.

Peter

<problem>
<script type="loncapa/perl">

#
#  Stammfunktion einer trigonometrischen Funktion mit kostantem 
Vorfaktor vor der Funktion und im Argument
#

#  Setzen der möglichen Vorfaktoren, Variablen und trigonometrischen 
Funktionen
#         $fakt - Vorfaktor vor Funktion
#         $argfalt - Vorfaktor im Argument
#         $funktion - Art der trigonometrischen Funktion
#         $var - Variable

$fakt=&random(2,8,1);
$argfakt=&random(1,5,1);
$funktion=&choose(&random(1,2,1),"sin","cos");
$var=&choose(&random(1,3,1),"x","z","t");

# zu intrgrierende Formel

#$formula="$fakt*$funktion($argfakt*$var)";

# Bestimmen der Art der trigonometrischen Stammfunktion und ihres 
Vorzeichens

if( $funktion eq "sin") {
     $intfakt=-1;
     $intfunkt="cos"; }
elsif( $funktion eq "cos") {
     $intfakt=1;
     $intfunkt="sin";  }

# Endgültiger Vorfaktor der Stammfunktion

$intfakt=$intfakt*$fakt/$argfakt;

# Richtiges Ergebnis

$integral="$intfakt*$intfunkt($argfakt*$var)+ C";</script>

<startouttext />Bestimmen Sie folgende Stammfunktion. Bezeichnen Sie die 
Integrationskonstante mit C.
<br> </br>
<m eval="on"> \int ( \, $fakt \, $funktion  (  $argfakt*$var)   )   \, 
d$var </m>
<br> </br><endouttext />

<formularesponse samples="x,z,t,C@-3,-3,-3,-3;2,2,2,2#4" 
answer="$integral" id="11">
     <responseparam name="tol" type="tolerance" default="0.00001" 
description="Numerical Tolerance" />
     <textline readonly="no" size="25" />
</formularesponse>
</problem>
-- 
Peter Riegler
Fachhochschule Braunschweig/Wolfenbüttel
Salzdahlumer Str. 46/48, 38302 Wolfenbüttel
Tel. +49 5331 939 6314, Fax. +49 5331 939 6002
email: [email-masked]
http://public.rz.fh-wolfenbuettel.de/~riegler

---

From: Guy Albertelli II <[email-masked]>
Date: Tue, 22 May 2007 14:57:58 -0400 (EDT)

Hi Peter,

Looks like a typo.

>         if not break out of the for loops and return false

Yes, it should, however you have a ; where you want a :

x,y@-3,-3,;2,2#4

Will sample at x=-3,y=-3, and x=2,y=2

x,y@-3,-3:2,2#4

Will sample at 4 random points in the box defined by -3 <= x <= 2, and
-3 <= y <= 2

> answer="$integral" id="11">

and similarly here there is a ; where you likely want a :
-- 
[email-masked]   0-7-0-9-27,137

---

From: Peter Riegler <[email-masked]>
Date: Wed, 23 May 2007 10:32:18 +0200

Hi Guy,

argh, shame on me!

Thanks!

Peter

PS: Funny though that wrong responses are graded as correctly ...

---

From: Guy Albertelli II <[email-masked]>
Date: Wed, 23 May 2007 12:51:19 -0400 (EDT)

Hi Peter,

> PS: Funny though that wrong responses are graded as correctly ...

If I sample at x=2,y=2

sin(x) == sin(y)

Doesn't it?

> Fachhochschule Braunschweig/Wolfenb?ttel
> Salzdahlumer Str. 46/48, 38302 Wolfenb?ttel
> _______________________________________________
> LON-CAPA-dev mailing list
> [email-masked]
> http://mail.lon-capa.org/mailman/listinfo/lon-capa-dev
>

---

From: Peter Riegler <[email-masked]>
Date: Thu, 24 May 2007 10:02:48 +0200

>>PS: Funny though that wrong responses are graded as correctly ...

Ehm, I think so.
Sorry, sometimes I need to be told twice.
I was still under the impression that code wise we have nested loops 
here. But your statement
 >>>Will sample at x=-3,y=-3, and x=2,y=2
makes it clear that we have a single "loop"

---

From: Gerd Kortemeyer <[email-masked]>
Date: Thu, 24 May 2007 08:13:54 -0400

Hi,

>> PS: Funny though that wrong responses are graded as correctly ...

Now I am confused. When specifying (x,y) to be between (-3,-3) and  
(2,2), is the system only running along the diagonal, i.e., something  
like

(-3,-3), (-1.7,-1.7), (0.5,0.5), (1.8,1.8)

?

- Gerd.

---

From: Guy Albertelli II <[email-masked]>
Date: Thu, 24 May 2007 15:19:40 -0400 (EDT)

Hi Gerd,

> (2,2), is the system only running along the diagonal, i.e., something  

No.

To recap
- the original example accidently used ; rather :
- this meant that it did NOT define a box to sample inside of
- it did define two points (and only two) to sample at specifically
   2,2 and -3-,3