Ejemplo n.º 1
0
def test_guess_symmetry_1(symmetry):
	C = Circle(0, 3)
	f = lambda z: z**4 + z**3 + z**2 + z

	roots = [0,-1,1j,-1j]
	multiplicities = [1,1,1,1]

	roots_approx_equal(C.roots(f, verbose=True, guessRootSymmetry=symmetry), (roots, multiplicities))
Ejemplo n.º 2
0
def test_reevaluation_of_N():
    from cxroots import Circle
    C = Circle(0, 2)
    f = lambda z: (z - 1) * (z - 0.2)**2

    roots = [1, 0.2]
    multiplicities = [1, 2]
    roots_approx_equal(
        C.roots(f, NIntAbsTol=10, intMethod='romb', verbose=True),
        (roots, multiplicities))
Ejemplo n.º 3
0
def test_guess_root(guesses):
	C = Circle(0, 3)
	f = lambda z: (z-2.5)**2 * (exp(-z)*sin(z/2.) - 1.2*cos(z))

	roots = [2.5,
			 1.44025113016670301345110737, 
			 -0.974651035111059787741822566 - 1.381047768247156339633038236j,
			 -0.974651035111059787741822566 + 1.381047768247156339633038236j]
	multiplicities = [2,1,1,1]

	roots_approx_equal(C.roots(f, guessRoots=[2.5], verbose=True), (roots, multiplicities))
Ejemplo n.º 4
0
def calcInt():
    plaTrue = ε > -1.0

    if plaTrue:
        Int = open(f"eps_{ε}_int", "w")
        Pla = open(f"eps_{ε}_pla", "w")
    else:
        Int = open(f"eps_{ε}_int", "w")

    for m in range(65):
        print(f"m = {m}")

        f0 = lambda k: ivp(m, η * k) * hankel1(m, k) / η + iv(m, η * k) * h1vp(
            m, k)
        f1 = (lambda k: ivp(m, η * k, 2) * hankel1(m, k) + c * ivp(m, η * k) *
              h1vp(m, k) + iv(m, η * k) * h1vp(m, k, 2))

        t = np.linspace(0.2, 65.0, num=1024)
        k = 1j * t
        rf = np.real(f0(k))

        ind = np.where(rf[1:] * rf[:-1] < 0.0)[0]
        roots = np.zeros(np.shape(ind), dtype=complex)
        for a, i in enumerate(ind):
            C = Circle(center=1j * (t[i] + t[i + 1]) / 2.0,
                       radius=(t[i + 1] - t[i]))
            z = C.roots(f0, df=f1)
            roots[a] = z.roots[0]

        if plaTrue:
            if m:
                writeFile(Int, m, roots[1:])
                writeFile(Pla, m, roots[[0]])
            else:
                writeFile(Int, m, roots)
        else:
            writeFile(Int, m, roots)

    if plaTrue:
        Int.close()
        Pla.close()
    else:
        Int.close()
Ejemplo n.º 5
0
def test_guess_symmetry_2(usedf):
	C = Circle(0, 1.5)
	f = lambda z: z**27-2*z**11+0.5*z**6-1
	df = (lambda z: 27*z**26-22*z**10+3*z**5) if usedf else None

	symmetry = lambda z: [z.conjugate()]

	roots = [-1.03509521179240, 
		  	 -0.920332541459108, 
		  	 1.05026721944263, 
		  	 -0.983563736801535 - 0.382365167035741j, 
		  	 -0.983563736801535 + 0.382365167035741j, 
		  	 -0.792214346729517 - 0.520708613101932j, 
		  	 -0.792214346729517 + 0.520708613101932j, 
		  	 -0.732229626596468 - 0.757345327222341j, 
		  	 -0.732229626596468 + 0.757345327222341j, 
		  	 -0.40289002582335 - 0.825650446354661j, 
		  	 -0.40289002582335 + 0.825650446354661j, 
		  	 -0.383382611408318 - 0.967939747947639j, 
		  	 -0.383382611408318 + 0.967939747947639j, 
		  	 -0.02594227096144 - 1.05524415820652j, 
		  	 -0.02594227096144 + 1.05524415820652j, 
		  	 0.160356899544475 - 0.927983420797727j, 
		  	 0.160356899544475 + 0.927983420797727j, 
		  	 0.41133738621461 - 0.967444751898913j, 
		  	 0.41133738621461 + 0.967444751898913j, 
		  	 0.576737152896681 - 0.719511178392941j, 
		  	 0.576737152896681 + 0.719511178392941j, 
		  	 0.758074415348703 - 0.724716122470435j, 
		  	 0.758074415348703 + 0.724716122470435j, 
		  	 0.903278407433416 - 0.22751872334709j, 
		  	 0.903278407433416 + 0.22751872334709j, 
		  	 0.963018623787179 - 0.427294816877434j, 
		  	 0.963018623787179 + 0.427294816877434j]
	
	multiplicities = np.ones_like(roots)

	roots_approx_equal(C.roots(f, df, verbose=True, guessRootSymmetry=symmetry), (roots, multiplicities))
