find_root revision (argument evaluation)



Hello,

I have revised the find_root function so that it evaluates its arguments
in the same manner as most other Maxima functions
(by defining $FIND_ROOT with DEFUN instead of DEFMSPEC).
Also, if the function for which the root is sought returns a nonnumeric
value, find_root returns a find_root expression.
I believe these changes will reduce the number of messages
to the mailing list concerning find_root strangeness.

I didn't change the find_root algorithm; I wouldn't be
surprised if stronger seach algorithms are known.

I have committed changes to src/intpol.lisp and src/plot.lisp
and appended some additional find_root examples to tests/rtest8.mac,
which are shown below.

Hope this helps.

Robert

PS. find_root examples:
(%i1) batch ("/tmp/find_root_examples.mac", test);

Error log on #<FD-STREAM for "file /tmp/find_root_examples.ERR" {B5FF6C9}>
********************** Problem 1 ***************
Input:
find_root(2*x = -log((%e+4)/(2*%pi))*((%e+4)/(2*%pi))^x,x,-1,0)


Result:
-.03340289826874122

... Which was correct.

********************** Problem 2 ***************
Input:
find_root(2*x = cos((%pi+%e)*x),x,0,1)


Result:
.1984210505656873

... Which was correct.

********************** Problem 3 ***************
Input:
(expr:x^2-5,find_root(expr,x,0,10))


Result:
2.23606797749979

... Which was correct.

********************** Problem 4 ***************
Input:
(kill(a,b),find_root(x^a-5,x,0,10))


Result:
find_root(x^a-5,x,0.0,10.0)

... Which was correct.

********************** Problem 5 ***************
Input:
find_root(x^3-5,x,a,b)


Result:
find_root(x^3-5,x,a,b)

... Which was correct.

********************** Problem 6 ***************
Input:
quad_qags(find_root(x^a-5,x,0,10),a,1,3)


Result:
[5.05826377663869,3.544114210784957e-10,21,0]

... Which was correct.

********************** Problem 7 ***************
Input:
find_root(find_root(a^2 = x,a,0,x) = 7,x,0,100)


Result:
49.0

... Which was correct.

********************** Problem 8 ***************
Input:
(foo(a):=3^a-5,bar:foo,find_root(bar,0,10))


Result:
1.464973520717927

... Which was correct.

********************** Problem 9 ***************
Input:
(expr:t = (297*exp(1000000*t/33)-330)/10000000,
 find_root(expr,t,1.e-9,0.003))


Result:
1.7549783076857198e-5

... Which was correct.

********************** Problem 10 ***************
Input:
(expr:6096*tan(2*atan(c/(2*fl))/r)/tan(%pi/(60*180)),
 ev(find_root(expr = 6096,fl,1,10),c = 7.176,r = 3264))


Result:
6.98149293282488

... Which was correct.

********************** Problem 11 ***************
Input:
(g(a):=find_root(f(x,a),x,0,200),f(x,a):=x^a-5,0)


Result:
0

... Which was correct.

********************** Problem 12 ***************
Input:
g(0.5)


Result:
25.0

... Which was correct.

********************** Problem 13 ***************
Input:
expr:g(z+z)


Result:
find_root(x^(2*z)-5,x,0.0,200.0)

... Which was correct.

********************** Problem 14 ***************
Input:
find_root(x^0.5-5,x,0.0,200.0)


Result:
25.0

... Which was correct.

********************** Problem 15 ***************
Input:
quad_qags(g(z),z,1,3)


Result:
[5.05826377663869,3.544114210784957e-10,21,0]

... Which was correct.

********************** Problem 16 ***************
Input:
(f(x):=sin(x)-x/2,0)


Result:
0

... Which was correct.

********************** Problem 17 ***************
Input:
[find_root(sin(x)-x/2,x,0.1,%pi),
 find_root(sin(x) = x/2,x,0.1,%pi),find_root(f(x),x,0.1,%pi),
 find_root(f,0.1,%pi)]


Result:
[1.895494267033981,1.895494267033981,1.895494267033981,
 1.895494267033981]

... Which was correct.

********************** Problem 18 ***************
Input:
[find_root(f,1/(%pi*%e),2*%pi*sin(%e)),
 find_root(f,log(%pi),%e^%pi),
 find_root(f,exp(1/5),exp(cos(%pi+%e))),
 find_root(f,cos(exp(2))/10,10*cos(exp(2)))]


Result:
[1.895494267033981,1.895494267033981,1.895494267033981,
 1.895494267033981]

... Which was correct.

********************** Problem 19 ***************
Input:
(charfun2(z,l1,l2):=charfun(l1 <= z and z < l2),
 (-0.213+1.55*x-0.498*x^2+0.00117*x^3)*charfun2(x,1.0,1.5)
  +(-0.275+1.67*x-0.581*x^2+0.0195*x^3)*charfun2(x,1.5,2.0)
  +(-0.866+2.56*x-1.02*x^2+0.0933*x^3)*charfun2(x,2.0,2.5)
  +(-2.77+4.85*x-1.94*x^2+0.215*x^3)*charfun2(x,2.5,inf)
  +(0.117+0.559*x+0.494*x^2-0.329*x^3)*charfun2(x,minf,1.0),
 find_root(%%,x,0,4))


Result:
3.127271310605422

... Which was correct.
19/19 tests passed.
(%o1) []