[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 320 Revision 321
5#################################################################### 5####################################################################
6# Copyright @ 1995-2001 The WeBWorK Team 6# Copyright @ 1995-2001 The WeBWorK Team
7# All Rights Reserved 7# All Rights Reserved
8#################################################################### 8####################################################################
9#$Id$ 9#$Id$
10
11
12
13
14
15
16
10 17
11 18
12=head1 NAME 19=head1 NAME
13 20
14 Macros for complex numbers for the PG language 21 Macros for complex numbers for the PG language
25BEGIN{ 32BEGIN{
26 be_strict(); 33 be_strict();
27 34
28} 35}
29sub _PGcomplexmacros_init { 36sub _PGcomplexmacros_init {
30} 37
31# export functions from Complex1. 38# export functions from Complex1.
32 39
33foreach my $f (@Complex1::EXPORT) { 40 foreach my $f (@Complex1::EXPORT) {
34 #PG_restricted_eval("\*$f = \*Complex1::$f"); # this is too clever -- 41 #PG_restricted_eval("\*$f = \*Complex1::$f"); # this is too clever --
35 # the original subroutines are destroyed 42 # the original subroutines are destroyed
36 next if $f eq 'sqrt'; #exporting the square root caused conflicts with the standard version 43 next if $f eq 'sqrt'; #exporting the square root caused conflicts with the standard version
37 # You can still use Complex1::sqrt to take square root of complex numbers 44 # You can still use Complex1::sqrt to take square root of complex numbers
38 next if $f eq 'log'; #exporting loq caused conflicts with the standard version 45 next if $f eq 'log'; #exporting loq caused conflicts with the standard version
39 # You can still use Complex1::log to take square root of complex numbers 46 # You can still use Complex1::log to take square root of complex numbers
40 47
41 my $string = qq{ 48 my $string = qq{
42 sub main::$f { 49 sub main::$f {
43 &Complex1::$f; 50 &Complex1::$f;
44 } 51 }
45 }; 52 };
46 PG_restricted_eval($string); 53 PG_restricted_eval($string);
54 }
47} 55}
48 56
49# You need to add 57# You need to add
50# sub i(); # to your problem or else to dangerousMacros.pl 58# sub i(); # to your problem or else to dangerousMacros.pl
51# in order to use expressions such as 1 +3*i; 59# in order to use expressions such as 1 +3*i;
53# The prototype has to be defined at compile time, but dangerousMacros.pl is complied first. 61# The prototype has to be defined at compile time, but dangerousMacros.pl is complied first.
54#Complex1::display_format('cartesian'); 62#Complex1::display_format('cartesian');
55 63
56 64
57=head4 polar 65=head4 polar
66
58 Usage polar($complex_number,r_format=>"%0.3f",theta_format=>"%0.3f") 67 Usage polar($complex_number,r_format=>"%0.3f",theta_format=>"%0.3f")
59 68
60 Output is text displaying the complex number in "e to the i theta" form. The 69 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 70 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. 71 format for the modulus is determined by the C<r_format> option.
63 72
64 73=cut
74
65 75
66sub polar{ 76sub polar{
67 my $z = shift; 77 my $z = shift;
68 my %options = @_; 78 my %options = @_;
69 set_default_options(\%options, r_format => ':%0.3f', 79 set_default_options(\%options, r_format => ':%0.3f',
70 theta_format => ':%0.3f', 80 theta_format => ':%0.3f',
71 ); 81 );
72 my $r = rho($z); 82 my $r = rho($z);
73 my $theta = $z->theta; 83 my $theta = $z->theta;
74 $r_format=":" . $options{r_format}; 84 my $r_format=":" . $options{r_format};
75 $theta_format = ":" . $options{theta_format}); 85 my $theta_format = ":" . $options{theta_format});
76 "{$r$r_format} e^{i {$theta$theta_format}}"; 86 "{$r$r_format} e^{i {$theta$theta_format}}";
77 87
78} 88}
79 89
80sub cplx_cmp { 90sub cplx_cmp {

Legend:
Removed from v.320  
changed lines
  Added in v.321

aubreyja at gmail dot com
ViewVC Help
Powered by ViewVC 1.0.9