Ejemplo n.º 6
0
from numpy import sin, cos 			
f  = lambda z: 1j*z**5 + z*sin(z)          	# Define f(z)
df = lambda z: 5j*z**4 + z*cos(z) + sin(z) 	# Define f'(z)

from cxroots import Circle 			
C = Circle(0, 2)		# Define a circle, centered at 0 and with radius 2
r = C.roots(f, df)		# Find the roots of f(z) within the circle 

r.show('tutorial_roots.png')
Ejemplo n.º 7
0
from cxroots import Circle
C = Circle(0, 2)
f = lambda z: z**6 + z**3
df = lambda z: 6 * z**5 + 3 * z**2
r = C.roots(f, df)
r.show()
Ejemplo n.º 8
0
class TestRootfindingContours(unittest.TestCase):
    def setUp(self):
        self.roots = roots = [0, -1.234, 1 + 1j, 1 - 1j, 2.345]
        self.multiplicities = [1, 1, 1, 1, 1]
        self.f = lambda z: (z - roots[0]) * (z - roots[1]) * (z - roots[2]) * (
            z - roots[3]) * (z - roots[4])
        self.df = lambda z: (z - roots[1]) * (z - roots[2]) * (z - roots[
            3]) * (z - roots[4]) + (z - roots[0]) * (z - roots[2]) * (
                z - roots[3]) * (z - roots[4]) + (z - roots[0]) * (z - roots[
                    1]) * (z - roots[3]) * (z - roots[4]) + (z - roots[0]) * (
                        z - roots[1]) * (z - roots[2]) * (z - roots[4]) + (
                            z - roots[0]) * (z - roots[1]) * (z - roots[2]) * (
                                z - roots[3])

        self.Circle = Circle(0, 3)
        self.Rectangle = Rectangle([-2, 2], [-2, 2])
        self.halfAnnulus = AnnulusSector(0, [0.5, 3], [-pi / 2, pi / 2])
        self.Annulus = Annulus(0, [1, 2])

    def test_rootfinding_circle_fdf(self):
        roots_approx_equal(self.Circle.roots(self.f, self.df, verbose=True),
                           (self.roots, self.multiplicities),
                           decimal=7)

    def test_rootfinding_circle_f(self):
        roots_approx_equal(self.Circle.roots(self.f, self.df, verbose=True),
                           (self.roots, self.multiplicities),
                           decimal=7)

    def test_rootfinding_rectangle_fdf(self):
        roots_approx_equal(self.Rectangle.roots(self.f, self.df, verbose=True),
                           (self.roots[:-1], self.multiplicities[:-1]),
                           decimal=7)

    def test_rootfinding_rectangle_f(self):
        roots_approx_equal(self.Rectangle.roots(self.f, self.df, verbose=True),
                           (self.roots[:-1], self.multiplicities[:-1]),
                           decimal=7)

    def test_rootfinding_halfAnnulus_fdf(self):
        roots_approx_equal(self.halfAnnulus.roots(self.f,
                                                  self.df,
                                                  verbose=True),
                           (self.roots[2:], self.multiplicities[2:]),
                           decimal=7)

    def test_rootfinding_halfAnnulus_f(self):
        roots_approx_equal(self.halfAnnulus.roots(self.f,
                                                  self.df,
                                                  verbose=True),
                           (self.roots[2:], self.multiplicities[2:]),
                           decimal=7)

    def test_rootfinding_Annulus_fdf(self):
        roots_approx_equal(self.Annulus.roots(self.f, self.df, verbose=True),
                           (self.roots[1:-1], self.multiplicities[1:-1]),
                           decimal=7)

    def test_rootfinding_Annulus_f(self):
        roots_approx_equal(self.Annulus.roots(self.f, self.df, verbose=True),
                           (self.roots[1:-1], self.multiplicities[1:-1]),
                           decimal=7)
Ejemplo n.º 9
0
# Taking the derivative
FP = sym.diff(F, Z)


def fp(z):
    return complex(FP.evalf(subs={Z: z, C: c}))


print(FP)
#print(complex(FP.evalf(subs={Z: 4+1j, C: 1})))

# Finding the roots
roots = []
cont = Circle(0, 3)
zeroes = cont.roots(f)
zeroes.show()
print(zeroes)
numroots = len(zeroes[0])
for j in range(numroots):
    roots.append(complex(zeroes[0][j].real, zeroes[0][j].imag))
print(roots)

# Assign hues for each root
colours = [(90, 190, 155), (0, 190, 155), (150, 255, 255), (90, 190, 155),
           (90, 190, 155), (90, 190, 155)]

# Converting to latex
# Write the latex expression to file
exp = sym.Eq(FZ, F)
sym.preview(exp, viewer='file', filename='latex.png')
Ejemplo n.º 10
0
from numpy import exp, cos, sin
f = lambda z: (exp(2 * z) * cos(z) - 1 - sin(z) + z**5) * (z * (z + 2))**2

from matplotlib import pyplot as plt
plt.figure(figsize=(4.8, 4.8), dpi=80)

from cxroots import Circle
C = Circle(0, 3)
roots = C.roots(f)
roots.show('readmeEx.png')
print(roots)