[LON-CAPA-users] EXT question

Mark Lucas lon-capa-users@mail.lon-capa.org
Tue, 12 May 2009 15:20:56 -0400


Here is the text of a somewhat extended problem I use. It is found
under /res/ohiou/physlets/momentum/inelastic_collision_zero.problem
It uses the student's latest answer to affect the simulation.

I think what you want to do is ignore the second parameter, if I
remember right.

Mark


<problem>
<script type="loncapa/perl">
$vA=0;
$vB=-&random(2.0,5.0,-0.1);
$tcollision=2.0;
$tfinal = $tcollision-0.2;
$vdB = 0;
$vA2 = &EXT('user.resource.resource.0.11.submission');
$vA2 =~ s/([\d\.+-eE\s]*)(.+)/\1/;
$n = &EXT('user.resource.resource.0.tries');
if ($n>0) {
   $vA = $vA2;
   $tfinal = 15.0;
   $vdB = $vB;
}
$mA=&random(2.0,12.0,0.1);
$mB=$mA*(1+&random(0.15,0.50,0.01)*&random(-1,1,2));
$mB=&roundto($mB,1);
$vf = ($mA*$vA + $mB*$vB)/($mA+$mB);
$vcorrect = -($mB*$vB)/$mA;

$halfwidth=20/20;
$xoffA=-$vA*$tcollision-$halfwidth;
$xoffB=-$vB*$tcollision+$halfwidth;
if ($vdB == 0) {
   $xoffA = -2*$halfwidth;
   $xoffB = 2*$halfwidth;
}

$xA = "($xoffA
+$vA*t)*step($tcollision-t)+step(t-$tcollision)*(-$halfwidth
+($vf*(t-$tcollision)))";
$xB = "($xoffB
+($vdB*t))*step($tcollision-t)+step(t-$tcollision)*($halfwidth
+($vf*(t-$tcollision)))";

</script>
<startouttext />
<web>
<script language="JavaScript"> 
var timerID=0;
var loaded=false;

function initApplets(){
        clearTimeout(timerID);
        loaded=true;
        timerID=setTimeout("initMomentum()",100);
}

function initMomentum(){
        if(!loaded) return;
        
        document.Animator.setAutoRefresh(false); 
        document.Animator.setDefault(); 
        document.Animator.setPixPerUnit(20); 
        document.Animator.shiftPixOrigin(0,0); 
        document.Animator.setGridUnit(5);

        ridA=document.Animator.addObject("rectangle","x=
$xA,y=0.0,h=20,w=40");
        document.Animator.setRGB(ridA,255,0,0);
        ridB=document.Animator.addObject("rectangle","x=
$xB,y=0.0,h=20,w=40");
        document.Animator.setRGB(ridB,0,255,0);

        textA=document.Animator.addObject("text","x=0,y=0,text=A");
        textB=document.Animator.addObject("text","x=0,y=0,text=B");
        document.Animator.setAnimationSlave(ridA,textA);
        document.Animator.setAnimationSlave(ridB,textB);



        document.Animator.setOneShot(0,$tfinal,"End of Animation"); 
        document.Animator.setAutoRefresh(true); 
        document.Animator.forward();
}

function killmenow(){
        window.onerror= function() { return true;}
        clearTimeout(timerID);
                loaded=false;
                timerID=-1;
}
</script>
<p align="center">
<applet vspace="0" width="600" archive="Animator4_.jar,STools4.jar"
align="middle" name="Animator" height="160" mayscript="mayscript"
hspace="0" code="animator4.Animator.class" codebase="../classes">
  <param value="true" name="ShowControls" />
  <param value="0.1" name="dt" />
  <param value="10" name="FPS" />
  <param value="20" name="PixPerUnit" /> 
  <param value="5 name=" GridUnit"='GridUnit"' />
  <param value="initApplets()" name="onLoad" /> 
</applet>
</p>
</web>
<tex>There is an applet associated with this problem which can be viewed
online.</tex>
<p>
The green block(B) has a mass of
<display>&prettyprint($mB,'2f')</display>kg and is moving
to the left at a speed of
<display>&prettyprint(-($vB),'2f')</display>m/s. The red
block (A) has a mass of <display>&prettyprint($mA,'2f')</display>kg and
is moving
to the right. The two blocks undergo a perfectly inelastic collision.
What should the
velocity of the red block be in order to have the two blocks remain at
rest after
the collision?
</p>
<p>When you submit an answer, the animation will show you the collision
using the
initial velocity you selected.</p>
<endouttext />

<numericalresponse answer="$vcorrect" unit="m/s" format="2f" id="11">
	<responseparam name="tol" default="2%" description="Numerical
Tolerance" type="tolerance" />
	<responseparam name="sig" default="0,15" description="Significant
Figures" type="int_range,0-16" />
	<textline />
</numericalresponse>
<allow src="/res/ohiou/physlets/classes/*" />
</problem>





On Tue, 2009-05-12 at 10:15 -0400, Robert_Brewington@er.monroe.edu
wrote:
> Once again, I am trying to use the powerful &EXT construct to retrieve
> information from LonCapa. I think this is supposed to be possible, but
> I can't guess the syntax after a couple of hours.
> 
> The setup:
> 
> Problem1.problem
> <problem>
> <part id="A">
> <numericresponse id="answer">
> ...
> 
> Problem2.problem
> <problem>
> 
> <script>
> $answerFromA = &EXT('user.resource.resource.A.answer.submission',
> 'something goes here');
> </script>
> 
> The script line is my problem - I don't know what to put in the second
> parameter of the EXT call, to retrieve the submitted value of
> A.answer. I know that the enclosing map is given by
> &EXT('resource.map'); how do I navigate to the Problem1.A.answer?
> 
> Thanks for any clues,
> brew
> 
> _______________________________________________ LON-CAPA-users mailing
> list LON-CAPA-users@mail.lon-capa.org
> http://mail.lon-capa.org/mailman/listinfo/lon-capa-users