[system] / trunk / pg / macros / PGdiffeqmacros.pl Repository:
ViewVC logotype

Diff of /trunk/pg/macros/PGdiffeqmacros.pl

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

Revision 4318 Revision 4997
1#163macros.pl 1
2=head1 PGdiffeqmacros.pl DESCRIPTION
3
2#macros for Prills 163 problems 4# Macros for Prills 163 problems
5
6=cut
3 7
4#!/usr/bin/perl -w 8#!/usr/bin/perl -w
5#use strict; 9#use strict;
6#use Carp; 10#use Carp;
7BEGIN { 11BEGIN {
25#this line defines the input arguments as local variables 29#this line defines the input arguments as local variables
26 my $R = $S *$U -$T * $V; 30 my $R = $S *$U -$T * $V;
27 my $I = $S *$V + $T * $U ; 31 my $I = $S *$V + $T * $U ;
28 ($R,$I) ;#this returns ($R,$I) from the subroutine 32 ($R,$I) ;#this returns ($R,$I) from the subroutine
29} 33}
34
35=head3 addtwo($1stAddend,$1stIndicator,$2ndAddend,$2ndIndicator)
36
30########## 37##########
31#sub addtwo adds two strings formally 38# sub addtwo adds two strings formally
32#An "indicator" for a string is a 39# An "indicator" for a string is a
33# number ,e.g. coefficient,which indicates 40# number ,e.g. coefficient,which indicates
34#whether the string is to be 41# whether the string is to be
35#added or is to be regarded as zero. 42# added or is to be regarded as zero.
36#The non-zero terms are formally added as strings. 43# The non-zero terms are formally added as strings.
37#The input is an array 44# The input is an array
38#($1staddend, $1stindicator,$2ndaddend,$2ndindicator) 45# ($1staddend, $1stindicator,$2ndaddend,$2ndindicator)
39#The return is an array 46# The return is an array
40#(formal sum, indicator of formal sum) 47# (formal sum, indicator of formal sum)
48
49=cut
41 50
42sub addtwo { 51sub addtwo {
43 my ($A,$a,$B,$b) = @_; 52 my ($A,$a,$B,$b) = @_;
44 my $out = "0"; 53 my $out = "0";
45 if ($a != 0) { 54 if ($a != 0) {
55 } 64 }
56 } 65 }
57 my $ind = abs($a) + abs($b); 66 my $ind = abs($a) + abs($b);
58 ($out,$ind); 67 ($out,$ind);
59} 68}
69
70=head3 add($1stAddend,$1stIndicator,$2ndAddend,$2ndIndicator,...)
71
60######## 72########
61
62#sub add generalizes sub addtwo to more addends. 73# sub add generalizes sub addtwo to more addends.
63#It formally adds the nonzero terms. 74# It formally adds the nonzero terms.
64# The input is an array of even length 75# The input is an array of even length
65# consisting of each addend,a string, 76# consisting of each addend,a string,
66# followed by its indicator. 77# followed by its indicator.
78
79=cut
67 80
68sub add { 81sub add {
69 # this function takes the first two terms, puts them together, and keep repeating until you have emptied the list. 82 # this function takes the first two terms, puts them together, and keep repeating until you have emptied the list.
70 my @sum = ("0" ,0); 83 my @sum = ("0" ,0);
71 my @list = @_; 84 my @list = @_;
79 @sum = addtwo(@sum); 92 @sum = addtwo(@sum);
80 $el = @list; 93 $el = @list;
81 } 94 }
82 @sum ; 95 @sum ;
83} 96}
97
98=head3 diffop($a,$b,$c)
99
84####### 100#######
85
86# sub diffop cleans up the typed expression 101# sub diffop cleans up the typed expression
87#of a diff. operator. 102# of a diff. operator.
88#input @diffop =($A,$B,$C) is the coefficients. 103# input @diffop =($A,$B,$C) is the coefficients.
89#input is given as arguments viz difftop($A,$B,$C); 104# input is given as arguments viz difftop($A,$B,$C);
90#output is the diff. operator as a string $L in TEX 105# output is the diff. operator as a string $L in TEX
106
107=cut
91 108
92sub diffop 109sub diffop
93{ 110{
94 my ($A,$B,$C) = @_ ; 111 my ($A,$B,$C) = @_ ;
95 my ($LDD, $LD ,$LF) = ($A."y'' ",$B."y' ",$C."y "); 112 my ($LDD, $LD ,$LF) = ($A."y'' ",$B."y' ",$C."y ");
115 } 132 }
116 my ($L,$ind) = add($LDD,$A,$LD,$B,$LF,$C); 133 my ($L,$ind) = add($LDD,$A,$LD,$B,$LF,$C);
117 $L; 134 $L;
118} 135}
119 136
137=head3 rad($num1,$num2,$num3)
138
120######## 139########
121
122#sub rad simplifies (a/b)*(sqrt(c)) 140# sub rad simplifies (a/b)*(sqrt(c))
123#input is given as arguments on rad viz.: rad($a,$b,$c); 141# input is given as arguments on rad viz.: rad($a,$b,$c);
124#$a,$b,$c are integers and $c>=0 and $b is not zero. 142# $a,$b,$c are integers and $c>=0 and $b is not zero.
125#output is an array =(answer as string,new$a,new$b, new$c) 143# output is an array =(answer as string,new$a,new$b, new$c)
144
145=cut
126 146
127sub rad{ 147sub rad{
128 # initalize primes 148 # initalize primes
129 my @p = (2,3,5,7,11,13,17,19,23,29); 149 my @p = (2,3,5,7,11,13,17,19,23,29);
130 my ($a,$b,$c) = @_; 150 my ($a,$b,$c) = @_;
220 root => $c}; 240 root => $c};
221 $rh_hash; 241 $rh_hash;
222 242
223} 243}
224 244
225####### 245##########
226sub frac { 246sub frac {
227 # use rad subroutine 247 # use rad subroutine
228 my ($a,$b) = @_; 248 my ($a,$b) = @_;
229 rad($a,$b,1); 249 rad($a,$b,1);
230} 250}
231########## 251##########
232 252
253=head3 simpleexp($r,$ind)
254
233#### 255####
234#sub exp simplifies exp($r*t) in form for writing perl 256# sub exp simplifies exp($r*t) in form for writing perl
235#or tex.The input is exp($r,$ind); $ind indicates whether 257# or tex. The input is exp($r,$ind); $ind indicates whether
236#we want perl or tex mode.$r is a string that represents 258# we want perl or tex mode. $r is a string that represents
237#a number. 259# a number.
238#If $ind = 0 output is "exp(($r)*t)", simplified if possible. 260# If $ind = 0 output is "exp(($r)*t)", simplified if possible.
239#If $ind = 1 output is "exp(($r) t)", simplified if possible. 261# If $ind = 1 output is "exp(($r)*t)", simplified if possible.
262
263=cut
264
240sub simpleexp { 265sub simpleexp {
241 my $r = shift; 266 my $r = shift;
242 my @rr = @_; 267 my @rr = @_;
243 my %options; 268 my %options;
244 if ($rr[0] eq 'mode') { 269 if ($rr[0] eq 'mode') {
340 my $rr2 = simpleexp($r2,0); # rr2 = e^r2 = e^(-B/(2A)) 365 my $rr2 = simpleexp($r2,0); # rr2 = e^r2 = e^(-B/(2A))
341 $answer = "($c1) *($rr1)*($cs1) + ($c2) *($rr2)*($cs2)"; 366 $answer = "($c1) *($rr1)*($cs1) + ($c2) *($rr2)*($cs2)";
342 } 367 }
343 $answer; 368 $answer;
344} 369}
370
345 371
346############ 372############
347#sub ivy solves the initial value problem 373#sub ivy solves the initial value problem
348# $a*y'' + $b*y' + $c*y = 0, with y(0) = $m, y'(0) = $n 374# $a*y'' + $b*y' + $c*y = 0, with y(0) = $m, y'(0) = $n
349 375
454 my $outc = $addc[0]; 480 my $outc = $addc[0];
455 my $y = "( $outc ) * $exp" ; 481 my $y = "( $outc ) * $exp" ;
456 } 482 }
457 483
458} 484}
485
486=head3 undeterminedSin($A,$B,$C,$r,$w,$q1,$q0,$r1,$r0)
487
459################# 488#################
460
461# undeterminedSin is a subroutine to solve 489# undeterminedSin is a subroutine to solve
462#undetermined coefficient problems that have 490# undetermined coefficient problems that have
463#sines and cosines. 491# sines and cosines.
464#The input is an array ($A,$B,$C,$r,$w,$q1,$q0,$r1,$r0) 492# The input is an array ($A,$B,$C,$r,$w,$q1,$q0,$r1,$r0)
465#given as arguments on undeterminedSin 493# given as arguments on undeterminedSin
466# $L =$A y'' + $B y' + $C y 494# $L =$A y'' + $B y' + $C y
467# $rhs = ($q1 t + $q0) cos($w t)exp($r t) + 495# $rhs = ($q1 t + $q0) cos($w t)exp($r t) +
468# ($r1 t + $r0) sin($w t)exp($r t) 496# ($r1 t + $r0) sin($w t)exp($r t)
469#The subroutine uses undetermined coefficients 497# The subroutine uses undetermined coefficients
470#to find a solution $y of $L = $rhs . 498# to find a solution $y of $L = $rhs .
471#The output \is $y 499# The output \is $y
500
501=cut
472 502
473sub undeterminedSin { 503sub undeterminedSin {
474 my ($A,$B,$C,$r,$w,$q1,$q0,$r1,$r0) = @_; 504 my ($A,$B,$C,$r,$w,$q1,$q0,$r1,$r0) = @_;
475 my $Pr = ($A*$r*$r) + $B *$r + $C; 505 my $Pr = ($A*$r*$r) + $B *$r + $C;
476 my $PPr = (2*$A *$r ) + $B ; 506 my $PPr = (2*$A *$r ) + $B ;

Legend:
Removed from v.4318  
changed lines
  Added in v.4997

aubreyja at gmail dot com
ViewVC Help
Powered by ViewVC 1.0.9