Skip to content

Commit 6a9cc84

Browse files
committed
Fix bug 4686
1 parent da48052 commit 6a9cc84

File tree

1 file changed

+52
-43
lines changed
  • OpenProblemLibrary/Rochester/setComplexNumbers3RationalFunctions

1 file changed

+52
-43
lines changed

OpenProblemLibrary/Rochester/setComplexNumbers3RationalFunctions/ss_3_1_11d.pg

Lines changed: 52 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -37,60 +37,69 @@ Context("Complex");
3737
#
3838
#
3939

40-
$a = random(-1,10,1);
41-
$b = random(-1,10,1);
40+
$a = Complex(random(-3,8,1));
41+
$b = Complex(random(-3,8,1));
4242

43+
# create
44+
# f = 2z/((z-a)(z-b)) + 2/(z+1) = [2z(z+1) + 2(z-a)(z-b)]/[(z-a)(z-b)(z+1)]
4345

44-
#create two complex roots
45-
$aa = Complex($a, $ai); # Formula("$a + i ($ai)");
46-
$bb = Complex($b, $bi); # Formula("$b + i ($bi)");
46+
$f = Compute("2z/(z^2 - ($a+$b)z + $a*$b) + 2/(z+1)")->reduce;
4747

48-
# calculate quadratic polynomial
49-
$cc = $aa+$bb ;
50-
$dd = $aa*$bb;
51-
$quad = Formula("z^2 - ${cc}z+$dd")->reduce;
48+
# initialize generic answer for use unless special conditions are met
5249

53-
# enter rational function
54-
$f = Formula("2z/(".$quad->string.")+2/(z+1)");
55-
$f->reduce;
50+
$poles_deg1 = List(Complex(-1),Complex($a),Complex($b));
51+
$poles_deg2 = List("none");
52+
$poles_deg3 = List("none");
5653

57-
#calculate pole locations factors
54+
# the special conditions are:
5855

59-
if (($aa == -1)&&($bb == -1))
60-
# Repeated Root of -1
61-
{
62-
$poles_deg1 = List(Formula("none"));
63-
$poles_deg2 = List($bb);
64-
$poles_deg3 = List(Formula("none"));
56+
if ($a==0){ # then f = 2/(z-b) + 2/(z+1)
57+
if ($b == -1) {
58+
$poles_deg1 = List(Complex(-1));
59+
}
60+
else {
61+
$poles_deg1 = List(Complex($b),Complex(-1));
62+
}
6563
}
66-
elsif ($aa == -1)
67-
# Shared root of -1 amongst polynomial created and (z + 1)
68-
{
69-
$poles_deg1 = List($bb, $aa);
70-
$poles_deg2 = List(Formula("none"));
71-
$poles_deg3 = List(Formula("none"));
64+
elsif ($b==0) { # then f = 2/(z-a) + 2/(z+1)
65+
if ($a == -1) {
66+
$poles_deg1 = List(Complex(-1));
67+
}
68+
else {
69+
$poles_deg1 = List(Complex($a),Complex(-1));
70+
}
7271
}
73-
elsif ($bb == -1)
74-
{
75-
$poles_deg1 = List($bb, $aa);
76-
$poles_deg2 = List(Formula("none"));
77-
$poles_deg3 = List(Formula("none"));
72+
elsif ($a == -1) { # then f = 2(2z-b)/((z+1)(z-b)) and b != 0
73+
if ($b == -2) {
74+
$poles_deg1 = List(Complex(-1));
75+
}
76+
elsif ($b == -1) {
77+
$poles_deg1 = List("none");
78+
$poles_deg2 = List(Complex(-1));
79+
}
80+
else {
81+
$poles_deg1 = List(Complex(-1),Complex($b));
82+
}
7883
}
79-
elsif($aa == $bb)
80-
# Repeated root (but not -1) with the -1 root
81-
{
82-
$poles_deg1 = List(Complex(-1,0));
83-
$poles_deg2 = List($aa);
84-
$poles_deg3 = List(Formula("none"));
84+
elsif ($b == -1) { # then f = 2(2z-a)/((z+1)(z-a)) and a != 0
85+
if ($a == -2) {
86+
$poles_deg1 = List(Complex(-1));
87+
}
88+
elsif ($a == -1) {
89+
$poles_deg1 = List("none");
90+
$poles_deg2 = List(Complex(-1));
91+
}
92+
else {
93+
$poles_deg1 = List(Complex(-1),Complex($a));
94+
}
8595
}
86-
else
87-
# Two distinct roots (with neither = -1) and the -1 root
88-
{
89-
$poles_deg1 = List($aa, $bb, Complex(-1,0));
90-
$poles_deg2 = List(Formula("none"));
91-
$poles_deg3 = List(Formula("none"));
96+
elsif ($a == $b) { # then f = 2z/(z-a)^2 + 2/(z+1) and a != 0 and a != -1
97+
$poles_deg1 = List(Complex(-1));
98+
$poles_deg2 = List(Complex($a));
9299
}
93100

101+
102+
94103
##############################################################
95104
#
96105
# Text
@@ -99,7 +108,7 @@ $poles_deg3 = List(Formula("none"));
99108
Context()->texStrings;
100109

101110
BEGIN_TEXT
102-
Find the poles for the function:
111+
Find the poles for the function:
103112

104113
\[ R(z) = $f \]
105114

0 commit comments

Comments
 (0)