Monday, 6 April 2026

How many roots of f(z) = i*z^15 + z*sin(z) + z^3*exp(2*z) 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 complexSinZExpZ05.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: 1j*z**15 + z*np.sin(z) + z**3*np.exp(2*z)  
df = lambda z: 15j*z**14 + z*np.cos(z) + np.sin(z) +  3*z**2*np.exp(2*z) + 2*z**3*np.exp(2*z)

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

print("f(z) = 1j*z**15 + z*np.sin(z) + z**3*np.exp(2*z)")
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()



Add to the bottom of ~/.bashrc                                                        function activatevenv() {
 # Names of possible virtualenv directories
 VIRTUALENV_DIRS=("venv/" "env/" ".env/" ".venv/" "${PWD##*/}")

 for dir in "${VIRTUALENV_DIRS[@]}"; do
   if [[ -d "${dir}" ]]; then
     # Found a possible venv directory
     # Try activating the venv
     if [[ -e "./${dir}/bin/activate" ]]; then
       source ./$dir/bin/activate
       echo "Virtual environment activated automatically"
       break
     fi
   fi
 done

}
# Extension for `cd` command in order to automatically activate virtual env when changing directories.
cd() {
 builtin cd $1
 # Try activating venv
 activatevenv
}

No comments:

Post a Comment

Setup non-flat btrfs achitecture on Arch Linux via CachyOS approach

The first phase follows exactly guidelines proposed in  Bring CachyOS KDE Plasma 6.7.2 along with kernel 7.1.3 to Arch Linux   Second phase ...