0

I need to find out values of Alpha, Beta, Gama, l1, l2, l3, so it is necessary to work with symbols. I tried to solve but it was solving 13 hours and didn't finish.

Code is below:

    import sympy as sym
    from scipy.optimize import fsolve
    from sympy import symbols, Eq, solve
    Alpha, Beta, Gama, l1, l2, l3 = sym.symbols('Alpha, Beta, Gama, l1, l2, l3')



    Eq1 = sym.Eq(-0.945592*l1 + 0.235025*l2 + 0.224988*l3 + 
    0.0031173010925*sym.sin(Alpha)*sym.sin(Beta)*sym.sin(Gama) + 
    0.031830140825*sym.sin(Alpha)*sym.sin(Beta)*sym.cos(Gama) - 
    0.128064361336*sym.sin(Alpha)*sym.sin(Gama) + 
    0.00038524122875*sym.sin(Alpha)*sym.cos(Beta) + 
    0.0125420486104*sym.sin(Alpha)*sym.cos(Gama) - 
    0.0125420486104*sym.sin(Beta)*sym.sin(Gama)*sym.cos(Alpha) - 
    0.128064361336*sym.sin(Beta)*sym.cos(Alpha)*sym.cos(Gama) - 
    0.0003687890802*sym.sin(Beta) - 0.031830140825*sym.sin(Gama)*sym.cos(Alpha) + 
    0.0029841733356*sym.sin(Gama)*sym.cos(Beta) - 
    0.0015499671268*sym.cos(Alpha)*sym.cos(Beta) + 
    0.0031173010925*sym.cos(Alpha)*sym.cos(Gama) + 
    0.030470799804*sym.cos(Beta)*sym.cos(Gama) - 0.0685469-(-0.998117*l1 + 0.0200759*l2 - 
    0.0579618*l3 - 0.00035774651523*sym.sin(Alpha)*sym.sin(Beta)*sym.sin(Gama) + 
    0.0025561238157*sym.sin(Alpha)*sym.sin(Beta)*sym.cos(Gama) - 
    0.127083250791*sym.sin(Alpha)*sym.sin(Gama) - 
    0.0006249025393*sym.sin(Alpha)*sym.cos(Beta) - 
    0.0177861455049*sym.sin(Alpha)*sym.cos(Gama) + 
    0.0177861455049*sym.sin(Beta)*sym.sin(Gama)*sym.cos(Alpha) - 
    0.127083250791*sym.sin(Beta)*sym.cos(Alpha)*sym.cos(Gama) - 
    0.0018041769486*sym.sin(Beta) - 0.0025561238157*sym.sin(Gama)*sym.cos(Alpha) + 
    0.00103286188746*sym.sin(Gama)*sym.cos(Beta) + 
    0.031068387859*sym.cos(Alpha)*sym.cos(Beta) - 
    0.00035774651523*sym.cos(Alpha)*sym.cos(Gama) - 
    0.0073798702614*sym.cos(Beta)*sym.cos(Gama) - 0.0520369),0)
    Eq2 = sym.Eq(-0.998117*l1 + 0.0200759*l2 - 0.0579618*l3 - 
    0.00035774651523*sym.sin(Alpha)*sym.sin(Beta)*sym.sin(Gama) + 
    0.0025561238157*sym.sin(Alpha)*sym.sin(Beta)*sym.cos(Gama) - 
    0.127083250791*sym.sin(Alpha)*sym.sin(Gama) - 
    0.0006249025393*sym.sin(Alpha)*sym.cos(Beta) - 
    0.0177861455049*sym.sin(Alpha)*sym.cos(Gama) + 
    0.0177861455049*sym.sin(Beta)*sym.sin(Gama)*sym.cos(Alpha) - 
    0.127083250791*sym.sin(Beta)*sym.cos(Alpha)*sym.cos(Gama) - 
    0.0018041769486*sym.sin(Beta) - 0.0025561238157*sym.sin(Gama)*sym.cos(Alpha) + 
    0.00103286188746*sym.sin(Gama)*sym.cos(Beta) + 
    0.031068387859*sym.cos(Alpha)*sym.cos(Beta) - 
    0.00035774651523*sym.cos(Alpha)*sym.cos(Gama) - 
    0.0073798702614*sym.cos(Beta)*sym.cos(Gama) - 0.0520369 - (-0.999146*l1 + 0.023687*l2 - 
    0.0338601*l3 - 0.00020770774995*sym.sin(Alpha)*sym.sin(Beta)*sym.sin(Gama) + 
    0.002625917133*sym.sin(Alpha)*sym.sin(Beta)*sym.cos(Gama) - 
    0.110764326414*sym.sin(Alpha)*sym.sin(Gama) + 
    0.0003371418084*sym.sin(Alpha)*sym.cos(Beta) - 
    0.0087613614021*sym.sin(Alpha)*sym.cos(Gama) + 
    0.0087613614021*sym.sin(Beta)*sym.sin(Gama)*sym.cos(Alpha) - 
    0.110764326414*sym.sin(Beta)*sym.cos(Alpha)*sym.cos(Gama) + 
    0.00048193757532*sym.sin(Beta) - 0.002625917133*sym.sin(Gama)*sym.cos(Alpha) + 
    0.000296914137885*sym.sin(Gama)*sym.cos(Beta) - 
    0.0142210448472*sym.cos(Alpha)*sym.cos(Beta) - 
    0.00020770774995*sym.cos(Alpha)*sym.cos(Gama) - 
    0.0037536968259*sym.cos(Beta)*sym.cos(Gama) - 0.0424406),0)
    Eq3 = sym.Eq(0.305065*l1 + 0.880846*l2 + 0.362004*l3 + 
    0.0116832770902*sym.sin(Alpha)*sym.sin(Beta)*sym.sin(Gama) + 
    0.119295616318*sym.sin(Alpha)*sym.sin(Beta)*sym.cos(Gama) + 
    0.041315868145*sym.sin(Alpha)*sym.sin(Gama) + 
    0.0014438387209*sym.sin(Alpha)*sym.cos(Beta) - 
    0.0040462906405*sym.sin(Alpha)*sym.cos(Gama) + 
    0.0040462906405*sym.sin(Beta)*sym.sin(Gama)*sym.cos(Alpha) + 
    0.041315868145*sym.sin(Beta)*sym.cos(Alpha)*sym.cos(Gama) - 
    0.0005933788566*sym.sin(Beta) - 0.119295616318*sym.sin(Gama)*sym.cos(Alpha) + 
    0.0048015124548*sym.sin(Gama)*sym.cos(Beta) + 
    0.00050004729475*sym.cos(Alpha)*sym.cos(Beta) + 
    0.0116832770902*sym.cos(Alpha)*sym.cos(Gama) + 
    0.049027287732*sym.cos(Beta)*sym.cos(Gama) - 0.612159 - (0.025017*l1 + 0.995996*l2 - 
    0.0858224*l3 - 0.0177483499212*sym.sin(Alpha)*sym.sin(Beta)*sym.sin(Gama) + 
    0.126813198708*sym.sin(Alpha)*sym.sin(Beta)*sym.cos(Gama) + 
    0.003185239491*sym.sin(Alpha)*sym.sin(Gama) - 
    0.031002367492*sym.sin(Alpha)*sym.cos(Beta) + 
    0.0004457954349*sym.sin(Alpha)*sym.cos(Gama) - 
    0.0004457954349*sym.sin(Beta)*sym.sin(Gama)*sym.cos(Alpha) + 
    0.003185239491*sym.sin(Beta)*sym.cos(Alpha)*sym.cos(Gama) - 
    0.0026713938448*sym.sin(Beta) - 0.126813198708*sym.sin(Gama)*sym.cos(Alpha) + 
    0.00152932942128*sym.sin(Gama)*sym.cos(Beta) - 
    0.000778704159*sym.cos(Alpha)*sym.cos(Beta) - 
    0.0177483499212*sym.cos(Alpha)*sym.cos(Gama) - 
    0.0109271654352*sym.cos(Beta)*sym.cos(Gama) - 0.574885),0)
    Eq4 = sym.Eq(0.025017*l1 + 0.995996*l2 - 0.0858224*l3 - 
    0.0177483499212*sym.sin(Alpha)*sym.sin(Beta)*sym.sin(Gama) + 
    0.126813198708*sym.sin(Alpha)*sym.sin(Beta)*sym.cos(Gama) + 
    0.003185239491*sym.sin(Alpha)*sym.sin(Gama) - 
    0.031002367492*sym.sin(Alpha)*sym.cos(Beta) + 
    0.0004457954349*sym.sin(Alpha)*sym.cos(Gama) - 
    0.0004457954349*sym.sin(Beta)*sym.sin(Gama)*sym.cos(Alpha) + 
    0.003185239491*sym.sin(Beta)*sym.cos(Alpha)*sym.cos(Gama) - 
    0.0026713938448*sym.sin(Beta) - 0.126813198708*sym.sin(Gama)*sym.cos(Alpha) + 
    0.00152932942128*sym.sin(Gama)*sym.cos(Beta) - 
    0.000778704159*sym.cos(Alpha)*sym.cos(Beta) - 
    0.0177483499212*sym.cos(Alpha)*sym.cos(Gama) - 
    0.0109271654352*sym.cos(Beta)*sym.cos(Gama) - 0.574885 - (0.0313426*l1 + 0.968404*l2 - 
    0.247408*l3 - 0.0084917894154*sym.sin(Alpha)*sym.sin(Beta)*sym.sin(Gama) + 
    0.107356299036*sym.sin(Alpha)*sym.sin(Beta)*sym.cos(Gama) + 
    0.0034746092934*sym.sin(Alpha)*sym.sin(Gama) + 
    0.0137834878128*sym.sin(Alpha)*sym.cos(Beta) + 
    0.00027483855801*sym.sin(Alpha)*sym.cos(Gama) - 
    0.00027483855801*sym.sin(Beta)*sym.sin(Gama)*sym.cos(Alpha) + 
    0.0034746092934*sym.sin(Beta)*sym.cos(Alpha)*sym.cos(Gama) + 
    0.0035214075456*sym.sin(Beta) - 0.107356299036*sym.sin(Gama)*sym.cos(Alpha) + 
    0.0021694836408*sym.sin(Gama)*sym.cos(Beta) + 
    0.00044610549432*sym.cos(Alpha)*sym.cos(Beta) - 
    0.0084917894154*sym.cos(Alpha)*sym.cos(Gama) - 
    0.027427403472*sym.cos(Beta)*sym.cos(Gama) - 0.507045),0)
    Eq5 = sym.Eq(-0.1131*l1 + 0.410944*l2 - 0.904618*l3 + 
    0.0054506379328*sym.sin(Alpha)*sym.sin(Beta)*sym.sin(Gama) + 
    0.055655378752*sym.sin(Alpha)*sym.sin(Beta)*sym.cos(Gama) - 
    0.0153174723*sym.sin(Alpha)*sym.sin(Gama) + 0.0006735988576*sym.sin(Alpha)*sym.cos(Beta) 
    + 0.00150012447*sym.sin(Alpha)*sym.cos(Gama) - 
    0.00150012447*sym.sin(Beta)*sym.sin(Gama)*sym.cos(Alpha) - 
    0.0153174723*sym.sin(Beta)*sym.cos(Alpha)*sym.cos(Gama) + 0.0014828045947*sym.sin(Beta) 
    - 0.055655378752*sym.sin(Gama)*sym.cos(Alpha) - 
    0.0119985817666*sym.sin(Gama)*sym.cos(Beta) - 
    0.000185387865*sym.cos(Alpha)*sym.cos(Beta) + 
    0.0054506379328*sym.cos(Alpha)*sym.cos(Gama) - 
    0.122515129594*sym.cos(Beta)*sym.cos(Gama) + 0.200443 - (0.0560068*l1 - 0.0871109*l2 - 
    0.994623*l3 + 0.00155229010473*sym.sin(Alpha)*sym.sin(Beta)*sym.sin(Gama) - 
    0.0110912211207*sym.sin(Alpha)*sym.sin(Beta)*sym.cos(Gama) + 
    0.0071309537964*sym.sin(Alpha)*sym.sin(Gama) + 
    0.0027115009843*sym.sin(Alpha)*sym.cos(Beta) + 
    0.00099802437396*sym.sin(Alpha)*sym.cos(Gama) - 
    0.00099802437396*sym.sin(Beta)*sym.sin(Gama)*sym.cos(Alpha) + 
    0.0071309537964*sym.sin(Beta)*sym.cos(Alpha)*sym.cos(Gama) - 
    0.030959630121*sym.sin(Beta) + 0.0110912211207*sym.sin(Gama)*sym.cos(Alpha) + 
    0.0177238834731*sym.sin(Gama)*sym.cos(Beta) - 
    0.0017433236636*sym.cos(Alpha)*sym.cos(Beta) + 
    0.00155229010473*sym.cos(Alpha)*sym.cos(Gama) - 
    0.126638384229*sym.cos(Beta)*sym.cos(Gama) + 0.207426),0)
    Eq6 = sym.Eq(0.0560068*l1 - 0.0871109*l2 - 0.994623*l3 + 
    0.00155229010473*sym.sin(Alpha)*sym.sin(Beta)*sym.sin(Gama) - 
    0.0110912211207*sym.sin(Alpha)*sym.sin(Beta)*sym.cos(Gama) + 
    0.0071309537964*sym.sin(Alpha)*sym.sin(Gama) + 
    0.0027115009843*sym.sin(Alpha)*sym.cos(Beta) + 
    0.00099802437396*sym.sin(Alpha)*sym.cos(Gama) - 
    0.00099802437396*sym.sin(Beta)*sym.sin(Gama)*sym.cos(Alpha) + 
    0.0071309537964*sym.sin(Beta)*sym.cos(Alpha)*sym.cos(Gama) - 
    0.030959630121*sym.sin(Beta) + 0.0110912211207*sym.sin(Gama)*sym.cos(Alpha) + 
    0.0177238834731*sym.sin(Gama)*sym.cos(Beta) - 
    0.0017433236636*sym.cos(Alpha)*sym.cos(Beta) + 
    0.00155229010473*sym.cos(Alpha)*sym.cos(Gama) - 
    0.126638384229*sym.cos(Beta)*sym.cos(Gama) + 0.207426 - (0.0269299*l1 - 0.248258*l2 - 
    0.968319*l3 + 0.0021769371633*sym.sin(Alpha)*sym.sin(Beta)*sym.sin(Gama) - 
    0.027521633622*sym.sin(Alpha)*sym.sin(Beta)*sym.cos(Gama) + 
    0.0029854217841*sym.sin(Alpha)*sym.sin(Gama) - 
    0.0035335057656*sym.sin(Alpha)*sym.cos(Beta) + 
    0.000236144253615*sym.sin(Alpha)*sym.cos(Gama) - 
    0.000236144253615*sym.sin(Beta)*sym.sin(Gama)*sym.cos(Alpha) + 
    0.0029854217841*sym.sin(Beta)*sym.cos(Alpha)*sym.cos(Gama) + 
    0.0137822779908*sym.sin(Beta) + 0.027521633622*sym.sin(Gama)*sym.cos(Alpha) + 
    0.00849104406315*sym.sin(Gama)*sym.cos(Beta) + 
    0.00038329865268*sym.cos(Alpha)*sym.cos(Beta) + 
    0.0021769371633*sym.cos(Alpha)*sym.cos(Gama) - 
    0.107346876021*sym.cos(Beta)*sym.cos(Gama) + 0.184387),0)    
