[Python] To solve a set of many algebraic equations with more unknowns under a restrictive...

Discussão em 'Python' iniciado por Stack, Março 29, 2025.

  1. Stack

    Stack Membro Participativo

    I have recently tried to solve (for some nontrivial solutions) a set of 15 nonlinear algebraic equations with 18 unknowns (each of which is -1, -1/2, 0, 1/2, or 1) by using "nonlinsolve" of sympy in Python, and the following was a simple attempt:

    from sympy import symbols, nonlinsolve, Interval
    from sympy import FiniteSet

    x1,x2,x3,x4,x5,x6,x7,x8,x9,x10,x11,x12,x13,x14,x15,x16,x17,x18 = symbols('x1,x2,x3,x4,x5,x6,x7,x8,x9,x10,x11,x12,x13,x14,x15,x16,x17,x18', real=True)
    domains = [FiniteSet(-1,-1/2, 0, 1/2, 1),FiniteSet(-1,-1/2, 0, 1/2, 1), FiniteSet(-1,-1/2, 0, 1/2, 1), FiniteSet(-1,-1/2, 0, 1/2, 1), FiniteSet(-1,-1/2, 0, 1/2, 1), FiniteSet(-1,-1/2, 0, 1/2, 1), FiniteSet(-1,-1/2, 0, 1/2, 1), FiniteSet(-1,-1/2, 0, 1/2, 1), FiniteSet(-1,-1/2, 0, 1/2, 1), FiniteSet(-1,-1/2, 0, 1/2, 1), FiniteSet(-1,-1/2, 0, 1/2, 1), FiniteSet(-1,-1/2, 0, 1/2, 1), FiniteSet(-1,-1/2, 0, 1/2, 1), FiniteSet(-1,-1/2, 0, 1/2, 1), FiniteSet(-1,-1/2, 0, 1/2, 1), FiniteSet(-1,-1/2, 0, 1/2, 1), FiniteSet(-1,-1/2, 0, 1/2, 1), FiniteSet(-1,-1/2, 0, 1/2, 1)]
    vars = [x1,x2,x3,x4,x5,x6,x7,x8,x9,x10,x11,x12,x13,x14,x15,x16,x17,x18]
    eqn1 = x1*x1 - x10*x10 + x4*x4 - x13*x13 + x7*x7 - x16*x16 - 1
    eqn2 = x1*x2 - x10*x11 + x4*x5 - x13*x14 + x7*x8 - x16*x17
    eqn3 = x1*x3 - x10*x12 + x4*x6 - x13*x15 + x7*x9 - x16*x18
    eqn4 = x2*x1 - x11*x10 + x5*x4 - x14*x13 + x8*x7 - x17*x16
    eqn5 = x2*x2 - x11*x11 + x5*x5 - x14*x14 + x8*x8 - x17*x17 - 0.5
    eqn6 = x2*x3 - x11*x12 + x5*x6 - x14*x15 + x8*x9 - x17*x18
    eqn7 = x3*x1 - x12*x10 + x6*x4 - x15*x13 + x9*x7 - x18*x16
    eqn8 = x3*x2 - x12*x11 + x6*x5 - x15*x14 + x9*x8 - x18*x17
    eqn9 = x3*x3 - x12*x12 + x6*x6 - x15*x15 + x9*x9 - x18*x18
    eqn10 = x1*x11 - x10*x2 + x4*x14 - x13*x5 + x7*x17 - x16*x8
    eqn11 = x1*x12 - x10*x3 + x4*x15 - x13*x6 + x7*x18 - x16*x9
    eqn12 = x2*x10 - x11*x1 + x5*x13 - x14*x4 + x8*x16 - x17*x7
    eqn13 = x2*x12 - x11*x3 + x5*x15 - x14*x6 + x8*x18 - x17*x9
    eqn14 = x3*x10 - x12*x1 + x6*x13 - x15*x4 + x9*x16 - x18*x7
    eqn15 = x3*x11 - x12*x2 + x6*x14 - x15*x5 + x9*x17 - x18*x8
    system = [eqn1,eqn2,eqn3,eqn4,eqn5,eqn6,eqn7,eqn8,eqn9,eqn10,eqn11,eqn12,eqn13,eqn14,eqn15]
    nonlinsolve(system,vars)


    On the other hand, the python in my computer appears not able to properly finish the solving equations, taking long time without any result after running the code in the program.

    Although there are many equations and more unknowns, I expected that it might not give too much burden for computations because the domain for solutions is quite restrictive, only having 5 elements, -1, -1/2, 0, 1/2, and 1; if there might be some way(s) to correct the code or to try alternative(s) for solving such kind of a set of many algebraic equations with more unknowns it would be useful for my reference.

    Also to avoid too many trivial solutions, I may impose a bit more conditions upon the 18 unknowns that

    x1**2 + x2**2 + x3**2, x4**2 + x5**2 + x6**2, x7**2 + x8**2 + x9**2, x10**2 + x11**2 + x12**2, x13**2 + x14**2 + x15**2, x16**2 + x17**2 + x18**2


    These 6 pairs are not zeros.

    Continue reading...

Compartilhe esta Página