[system] / trunk / webwork / system / courseScripts / PGcomplexmacros.pl Repository:
ViewVC logotype

View of /trunk/webwork/system/courseScripts/PGcomplexmacros.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 58 - (download) (as text) (annotate)
Fri Jun 22 19:38:28 2001 UTC (18 years, 3 months ago) by gage
File size: 2003 byte(s)
Corrected the #!/usr/local/bin/webwork-perl
line

    1 #!/usr/local/bin/webwork-perl
    2 BEGIN{
    3   be_strict();
    4   sub i();
    5 }
    6 
    7 foreach my $f (@Complex1::EXPORT) {
    8     PG_restricted_eval("\*$f = \*Complex1::$f");
    9 }
   10 
   11 # You need to add
   12 # sub i();  # to your problem or else to dangerousMacros.pl
   13 # in order to use expressions such as 1 +3*i;
   14 # Without this prototype you would have to write 1+3*i();
   15 # The prototype has to be defined at compile time, but dangerousMacros.pl is complied first.
   16 #Complex1::display_format('cartesian');
   17 
   18 sub polar{
   19   my $z = shift;
   20   my %options = @_;
   21     my $r = rho($z);
   22     my $theta = $z->theta;
   23     my $r_format = ':%0.3f';
   24     my $theta_format = ':%0.3f';
   25     $r_format=":" . $options{r_format} if defined($options{r_format});
   26     $theta_format = ":" . $options{theta_format} if defined($options{theta_format});
   27     "{$r$r_format} e^{i {$theta$theta_format}}";
   28 
   29 }
   30 sub cplx_cmp {
   31   my $correctAns = shift;
   32   my %options = @_;
   33   $correctAns = cplx($correctAns,0) unless ref($correctAns) =~/Complex/;
   34     set_default_options(\%options,
   35               reltol  =>  .01
   36     );
   37     my $tol = .01*$options{reltol};
   38   my $ans_eval = sub {
   39                my $in = shift;
   40          my $rh_ans = new AnswerHash;
   41          my($PG_errors,$PG_errors_long);
   42          $rh_ans->{correct_ans} = $correctAns;
   43                  $rh_ans->input($in);
   44                  $rh_ans=check_syntax($rh_ans);
   45                  $rh_ans->{student_ans} =~ s/e\^/exp /g;  #try to handle exponents
   46                  $rh_ans->{student_ans} =~ s/-\s*i/-1*i/g;  #try to keep -i being recognized as a file reference
   47          ($in,$PG_errors,$PG_errors_long) = PG_restricted_eval($rh_ans->{student_ans});
   48          if ($PG_errors_long) {
   49           $rh_ans->{error}=1;
   50           $rh_ans->{ans_message} = $PG_errors;
   51          } else {
   52            $in->display_format('cartesian') if ref($in) =~/Complex/;
   53            $rh_ans->{student_ans}="$in";
   54                    $rh_ans->{score} =  (abs($in - $correctAns)<$tol*abs($correctAns) )? 1:0;
   55 
   56                }
   57                  $rh_ans;
   58                  };
   59     $ans_eval;
   60 }
   61 
   62 1;

aubreyja at gmail dot com
ViewVC Help
Powered by ViewVC 1.0.9