I have 5 equations and I've to take combination of 3 equations at a time to check if I'm getting any intersection point for 3 lines. Equations used:

Eq1: y=-11.5 (slope zero)
Eq2: y=34.01+1.333 x
Eq3 : y=11.2449 +0.6666 x
Eq4 : x=-31.0
Eq5 : y=13.8283 +0.75 x

Take Xmin=-44, Xmax = -20, Ymin = -18 Ymax=2.0 implies that when you use the value of X you have to give values between the Xmin and Xmax. Make a plot for the intersection points and expand for the equations.

from itertools import combinations
from sympy import symbols, Eq, solve

# Define symbols for x and y
x, y = symbols('x y')

# List of equations in the form y = mx + c
equations = [
    Eq(y, 0*x - 11.5),
    Eq(y, 1.333*x + 34.01),
    Eq(y, 0.6666*x + 11.2449),
    Eq(x, 0*y - 31.0),
    Eq(y, 0.75*x + 13.8283)
]

# Generate all combinations of 3 equations
equation_combinations = list(combinations(equations, 3))
print(equation_combinations)

solution = []

# Calculate and compare intersection points for each combination
for eq_combination in equation_combinations:
    eq1, eq2, eq3 = eq_combination

    eq1_m, eq1_c = eq1.rhs.as_coefficients_dict()[x], eq1.rhs.as_coefficients_dict()[1]
    eq2_m, eq2_c = eq2.rhs.as_coefficients_dict()[x], eq2.rhs.as_coefficients_dict()[1]
    eq3_m, eq3_c = eq3.rhs.as_coefficients_dict()[x], eq3.rhs.as_coefficients_dict()[1]

    # Solve for intersection points of first two equations
    solution12 = solve((Eq(y, eq1_m*x + eq1_c), Eq(y, eq2_m*x + eq2_c)), (x, y))
    x12, y12 = solution12[x], solution12[y]
    x12 = round(x12, 1)
    y12 = round(y12, 1)
    solution.append(solution12)
    print(solution)

    # Calculate y value for the third equation at x12
    y3 = eq3_m * x12 + eq3_c
    y3 = round(y3, 1)
    x3 =  (y12 - eq3_c)/eq3_m
    x3 = round(x3, 1)
    print('y3:', y3)

    # Compare y3 with y12 within a tolerance of 3
    if abs(y3 - y12) <= 3:
        # Reduce decimal points for output
        x12 = round(x12, 1)
        y12 = round(y12, 1)
        print(f"Common intersection point: ({x12}, {y12})")

This is error I'm getting: I'm getting error when I change the order of equations and also I'm not getting the desired 2 intersection points instead I'm getting 3 points. TypeError
in <cell line: 23>() 30 # Solve for intersection points of first two equations 31 solution12 = solve((Eq(y, eq1_mx + eq1_c), Eq(y, eq2_mx + eq2_c)), (x, y)) ---> 32 x12, y12 = solution12[x], solution12[y] 33 x12 = round(x12, 1) 34 y12 = round(y12, 1)

TypeError: list indices must be integers or slices, not Symbol
0

There are 0 best solutions below