David Makogon
  • 69,407
  • 21
  • 141
  • 189
  • Not necessary to work in symbols. Six non-linear equations with six unknowns can be solved using numerical methods and Newton-Raphson. – duffymo Jun 02 '22 at 12:07
  • @duffymo I have 6 equations with 6 unknowns – mika hirvonen Jun 02 '22 at 12:11
  • Plus these are trigonometric equations so I think it should be symbols. If you have suggestion please write – mika hirvonen Jun 02 '22 at 12:12
  • Haven't finished coffee yet. Conclusion is the same. Doesn't matter what kind of functions they are. – duffymo Jun 02 '22 at 12:12
  • Ok, if you will have a time please write a suggestion. Thanks – mika hirvonen Jun 02 '22 at 12:16
  • I did write a suggestion: non-linear Newton-Raphson. That's your cue to to learn what that is and how to do it. More linear algebra. I'd bet Python has a library in NumPy or SciPy. – duffymo Jun 02 '22 at 12:17
  • Take a look at this: https://stackoverflow.com/questions/63806409/how-to-compute-system-of-multivariable-equations-in-python-using-newton-raphson – duffymo Jun 02 '22 at 13:14

1 Answers1

2

The solve function in SymPy is for finding exact analytic solutions but those are likely to be very complicated for your system of equations. You can use SymPy's nsolve function if you just want a numerical solution:

