Diff for /loncom/homework/default_homework.lcpm between versions 1.28 and 1.36

version 1.28, 2001/06/14 21:29:14 version 1.36, 2001/08/23 16:44:22
Line 13  $rad2deg=180.0/$pi; Line 13  $rad2deg=180.0/$pi;
 $deg2rad=$pi/180.0;  $deg2rad=$pi/180.0;
   
 sub caparesponse_check {  sub caparesponse_check {
   my $answer='';  #done    #not properly used yet: calc
   my $type='';    #done    #not to be used: $ans_fmt
     my ($answer,$type,$tol,$sig,$ans_fmt,$unit,$calc) = 
    eval $_[1].';return ($answer,$type,$tol,$sig,$ans_fmt,$unit,$calc);';
   
   my $tol_type=''; # gets it's value from whether tol has a % or not done    my $tol_type=''; # gets it's value from whether tol has a % or not done
   my $tol='';     #done  
   my $sig='';     #done lowerbnd,upperbnd  
   my $sig_lbound=''; #done    my $sig_lbound=''; #done
   my $sig_ubound=''; #done    my $sig_ubound=''; #done
   my $ans_fmt='';  
   my $units='';     #done  
   my $calc='';  
   my ($response,$expr)=@_;    my ($response,$expr)=@_;
     
   ($answer,$type,$tol,$sig,$ans_fmt,  
    $units,$calc) = eval $expr.';return $answer,$type,$tol,$sig,$ans_fmt,$units,$calc';  
   #type's definitons come from capaParser.h    #type's definitons come from capaParser.h
     my $message='';
     #remove leading and trailing whitespace
     if ($response=~ /^\s|\s$/) {
       $response=~ s:^\s+|\s+$::g;
       $message .="Removed ws now :$response:<br />";
     } else {
       $message .="no ws in :$response:<br />";
     }
   
   if ($type eq '' ) {    if ($type eq '' ) {
       $message .= "Didn't find a type :$type:$expr: defaulting<br />";
     if ( $answer eq ($answer *1.0)) { $type = 2;      if ( $answer eq ($answer *1.0)) { $type = 2;
     } else { $type = 3; }      } else { $type = 3; }
   } else {    } else {
Line 61  sub caparesponse_check { Line 68  sub caparesponse_check {
   my $result = &caparesponse_capa_check_answer($response,$answer,$type,    my $result = &caparesponse_capa_check_answer($response,$answer,$type,
        $tol_type,$tol,         $tol_type,$tol,
        $sig_lbound,$sig_ubound,         $sig_lbound,$sig_ubound,
        $ans_fmt,$units,$calc);         $ans_fmt,$unit,$calc);
   
   if    ($result == '1') { $result='EXACT_ANS'; }     if    ($result == '1') { $result='EXACT_ANS'; } 
   elsif ($result == '2') { $result='APPROX_ANS'; }    elsif ($result == '2') { $result='APPROX_ANS'; }
Line 77  sub caparesponse_check { Line 84  sub caparesponse_check {
   elsif ($result =='12') { $result='WANTED_NUMERIC'; }    elsif ($result =='12') { $result='WANTED_NUMERIC'; }
   else  {$result = "ERROR: Unknown Result:$result:$@:";}    else  {$result = "ERROR: Unknown Result:$result:$@:";}
   
   return "$result:<br />Error $error:<br />Answer $answer:<br />Response $response:<br />$type|$tol|$tol_type|$sig:$sig_lbound:$sig_ubound|$units<br />";    return "$result:<br />Error $error:<br />Answer $answer:<br />Response $response:<br /> type-$type|$tol|$tol_type|$sig:$sig_lbound:$sig_ubound|$unit|<br />$message$expr";
 }  }
   
 sub caparesponse_check_list {  sub caparesponse_check_list {
   my ($response,$expr)=@_;    my ($response,$expr)=@_;
     # do these first, because who knows what varname the instructor might have used
     # but it probably isn't $CAPARESPONSE_CHECK_LIST_answer
     my $CAPARESPONSE_CHECK_LIST_answer = eval $expr.';return $answer';
     my (@list) = eval $CAPARESPONSE_CHECK_LIST_answer;
   my $result='';    my $result='';
     $result.="error:$@:<br />";
     # if the eval fails just use what is in the answer exactly
     if (!defined(@list) || !defined($list[0])) {
       $result.="list zero is undefined<br />";
       $list[0]=$CAPARESPONSE_CHECK_LIST_answer;
     }
   my $aresult='';    my $aresult='';
   my $current_answer;    my $current_answer;
   my $answer = eval $expr.';return $answer';    $result.="Got response :$CAPARESPONSE_CHECK_LIST_answer:$list[0]:<br />";
   my (@list) = eval $answer;    my @responselist;
   my (@responselist)=split /,/,$response;    my $type =eval $expr.';return $answer;';
     if ($type ne '' && $#list > 0) {
       (@responselist)=split /,/,$response;
     } else {
       (@responselist)=($response);
     }
   my $unit='';    my $unit='';
   $result.="Final response :$responselist['-1']:<br />";    $result.="Initial final response :$responselist['-1']:<br />";
   if ( $responselist['-1']=~ /(.*[^\s])\s+([^\s]+)/ ) {    if ($type eq '') {
     $responselist['-1']=$1;      #for numerical problems split off the unit
     $unit=$2;      if ( $responselist['-1']=~ /(.*[^\s])\s+([^\s]+)/ ) {
         $responselist['-1']=$1;
         $unit=$2;
       }
   }    }
   $result.="Final response :$responselist['-1']:<br />";    $result.="Final final response :$responselist['-1']:<br />";
     $result.=":$#list: answers<br />";
   $unit=~s/\s//;    $unit=~s/\s//;
   my $i=0;    my $i=0;
   my $awards='';    my $awards='';
   for ($i=0; $i<@list;$i++) {    for ($i=0; $i<@list;$i++) {
       $result.="trying answer :$list[$i]:<br />";
     if ($unit eq '') {      if ($unit eq '') {
       $aresult=&caparesponse_check($responselist[$i],        $aresult=&caparesponse_check($responselist[$i],
      $expr.';my $answer='.$list[$i].';');       $expr.';my $answer=\''.$list[$i].'\';');
     } else {      } else {
       $aresult=&caparesponse_check($responselist[$i]." $unit",        $aresult=&caparesponse_check($responselist[$i]." $unit",
    $expr.';my $answer='.$list[$i].';');     $expr.';my $answer=\''.$list[$i].'\';');
     }      }
     my ($temp)=split /:/, $aresult;      my ($temp)=split /:/, $aresult;
     $awards.="$temp,";      $awards.="$temp,";
Line 237  sub random_noncentral_f { Line 264  sub random_noncentral_f {
 }  }
   
 sub random_multivariate_normal {  sub random_multivariate_normal {
   my ($item_cnt,$seed,@mean) = @_;    my ($item_cnt,$seed,$mean,$covar) = @_;
   return "Number of deviates must be greater than 0" if $item_cnt <= 0;  
   my (@covar,@retArray);  
   my $ind = 0;  
   while ($ind<$item_cnt) {  
      push @covar, pop (@mean);  
      $ind++;  
   }  
   &random_set_seed_from_phrase($seed);    &random_set_seed_from_phrase($seed);
   @retArray=&math_random_multivariate_normal($item_cnt,@mean,@covar);    @retArray=&math_random_multivariate_normal($item_cnt,@$mean,@$covar);
   return @retArray;    return @retArray;
 }  }
   

Removed from v.1.28  
changed lines
  Added in v.1.36


FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>