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

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

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 219 Revision 293
52# Without this prototype you would have to write 1+3*i(); 52# Without this prototype you would have to write 1+3*i();
53# The prototype has to be defined at compile time, but dangerousMacros.pl is complied first. 53# The prototype has to be defined at compile time, but dangerousMacros.pl is complied first.
54#Complex1::display_format('cartesian'); 54#Complex1::display_format('cartesian');
55 55
56 56
57 57=head4 polar
58 Usage polar($complex_number,r_format=>"%0.3f",theta_format=>"%0.3f")
59
60 Output is text displaying the complex number in "e to the i theta" form. The
61 formats for the argument theta is determined by the option C<theta_format> and the
62 format for the modulus is determined by the C<r_format> option.
63
64
58 65
59sub polar{ 66sub polar{
60 my $z = shift; 67 my $z = shift;
61 my %options = @_; 68 my %options = @_;
69 set_default_options(\%options, r_format => ':%0.3f',
70 theta_format => ':%0.3f',
71 );
62 my $r = rho($z); 72 my $r = rho($z);
63 my $theta = $z->theta; 73 my $theta = $z->theta;
64 my $r_format = ':%0.3f'; 74 $r_format=":" . $options{r_format};
65 my $theta_format = ':%0.3f'; 75 $theta_format = ":" . $options{theta_format});
66 $r_format=":" . $options{r_format} if defined($options{r_format});
67 $theta_format = ":" . $options{theta_format} if defined($options{theta_format});
68 "{$r$r_format} e^{i {$theta$theta_format}}"; 76 "{$r$r_format} e^{i {$theta$theta_format}}";
69 77
70} 78}
71 79
72sub cplx_cmp { 80sub cplx_cmp {
73 my $correctAns = shift; 81 my $correctAns = shift;
75 $correctAns = cplx($correctAns,0) unless ref($correctAns) =~/Complex/; 83 $correctAns = cplx($correctAns,0) unless ref($correctAns) =~/Complex/;
76 assign_option_aliases( \%options, 84 assign_option_aliases( \%options,
77 'reltol' => 'relTol', 85 'reltol' => 'relTol',
78 ); 86 );
79 set_default_options(\%options, 87 set_default_options(\%options,
80 'tolType' => (defined($options{tol}) ) ? 'absolute' : 'relative', 88 'tolType' => (defined($options{tol}) ) ? 'absolute' : 'relative',
81 # default mode should be relative, to obtain this tol must not be defined 89 # default mode should be relative, to obtain this tol must not be defined
82 'tol' => $main::numAbsTolDefault, 90 'tol' => $main::numAbsTolDefault,
83 'relTol' => $main::numRelPercentTolDefault, 91 'relTol' => $main::numRelPercentTolDefault,
84 'zeroLevel' => $main::numZeroLevelDefault, 92 'zeroLevel' => $main::numZeroLevelDefault,
85 'zeroLevelTol' => $main::numZeroLevelTolDefault, 93 'zeroLevelTol' => $main::numZeroLevelTolDefault,
86 'format' => $main::numFormatDefault, 94 'format' => $main::numFormatDefault,
87 'debug' => 0, 95 'debug' => 0,
88 96
89 ); 97 );
90 98
91 99
92 my $ans_eval = sub { 100 my $ans_eval = sub {
93 my $in = shift; 101 my $in = shift;
94 my $rh_ans = new AnswerHash; 102 my $rh_ans = new AnswerHash;
95 $rh_ans->{correct_ans} = $correctAns; 103 $rh_ans->{correct_ans} = $correctAns;
96 unless (defined($in) and $in =~/\S/ ) { #bail on empty answer 104 unless (defined($in) and $in =~/\S/ ) { #bail on empty answer
97 $rh_ans->{student_ans} = "error: empty"; 105 $rh_ans->{student_ans} = "error: empty";
98 return $rh_ans; 106 return $rh_ans;
99 } 107 }

Legend:
Removed from v.219  
changed lines
  Added in v.293

aubreyja at gmail dot com
ViewVC Help
Powered by ViewVC 1.0.9