# [LON-CAPA-users] formula response question

Stefan Bisitz lon-capa-users@mail.lon-capa.org
Sun, 22 Feb 2009 16:08:54 +0000 (GMT)

Hi James,

something else I recognized is the following part of your code:
> $b=0;$d=0; while($b==0 ||$d==0){$b=&random(-10,10,1);$d=&random(-10,10,1);}
> $a=-1*$b/$d; while($a==-1*$b/$d){$a=&random(1,10,1);} It is recommended to avoid such loops, especially to create random variables. Can you asure that this will a) always properly terminate? b) not run to long under special random circumstences? The first loop$b=0; $d=0; while($b==0 || $d==0){$b=&random(-10,10,1);$d=&random(-10,10,1);} could be easily substituted by$b=&random(-1,1,2)*&random(1,10,1);$d=&random(-1,1,2)*&random(1,10,1); to get random numbers between -10 and +10 but without zero. The second loop is more tricky, but there should be solutions to avoid it, too. Stefan Bisitz On 22.02.09, Peter Riegler <p.riegler@fh-wolfenbuettel.de> wrote: > Hi, > > I have tested your code on my 2.8 server: > The problem is related to the +-2 in >$solution=7*exp(2*x)+-2*exp(-1*-7/4*x) .
> So you should write
> $solution="$M1*exp($d*x)+($M2)*exp(-1*$b/$a*x)
> in your script. Note the parentheses around $M2. > I can't explain that to you perlwise because "...+-2*..." is legal perl. > As your script is written$M2 becomes negative very infrequently, hence you don't encounter such problems often.
>
> Peter
>
> James Mueller wrote:
> >A student in a calculus course is entering an answer to a formula  response problem and keeps getting "Unable to understand formula" even  when they enter something simple like "x" for their answer.  The rest  of the students are reported to be not having troubles.  I assumed it  must be some problem with the script tat was triggered by the numbers  used for this particular problem.  After a quick look, I can't see  anything, but I have to admit my perl is rusty.  Anybody else se  anything?
> >
> >The script is
> >
> ><problem>
> ><meta name="isbasedontime" content="1235265561" />
> ><meta name="isbasedonres" content="\%2fres\%2fpitt\%2fathanas\%2fc2\ %2ddiffeq\%2d21\%2eproblem" />
> >    <script type="loncapa/perl">
> >$b=0;$d=0; while($b==0 ||$d==0){$b=&random(-10,10,1);$d=&random(-10,10,1);}
> >$a=-1*$b/$d; while($a==-1*$b/$d){$a=&random(1,10,1);} > >$c=&random(1,10,1); $i=&random(1,50,1); > >if($b<0){$s=" ";} if($b>0){$s="+";} > >$M1=$c/($a*$d+$b); $M2=$i-$M1; > >$solution="$M1*exp($d*x)+$M2*exp(-1*$b/$a*x) "; > > </script> > > <startouttext /> > ><br /> > >Determine the solution to the initial value differential equation <m eval="on"> $a y' s b y = c e^{d x} \hspace{.2in} y ( 0 )= i$</m> > ><endouttext /> > > > ><p /> > ><startouttext /><m>$ y ( x ) =  $</m><endouttext /> > ><formularesponse samples="x@1:3#4" answer="$solution" id="11">
> ><responseparam name="tol" default="0.001" type="tolerance"  description="Numerical Tolerance" />
> >        <textline readonly="no" size="35" />
> >    </formularesponse>
> ></problem>
> >
> >And the students variables for this problem are
> >
> >$M1=7 > >$M2=-2
> >$a=4 > >$b=-7
> >$c=7 > >$d=2
> >$deg2rad=0.0174532925199433 > >$i=5
> >$pi=3.14159265358979 > >$rad2deg=57.2957795130823
> >$s= > >$solution=7*exp(2*x)+-2*exp(-1*-7/4*x)
> >
> >
> >
> >
> >_______________________________________________
> >LON-CAPA-users mailing list
> >LON-CAPA-users@mail.lon-capa.org
> >http://mail.lon-capa.org/mailman/listinfo/lon-capa-users (http://mail.lon-capa.org/mailman/listinfo/lon-capa-users)
>
> --
> Peter Riegler
> Fachhochschule Braunschweig/Wolfenbüttel
> Salzdahlumer Str. 46/48, 38302 Wolfenbüttel
> Tel. +49 5331 939 6314, Fax. +49 5331 939 6002
> email: p.riegler@fh-wolfenbuettel.de
> http://public.rz.fh-wolfenbuettel.de/~riegler (http://public.rz.fh-wolfenbuettel.de/~riegler)
> _______________________________________________
> LON-CAPA-users mailing list
> LON-CAPA-users@mail.lon-capa.org
> http://mail.lon-capa.org/mailman/listinfo/lon-capa-users (http://mail.lon-capa.org/mailman/listinfo/lon-capa-users)
>
>