In [140]: from sympy import nsolve

In [141]: eqs = [Eq1, Eq2, Eq3, Eq4, Eq5, Eq6]

In [142]: nsolve(eqs, [l1, l2, l3, Alpha, Beta, Gama], [1, 1, 1, 1, 1, 1])
Out[142]: 
⎡-0.557604943463198⎤
⎢                  ⎥
⎢-0.300586875967959⎥
⎢                  ⎥
⎢0.383995113825599 ⎥
⎢                  ⎥
⎢ 3.21607797653942 ⎥
⎢                  ⎥
⎢-1.51886308101428 ⎥
⎢                  ⎥
⎣ 2.40460861693647 ⎦

Note that there can be other possible solutions to the equations so if you need to find a different solution than the one shown then you should use a different initial guess (something other than [1,1,1,1,1,1]).

Oscar Benjamin
  • 12,649
  • 1
  • 12
  • 14
  • Just curious - did you substitute this solution back into the given equations to confirm that it is indeed a solution? Your point about other solutions is an excellent one. There are likely to be many. – duffymo Jun 02 '22 at 14:41
  • 1
    I didn't check the answer before but since you asked I just did and the answer checks out. In fact the number of solutions is infinite (just add `2*pi` to any of the angles). – Oscar Benjamin Jun 02 '22 at 19:33
  • Very nice work. Adding or _subtracting_ 2*pi works. Well done. – duffymo Jun 02 '22 at 19:35