More solve curiosities

Doug Meade's picture

It's a new day, but not a new problem.

Yesterday I asked about solving inequalities with abs. Today I am looking at solving an equation with abs.

Try the following:

restart;
q :=  sin(x)/x - 1:
test4 := y -> [ y,
                solve( q=y, x ),
                [solve( abs(q)=y, x )],
                fsolve( q=y, x ),
                fsolve( abs(q)=y, x ) ]:
test4(  0  );
test4( 0.1 );
test4( 0.5 );
test4( 1/2 );
test4(  1  );

[                         /sin(x)           \                -13]
[ 0,   0, [0],      fsolve|------ - 1 = 0, x|, 1.869896012 10   ]
[                         \  x              /                   ]

[                         /sin(x)             \               ]
[0.1, 0., [0., 0.], fsolve|------ - 1 = 0.1, x|, -0.7866830720]
[                         \  x                /               ]

[                         /sin(x)             \              ]
[0.5, 0., [0., 0.], fsolve|------ - 1 = 0.5, x|, -1.895494267]
[                         \  x                /              ]

[ 1                                         /sin(x)       1   \              ]
[ - , 0, [0, RootOf(_Z - 2 sin(_Z))], fsolve|------ - 1 = -, x|, -1.895494267]
[ 2                                         \  x          2   /              ]

[                      /sin(x)           \              ]
[ 1,  0, [0, 0], fsolve|------ - 1 = 1, x|, -3.141592654]
[                      \  x              /              ]

At first, it is impressive that Maple seems to be able to solve sin(x)/x=1 and get x=0. But, looking at the results with other values of the RHS, it become obvious that Maple returns 0 for almost any RHS.

Putting an abs in the problem causes Maple to report the "solution" at x=0 twice. Based on yesterday's experience, I presume the multiple solutions are arising from Maple's attempt to separate the abs into two pieces. If so, then x=0 is only in one of the two subintervals but is never in the domain of the function, so should never be returned as an answer from solve.

Moving to fsolve, it's shocking (to me) that fsolve is unable to find a solution only in the cases where abs is used.

Each of these results is disappointing.

Comments? Explanations? Solutions?

Hoping for some enlightenment,

Doug

Comments

Robert Israel's picture

fsolve and solve

The possible values of sin(x)/x - 1 for x real are all negative, so it's not at all surprising to me that fsolve fails to find a solution for sin(x)/x - 1 = y when y > 0.
It's somewhat curious that it also fails for y = 0, but certainly not a bug: after all, sin(0)/0 is undefined.
That solve finds 0 as a solution for sin(x)/x - 1 = y when y is nonzero, on the other hand, is a bug. Of course what it's doing is multiplying the equation by x and solving sin(x) - x = x*y, then neglecting to notice that this isn't equivalent to the original equation when x=0.

acer's picture

variant

> fsolve(sin(x)/x-1=0,x=Pi);
0.

That's not so good.

acer

Doug Meade's picture

why two roots

How is Maple finding a repeated root of 0?

If it's splitting the abs into a piecewise, then 0 is only in the domain for one piece. Is this there another explanation for the double roots?

---------------------------------------------------------------------
Douglas B. Meade
Math, USC, Columbia, SC 29208  E-mail: mailto:meade@math.sc.edu       
Phone:  (803) 777-6183         URL:    http://www.math.sc.edu/~meade/
acer's picture

SolveTools:-Transformers

One can follow what happens, in the debugger.

Below, I followed some of what happens for the example solve(abs(-sin(x)/x+1) = 1, x).

One routine in which action takes place here is `solve/rec2`. It sets up a SYSTEM, first, as,

[[{abs(-sin(x)/x+1) = 1}, {}, {x}, {}, true, false, 1, {x}]]

Then, it makes calls to SolveTools:-Transformers[i] on SYSTEM. The transformers, i, which seems to affect this example include Abs and Inequality (I think).

The Abs Transformer turns SYSTEM into this,

[[{z+sin(x)/x-1, z-1, 0 < z}, {}, {x, z}, {}, true, false, 1, {x}],
[{z-sin(x)/x+1, z-1, 0 < z}, {}, {x, z}, {}, true, false, 1, {x}], [{z+sin(x)/x-1, z, z-1}, {}, {x, z}, {}, true, false, 1, {x}]]

The Inequality Transformer then turns it into this,

[[{z+sin(x)/x-1, z-1, 0 < z}, {}, {x, z}, [{z = 1, x = 0}], true, true, 1, {x}],
[{z-sin(x)/x+1, z-1, 0 < z}, {}, {x, z}, [{z = 1, x = 0}], true, true, 1, {x}],
[{z+sin(x)/x-1, z, z-1}, {}, {x, z}, {}, true, false, 1, {x}]]

That SYSTEM finally gets passed to SolveTools:-MakeSolutions, which returns [{x = 0}, {x = 0}].

One would have to know what the members in the system format mean, to know whether either Transformer is doing something unjustified. One could also follow it into SolveTools:-MakeSolutions, but I haven't done that..

acer

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
}