rtoy / maxima

A Clone of Maxima's repo
Other
0 stars 0 forks source link

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

Open rtoy opened 3 days ago

rtoy commented 3 days ago

Imported from SourceForge on 2024-07-02 15:31:15 Created by jyoberle on 2012-08-16 00:46:34 Original: https://sourceforge.net/p/maxima/bugs/2458


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

rtoy commented 3 days ago

Imported from SourceForge on 2024-07-02 15:31:16 Created by aleksasd on 2012-08-31 15:03:34 Original: https://sourceforge.net/p/maxima/bugs/2458/#630d


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])$

rtoy commented 3 days ago

Imported from SourceForge on 2024-07-02 15:31:18 Created by jyoberle on 2012-09-01 22:24:25 Original: https://sourceforge.net/p/maxima/bugs/2458/#2519


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