0% found this document useful (0 votes)
9 views3 pages

SOT Py

Uploaded by

uazeez478
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views3 pages

SOT Py

Uploaded by

uazeez478
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

import numpy as np

# Function to implement the SOT method

def sot(A, b, omega=1.25, tol=1e-5, max_iterations=10000):

n = len(b)

x = np.zeros(n) # Initial guess (zero vector)

# Tabulate (cache) inverse of diagonal elements of A

D_inv = 1 / np.diag(A)

for k in range(max_iterations):

x_old = np.copy(x) # Store old values of x for comparison

for i in range(n):

# Compute the sum of non-diagonal terms (this part is repeated


in each iteration)

sigma = sum(A[i, j] * x[j] for j in range(n) if j != i)

# Use tabulated diagonal inverse to update the value of x[i]

x[i] = (1 - omega) * x[i] + omega * D_inv[i] * (b[i] - sigma)

# Check for convergence based on the infinity norm of the


difference
if np.linalg.norm(x - x_old, ord=np.inf) < tol:

print(f"Converged after {k+1} iterations.")

return x

print("Maximum iterations reached without convergence.")

return x

# Coefficient matrix A and vector b representing the system of


equations

A = np.array([[6, -2],

[2, -8]], dtype=float)

b = np.array([10, 0], dtype=float)

# Relaxation factor (omega)

omega = 1.25 # Can be tuned for better performance

# Solve the system using SOT

solution = sot(A, b, omega)

# Print the currents I1 and I2

print("Solution (Currents):")

print("I1:", solution[0], "A")


print("I2:", solution[1], "A")

Converged after 15 iterations.

Solution (Currents):

I1: 2.0 A

I2: 0.5 A

You might also like