[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 91 Revision 219
1#!/usr/local/bin/perl 1#!/usr/local/bin/webwork-perl
2# This file is PGcomplexmacros.pl
3# This includes the subroutines for the ANS macros, that
4# is, macros allowing a more flexible answer checking
5####################################################################
6# Copyright @ 1995-2001 The WeBWorK Team
7# All Rights Reserved
8####################################################################
9#$Id$
10
11
12=head1 NAME
13
14 Macros for complex numbers for the PG language
15
16=head1 SYNPOSIS
17
18
19
20=head1 DESCRIPTION
21
22=cut
23
24
2BEGIN{ 25BEGIN{
3 be_strict(); 26 be_strict();
4 27
28}
29sub _PGcomplexmacros_init {
5} 30}
6# export functions from Complex1. 31# export functions from Complex1.
7 32
8foreach my $f (@Complex1::EXPORT) { 33foreach my $f (@Complex1::EXPORT) {
9 #PG_restricted_eval("\*$f = \*Complex1::$f"); # this is too clever -- 34 #PG_restricted_eval("\*$f = \*Complex1::$f"); # this is too clever --
10 # the original subroutines are destroyed 35 # the original subroutines are destroyed
11 next if $f eq 'sqrt'; #exporting the square root caused conflicts with the standard version 36 next if $f eq 'sqrt'; #exporting the square root caused conflicts with the standard version
12 # You can still use Complex1::sqrt to take square root of complex numbers 37 # You can still use Complex1::sqrt to take square root of complex numbers
13 local($main::string) = qq{ 38 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
40
41 my $string = qq{
14 sub main::$f { 42 sub main::$f {
15 &Complex1::$f; 43 &Complex1::$f;
16 } 44 }
17 }; 45 };
18 PG_restricted_eval($main::string); 46 PG_restricted_eval($string);
19} 47}
20 48
21# You need to add 49# You need to add
22# sub i(); # to your problem or else to dangerousMacros.pl 50# sub i(); # to your problem or else to dangerousMacros.pl
23# in order to use expressions such as 1 +3*i; 51# in order to use expressions such as 1 +3*i;
24# Without this prototype you would have to write 1+3*i(); 52# Without this prototype you would have to write 1+3*i();
25# 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.
26#Complex1::display_format('cartesian'); 54#Complex1::display_format('cartesian');
55
56
57
27 58
28sub polar{ 59sub polar{
29 my $z = shift; 60 my $z = shift;
30 my %options = @_; 61 my %options = @_;
31 my $r = rho($z); 62 my $r = rho($z);
35 $r_format=":" . $options{r_format} if defined($options{r_format}); 66 $r_format=":" . $options{r_format} if defined($options{r_format});
36 $theta_format = ":" . $options{theta_format} if defined($options{theta_format}); 67 $theta_format = ":" . $options{theta_format} if defined($options{theta_format});
37 "{$r$r_format} e^{i {$theta$theta_format}}"; 68 "{$r$r_format} e^{i {$theta$theta_format}}";
38 69
39} 70}
71
40sub cplx_cmp { 72sub cplx_cmp {
41 my $correctAns = shift; 73 my $correctAns = shift;
42 my %options = @_; 74 my %options = @_;
43 $correctAns = cplx($correctAns,0) unless ref($correctAns) =~/Complex/; 75 $correctAns = cplx($correctAns,0) unless ref($correctAns) =~/Complex/;
44 assign_option_aliases( \%options, 76 assign_option_aliases( \%options,

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

aubreyja at gmail dot com
ViewVC Help
Powered by ViewVC 1.0.9