#2458 to_poly_solve gives a wrong solution for cos(x)=sin(3x)

open
nobody
5
2012-11-18
2012-08-16
Jean-Yves
No

Hi,

When doing:
load(to_poly_solve);
algexact:true;
to_poly_solve(cos(x)-sin(3*x),x);

I get:
to_poly_solve: to_poly_solver.mac is obsolete; I'm loading to_poly_solve.mac instead.
%union([x=-(4*%pi*%z0+%pi)/4],[x=(4*%pi*%z1+%pi)/8])

But I think that the first solution should be (based on hand solving): (4*%pi*%z0+%pi)/4 (no minus sign).

For example: if we consider %z0 = 0 in the to_poly_solve solution, we get x=-%pi/4 which is not a solution of the equation cos(x)-sin(3*x). On the other hand, if we set %z0 = 0 in the hand found solution, we get x=%pi/4 which is a solution.

The build_info is: build_info("5.27.0","2012-05-08 11:27:57","i686-pc-mingw32","GNU Common Lisp (GCL)","GCL 2.6.8").

Best regards,

Jean-Yves

Discussion

  • Aleksas

    Aleksas - 2012-08-31

    To finding all solutions of trigonometric equation eq
    from interval [a, b] we define function "trigsolve":

    (%i1) trigsolve(eq,a,b):=block([s,i,ats,algebraic],
    algebraic:true,
    to_poly_solve([eq], [x],'simpfuncs =
    ['rootscontract,'expand,'radcan,'nicedummies]),
    s:makelist(rhs(part(%%,k)[1]),k,1,length(%%)),
    ats:[],
    for i:1 thru length(s) do
    (makelist(ev(s[i],%z0=k),k,-10,10),
    ats:append(ats,%%)),
    sublist(ats,lambda([e],e>=a and e<=b and
    float(ev(abs(lhs(eq)-rhs(eq)),x=e))<ratepsilon)),
    sort(%%), setify(%%)
    )$

    Example: solve cos(x)-sin(3*x)=0

    (%i2) eq:cos(x)-sin(3*x)=0$
    (%i3) cos(x)-cos(y)=-2*sin(1/2*x+1/2*y)*sin(1/2*x-1/2*y)$
    (%i4) subst(y=3*x-%pi/2,%),expand;
    (%o4) cos(x)-sin(3*x)=2*sin(x-%pi/4)*sin(2*x-%pi/4)
    (%i5) eq1:sin(x-%pi/4)=0$
    (%i6) eq2:sin(2*x-%pi/4)=0$
    (%i7) S1:trigsolve(eq1,-%pi,%pi);
    to_poly_solve: to_poly_solver.mac is obsolete; I'm loading to_poly_solve.mac instead.
    Loading maxima-grobner $Revision: 1.6 $ $Date: 2009-06-02 07:49:49 $
    (%o7) {-(3*%pi)/4,%pi/4}
    (%i8) S2:trigsolve(eq2,-%pi,%pi);
    (%o8) {-(7*%pi)/8,-(3*%pi)/8,%pi/8,(5*%pi)/8}
    (%i9) S:union(S1,S2);
    (%o9) {-(7*%pi)/8,-(3*%pi)/4,-(3*%pi)/8,%pi/8,%pi/4,(5*%pi)/8}
    (%i10) float(%), numer;
    (%o10) {-2.748893571891069,-2.356194490192345,-1.178097245096172,0.39269908169872,0.78539816339745,1.963495408493621}

    Answer: x=a+2*%pi*k, where a - any from S, k - any integer

    (%i11) plot2d([cos(x)-sin(3*x)], [x,-%pi,%pi])$

     
  • Jean-Yves

    Jean-Yves - 2012-09-01

    Aleksasd,

    I agree with you regarding your calculations. However, when I apply the function "trigsolve" to the equation, I get:

    trigsolve(cos(x)-sin(3*x),-%pi,%pi);
    {-(7*%pi)/8,-(3*%pi)/8,%pi/8,(5*%pi)/8}

    Several solutions are missing (e.g. %pi/4) because of the bug I highlighted.

    Best regards,

    Jean-Yves

     

Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks