| 1 | initial version |
Well...
sage: var('x tb');
sage: Ra=1/2; Rb=3; ta=pi/2;
sage: Sys = [Ra*cos(ta)+Rb*cos(tb)==x, Ra*sin(ta)+Rb*sin(tb)==0] ; Sys
[3*cos(tb) == x, 3*sin(tb) + 1/2 == 0]
Sage's default solver (i. e. Maxima's) isn't especially good at solving trigonometric systems :
sage: solve(Sys, [x, tb])
[3*cos(tb) == x, 3*sin(tb) + 1/2 == 0]
sage: solve(Sys, [x, tb], to_poly_solve=True)
[3*cos(tb) == x, 3*sin(tb) + 1/2 == 0]
sage: solve(Sys, [x, tb], to_poly_solve="force")
[3*cos(tb) == x, 3*sin(tb) + 1/2 == 0]
but Sympy's can solve this one :
sage: solve(Sys, [x, tb], algorithm="sympy")
[{tb: pi + arcsin(1/6), x: -1/2*sqrt(35)}, {tb: -arcsin(1/6), x: 1/2*sqrt(35)}]
(and, FWIW, so can the gratis Wolfram engine :
sage: mathematica.Solve(Sys, [x, tb])
{{x -> -Sqrt[35]/2, tb -> ConditionalExpression[-Pi + ArcTan[1/Sqrt[35]] +
2*Pi*C[1], Element[C[1], Integers]]},
{x -> Sqrt[35]/2, tb -> ConditionalExpression[-ArcTan[1/Sqrt[35]] +
2*Pi*C[1], Element[C[1], Integers]]}}
but that's hardly surprising...).
More interesting is the general case (i. e. non-constant Ra, Rb, ta) :
sage: var("Ra, Rb, ta");
sage: Sys = [Ra*cos(ta)+Rb*cos(tb)==x, Ra*sin(ta)+Rb*sin(tb)==0]
Maxima can't solve this (no surprise...) :
sage: solve(Sys, [x, tb])
[Ra*cos(ta) + Rb*cos(tb) == x, Ra*sin(ta) + Rb*sin(tb) == 0]
sage: solve(Sys, [x, tb], to_poly_solve="force")
[Ra*cos(ta) + Rb*cos(tb) == x, Ra*sin(ta) + Rb*sin(tb) == 0]
but Sympy (and Mathematica) can :
sage: solve(Sys, [x, tb], algorithm="sympy")
[{tb: pi + arcsin(Ra*sin(ta)/Rb),
x: Ra*cos(ta) - sqrt(-Ra^2*sin(ta)^2/Rb^2 + 1)*Rb},
{tb: -arcsin(Ra*sin(ta)/Rb),
x: Ra*cos(ta) + sqrt(-Ra^2*sin(ta)^2/Rb^2 + 1)*Rb}]
sage: mathematica.Solve(Sys, [x, tb])
{{x -> Ra*Cos[ta] - Sqrt[Rb^2 - Ra^2*Sin[ta]^2],
tb -> ConditionalExpression[ArcTan[-(Sqrt[Rb^2 - Ra^2*Sin[ta]^2]/Rb),
-((Ra*Sin[ta])/Rb)] + 2*Pi*C[1], Element[C[1], Integers]]},
{x -> Ra*Cos[ta] + Sqrt[Rb^2 - Ra^2*Sin[ta]^2],
tb -> ConditionalExpression[ArcTan[Sqrt[Rb^2 - Ra^2*Sin[ta]^2]/Rb,
-((Ra*Sin[ta])/Rb)] + 2*Pi*C[1], Element[C[1], Integers]]}}
HTH,
| 2 | No.2 Revision |
Well...
sage: var('x tb');
sage: Ra=1/2; Rb=3; ta=pi/2;
sage: Sys = [Ra*cos(ta)+Rb*cos(tb)==x, Ra*sin(ta)+Rb*sin(tb)==0] ; Sys
[3*cos(tb) == x, 3*sin(tb) + 1/2 == 0]
Sage's default solver (i. e. Maxima's) isn't especially good at solving trigonometric systems :
sage: solve(Sys, [x, tb])
[3*cos(tb) == x, 3*sin(tb) + 1/2 == 0]
sage: solve(Sys, [x, tb], to_poly_solve=True)
[3*cos(tb) == x, 3*sin(tb) + 1/2 == 0]
sage: solve(Sys, [x, tb], to_poly_solve="force")
[3*cos(tb) == x, 3*sin(tb) + 1/2 == 0]
but Sympy's can solve this one :
sage: solve(Sys, [x, tb], algorithm="sympy")
[{tb: pi + arcsin(1/6), x: -1/2*sqrt(35)}, {tb: -arcsin(1/6), x: 1/2*sqrt(35)}]
(and, FWIW, so can the gratis Wolfram engine :
sage: mathematica.Solve(Sys, [x, tb])
{{x -> -Sqrt[35]/2, tb -> ConditionalExpression[-Pi + ArcTan[1/Sqrt[35]] +
2*Pi*C[1], Element[C[1], Integers]]},
{x -> Sqrt[35]/2, tb -> ConditionalExpression[-ArcTan[1/Sqrt[35]] +
2*Pi*C[1], Element[C[1], Integers]]}}
but that's hardly surprising...).
More interesting is the general case (i. e. non-constant Ra, Rb, ta) :
sage: var("Ra, Rb, ta");
sage: Sys = [Ra*cos(ta)+Rb*cos(tb)==x, Ra*sin(ta)+Rb*sin(tb)==0]
Maxima can't solve this (no surprise...) :
sage: solve(Sys, [x, tb])
[Ra*cos(ta) + Rb*cos(tb) == x, Ra*sin(ta) + Rb*sin(tb) == 0]
sage: solve(Sys, [x, tb], to_poly_solve="force")
[Ra*cos(ta) + Rb*cos(tb) == x, Ra*sin(ta) + Rb*sin(tb) == 0]
but Sympy (and Mathematica) can :
sage: solve(Sys, [x, tb], algorithm="sympy")
[{tb: pi + arcsin(Ra*sin(ta)/Rb),
x: Ra*cos(ta) - sqrt(-Ra^2*sin(ta)^2/Rb^2 + 1)*Rb},
{tb: -arcsin(Ra*sin(ta)/Rb),
x: Ra*cos(ta) + sqrt(-Ra^2*sin(ta)^2/Rb^2 + 1)*Rb}]
sage: mathematica.Solve(Sys, [x, tb])
{{x -> Ra*Cos[ta] - Sqrt[Rb^2 - Ra^2*Sin[ta]^2],
tb -> ConditionalExpression[ArcTan[-(Sqrt[Rb^2 - Ra^2*Sin[ta]^2]/Rb),
-((Ra*Sin[ta])/Rb)] + 2*Pi*C[1], Element[C[1], Integers]]},
{x -> Ra*Cos[ta] + Sqrt[Rb^2 - Ra^2*Sin[ta]^2],
tb -> ConditionalExpression[ArcTan[Sqrt[Rb^2 - Ra^2*Sin[ta]^2]/Rb,
-((Ra*Sin[ta])/Rb)] + 2*Pi*C[1], Element[C[1], Integers]]}}
EDIT : Coaxing Maxima's default solver to give a solution.
You have a system of two equatins with three unknowns ; one of the has to mecome a parametter of the solution(s). Choosing ta as a parameter allows us to write :
sage: S1 = Sys[1].solve(tb) ; S1
[tb == -arcsin(Ra*sin(ta)/Rb)]
sage: Sol = S1+Sys[0].subs(S1).solve(x) ; Sol
[tb == -arcsin(Ra*sin(ta)/Rb),
x == Ra*cos(ta) + sqrt(-Ra^2*sin(ta)^2/Rb^2 + 1)*Rb]
The (almost) equivalence of this answer and those given by Sympy ant dhe Wolfram engine is left as an (interesting !) exercise to the reader...
HTH,
| 3 | No.3 Revision |
Well...
sage: var('x tb');
sage: Ra=1/2; Rb=3; ta=pi/2;
sage: Sys = [Ra*cos(ta)+Rb*cos(tb)==x, Ra*sin(ta)+Rb*sin(tb)==0] ; Sys
[3*cos(tb) == x, 3*sin(tb) + 1/2 == 0]
Sage's default solver (i. e. Maxima's) isn't especially good at solving trigonometric systems :
sage: solve(Sys, [x, tb])
[3*cos(tb) == x, 3*sin(tb) + 1/2 == 0]
sage: solve(Sys, [x, tb], to_poly_solve=True)
[3*cos(tb) == x, 3*sin(tb) + 1/2 == 0]
sage: solve(Sys, [x, tb], to_poly_solve="force")
[3*cos(tb) == x, 3*sin(tb) + 1/2 == 0]
but Sympy's can solve this one :
sage: solve(Sys, [x, tb], algorithm="sympy")
[{tb: pi + arcsin(1/6), x: -1/2*sqrt(35)}, {tb: -arcsin(1/6), x: 1/2*sqrt(35)}]
(and, FWIW, so can the gratis Wolfram engine engine :
sage: mathematica.Solve(Sys, [x, tb])
{{x -> -Sqrt[35]/2, tb -> ConditionalExpression[-Pi + ArcTan[1/Sqrt[35]] +
2*Pi*C[1], Element[C[1], Integers]]},
{x -> Sqrt[35]/2, tb -> ConditionalExpression[-ArcTan[1/Sqrt[35]] +
2*Pi*C[1], Element[C[1], Integers]]}}
but that's hardly surprising...).
More interesting is the general case (i. e. non-constant Ra, Rb, ta) :
sage: var("Ra, Rb, ta");
sage: Sys = [Ra*cos(ta)+Rb*cos(tb)==x, Ra*sin(ta)+Rb*sin(tb)==0]
Maxima can't solve this (no surprise...) :
sage: solve(Sys, [x, tb])
[Ra*cos(ta) + Rb*cos(tb) == x, Ra*sin(ta) + Rb*sin(tb) == 0]
sage: solve(Sys, [x, tb], to_poly_solve="force")
[Ra*cos(ta) + Rb*cos(tb) == x, Ra*sin(ta) + Rb*sin(tb) == 0]
but Sympy (and Mathematica) can :
sage: solve(Sys, [x, tb], algorithm="sympy")
[{tb: pi + arcsin(Ra*sin(ta)/Rb),
x: Ra*cos(ta) - sqrt(-Ra^2*sin(ta)^2/Rb^2 + 1)*Rb},
{tb: -arcsin(Ra*sin(ta)/Rb),
x: Ra*cos(ta) + sqrt(-Ra^2*sin(ta)^2/Rb^2 + 1)*Rb}]
sage: mathematica.Solve(Sys, [x, tb])
{{x -> Ra*Cos[ta] - Sqrt[Rb^2 - Ra^2*Sin[ta]^2],
tb -> ConditionalExpression[ArcTan[-(Sqrt[Rb^2 - Ra^2*Sin[ta]^2]/Rb),
-((Ra*Sin[ta])/Rb)] + 2*Pi*C[1], Element[C[1], Integers]]},
{x -> Ra*Cos[ta] + Sqrt[Rb^2 - Ra^2*Sin[ta]^2],
tb -> ConditionalExpression[ArcTan[Sqrt[Rb^2 - Ra^2*Sin[ta]^2]/Rb,
-((Ra*Sin[ta])/Rb)] + 2*Pi*C[1], Element[C[1], Integers]]}}
EDIT : Coaxing Maxima's default solver to give a solution.
You have a system of two equatins equations with three unknowns ; one of the has to mecome become a parametter of the solution(s). Choosing ta as a parameter allows us to write :
sage: S1 = Sys[1].solve(tb) ; S1
[tb == -arcsin(Ra*sin(ta)/Rb)]
sage: Sol = S1+Sys[0].subs(S1).solve(x) ; Sol
[tb == -arcsin(Ra*sin(ta)/Rb),
x == Ra*cos(ta) + sqrt(-Ra^2*sin(ta)^2/Rb^2 + 1)*Rb]
The (almost) equivalence of this answer and those given by Sympy ant dhe the Wolfram engine is left as an (interesting !) exercise to the reader...
HTH,
Copyright Sage, 2010. Some rights reserved under creative commons license. Content on this site is licensed under a Creative Commons Attribution Share Alike 3.0 license.