Saturday, 4 April 2026

How many roots of polynomial 3*z^12+5*z^10+3*z^7+z^5+z^4+4*z^3+10*z^2+9 are in the right half-plane and how many are in the left ?

Follow code proposed in https://lxer.com/module/newswire/view/363645/index.html . Setup python3.14.3t on CachyOS along with aqtinstall via UV

   $ curl -LsSf https://astral.sh/uv/install.sh | sh
   $ uv python install 3.14t 
                                                                             $ uv python list
   $ mkdir MULTITHREAD
   $ cd MULTITHREAD
   $ python3.14t -m venv .env
   $ source .env/bin/activate
   $ pip install aqtinstall
   $ pip install --upgrade pip
   $ pip install numpy matplotlib cxroots
 


cat complexThreaded12.py
import os
import numpy as np
import matplotlib.pyplot as plt
from cxroots import Circle
from concurrent.futures import ThreadPoolExecutor

# Silence Qt warnings
os.environ["QT_LOGGING_RULES"] = "*.debug=false;qt.qpa.fonts.warning=false"

def count_zeros_task(f, df, contour_points):
 """Calculates zeros via the Argument Principle."""
 fz, dfz = f(contour_points), df(contour_points)
 integrand = dfz / fz
 dz = np.diff(contour_points, append=contour_points[0])
 integral = np.sum(integrand * dz)
 return int(np.round((integral / (2j * np.pi)).real))

def find_roots_task(contour, f, df):
 """Calculates specific root locations using cxroots."""
 return contour.roots(f, df)

# 1. Setup Data
f = lambda z: 3*z**12 + 5*z**10 + 3*z**7 + z**5 + z**4 + 4*z**3 + 10*z**2 + 9  
df = lambda z: 36*z**11 +  50*z**9 + 21*z**6 +  5*z**4 + 4*z**3 + 12*z**2 + 20*z

t = np.linspace(0, 2 * np.pi, 1000)
circle_pts = 3 * np.exp(1j * t)
C = Circle(0, 3)

print("Starting concurrent calculations...")

# 2. Parallel Execution
with ThreadPoolExecutor() as executor:
 # Submit both tasks to run simultaneously
 future_count = executor.submit(count_zeros_task, f, df, circle_pts)
 future_roots = executor.submit(find_roots_task, C, f, df)

 # Retrieve results (this waits for each to finish)
 zero_count = future_count.result()
 roots_result = future_roots.result()


# 3. Output and Visualization
print(f"\nVerification (Argument Principle): {zero_count} zeros found.")
print(f"Detailed Root Analysis:\n{roots_result}")

# Plotting must happen on the main thread
roots_result.show()
plt.show()

 

No comments:

Post a Comment

How many roots of polynomial 3*z^12+5*z^10+3*z^7+z^5+z^4+4*z^3+10*z^2+9 are in the right half-plane and how many are in the left ?

Follow code proposed in  https://lxer.com/module/newswire/view/363645/index.html  .  Setup python3.14.3t on CachyOS along with aqtinstall vi...