this works (A)(although takes awfully long)
a,b,x,y,l1,l2=symbols('a b x y l1 l2')
eq = [l1*cos(a)+l2*cos(b)-x,l1*sin(a)+l2*sin(b)-y]
res = solve(eq,[a,b])
this does not (B):
a,b,x,y,l1,l2=symbols('a b x y l1 l2')
eq = [l1*cos(a)+l2*cos(a+b)-x,l1*sin(a)+l2*sin(a+b)-y]
res = solve(eq,[a,b])
solution from (A) could be used to find solution for (B) by a simple substitution, so, analytic solution exists, sympy, however, produces error
python 3.11.13
sympy 1.14.0
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
Cell In[11], line 1
----> 1 res2 = solve(eq,[a,b])
File ~\Documents\FH\Python\venv\control\Lib\site-packages\sympy\solvers\solvers.py:1170, in solve(f, *symbols, **flags)
1168 solution = _solve(f[0], *symbols, **flags)
1169 else:
-> 1170 linear, solution = _solve_system(f, symbols, **flags)
1171 assert type(solution) is list
1172 assert not solution or type(solution[0]) is dict, solution
File ~\Documents\FH\Python\venv\control\Lib\site-packages\sympy\solvers\solvers.py:1963, in _solve_system(exprs, symbols, **flags)
1961 for s in ok_syms:
1962 try:
-> 1963 soln = _vsolve(eq2, s, **flags)
1964 except NotImplementedError:
1965 continue
File ~\Documents\FH\Python\venv\control\Lib\site-packages\sympy\solvers\solvers.py:2638, in _vsolve(e, s, **flags)
2636 def _vsolve(e, s, **flags):
2637 """return list of scalar values for the solution of e for symbol s"""
-> 2638 return [i[s] for i in _solve(e, s, **flags)]
File ~\Documents\FH\Python\venv\control\Lib\site-packages\sympy\solvers\solvers.py:1743, in _solve(f, *symbols, **flags)
1738 result = [r for r in result if
1739 not any(checksol(d, r, **flags)
1740 for d in dens)]
1741 if check:
1742 # keep only results if the check is not False
-> 1743 result = [r for r in result if
1744 checksol(f_num, r, **flags) is not False]
1745 return result
File ~\Documents\FH\Python\venv\control\Lib\site-packages\sympy\solvers\solvers.py:1744, in <listcomp>(.0)
1738 result = [r for r in result if
1739 not any(checksol(d, r, **flags)
1740 for d in dens)]
1741 if check:
1742 # keep only results if the check is not False
1743 result = [r for r in result if
-> 1744 checksol(f_num, r, **flags) is not False]
1745 return result
File ~\Documents\FH\Python\venv\control\Lib\site-packages\sympy\solvers\solvers.py:354, in checksol(f, symbol, sol, **flags)
352 return val == 0
353 if numerical and val.is_number:
--> 354 return (abs(val.n(18).n(12, chop=True)) < 1e-9) is S.true
356 if flags.get('warn', False):
357 warnings.warn("\n\tWarning: could not verify solution %s." % sol)
File ~\Documents\FH\Python\venv\control\Lib\site-packages\sympy\core\decorators.py:248, in _SympifyWrapper.make_wrapped.<locals>._func(self, other)
246 if not isinstance(other, expectedcls):
247 return retval
--> 248 return func(self, other)
File ~\Documents\FH\Python\venv\control\Lib\site-packages\sympy\core\expr.py:400, in Expr.__lt__(self, other)
397 @sympify_return([('other', 'Expr')], NotImplemented)
398 def __lt__(self, other):
399 from .relational import StrictLessThan
--> 400 return StrictLessThan(self, other)
File ~\Documents\FH\Python\venv\control\Lib\site-packages\sympy\core\relational.py:850, in _Inequality.__new__(cls, lhs, rhs, **options)
848 raise TypeError("Invalid comparison of non-real %s" % me)
849 if me is S.NaN:
--> 850 raise TypeError("Invalid NaN comparison")
851 # First we invoke the appropriate inequality method of `lhs`
852 # (e.g., `lhs.__lt__`). That method will try to reduce to
853 # boolean or raise an exception. It may keep calling
(...)
857 # exception). In that case, it must call us with
858 # `evaluate=False` to prevent infinite recursion.
859 return cls._eval_relation(lhs, rhs, **options)
TypeError: Invalid NaN comparison