What substitution were you thinking? I would expand the 2nd set and rewrite
in terms of exponentials and solve for them.
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]
eq=[i.expand(trig=1).rewrite(exp).subs(exp(I*a),var('A')).subs(exp(I*b),var("B")).as_numer_denom()[0]
for i in eq]
g = groebner(eq,(A,B))
solve(g,(A,B),simplify=0,verify=0)
which gives 3 solutions (but the one with A=0 is not valid, so just 2)
/c
On Tuesday, November 11, 2025 at 4:02:36 AM UTC-6 [email protected]
wrote:
> 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
>
> <http://localhost:8888/lab/tree/Teaching/RobReg/R2D/~/Documents/FH/Python/venv/control/Lib/site-packages/sympy/solvers/solvers.py#line=1169>,
>
> 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
>
> <http://localhost:8888/lab/tree/Teaching/RobReg/R2D/~/Documents/FH/Python/venv/control/Lib/site-packages/sympy/solvers/solvers.py#line=1962>,
>
> 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
>
> <http://localhost:8888/lab/tree/Teaching/RobReg/R2D/~/Documents/FH/Python/venv/control/Lib/site-packages/sympy/solvers/solvers.py#line=2637>,
>
> 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
>
> <http://localhost:8888/lab/tree/Teaching/RobReg/R2D/~/Documents/FH/Python/venv/control/Lib/site-packages/sympy/solvers/solvers.py#line=1742>,
>
> 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
>
> <http://localhost:8888/lab/tree/Teaching/RobReg/R2D/~/Documents/FH/Python/venv/control/Lib/site-packages/sympy/solvers/solvers.py#line=1743>,
>
> 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
>
> <http://localhost:8888/lab/tree/Teaching/RobReg/R2D/~/Documents/FH/Python/venv/control/Lib/site-packages/sympy/solvers/solvers.py#line=353>,
>
> 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
>
> <http://localhost:8888/lab/tree/Teaching/RobReg/R2D/~/Documents/FH/Python/venv/control/Lib/site-packages/sympy/core/decorators.py#line=247>,
>
> 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
> <http://localhost:8888/lab/tree/Teaching/RobReg/R2D/~/Documents/FH/Python/venv/control/Lib/site-packages/sympy/core/expr.py#line=399>,
>
> 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
>
> <http://localhost:8888/lab/tree/Teaching/RobReg/R2D/~/Documents/FH/Python/venv/control/Lib/site-packages/sympy/core/relational.py#line=849>,
>
> 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
>
--
You received this message because you are subscribed to the Google Groups
"sympy" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion visit
https://groups.google.com/d/msgid/sympy/ccf23788-3441-4742-bb8f-edb6a1b0dff2n%40googlegroups.com.