Bart Vandewoestyne wrote:
> Dear list,
>
> I would like to obtain a numerical value for the variation of the
> third function at
>
> http://en.wikipedia.org/wiki/Bounded_variation#Examples
>
> namely, the one with x^2*sin(1/x).
>
> I would like to do this using Maxima. The integral I need to
> calculate is
>
> (%i8) integrate(abs(2*x*sin(x)-cos(1/x)), x, 0, 2/%pi);
> 2
> ---
> %pi
> /
> [ ! 1 !
> (%o8) I !2 x sin(x) - cos(-)! dx
> ] ! x !
> /
> 0
>
> However, maxima refuses to compute it.
>
> I have asked this question also on comp.soft-sys.math.maple and the
> strategy proposed there is to integrate between the zeros of
> 2*x*sin(x)-cos(1/x) and then sum all these values:
>
> http://groups.google.be/group/comp.soft-sys.math.maple/browse_thread/thread/b3710ca0dc842857/6aeeadd1f4eb2172?hl=nl&lnk=st&q=integral+group%3Acomp.soft-sys.math.maple+author%3AVandewoestyne#6aeeadd1f4eb2172
>
> Somebody in that thread even proposed an approximation for the zeros, which
> can then be used as starting points for Newton rootfinding.
>
> As I'm not yet too familiar with Maxima, I wasn't however able to translate
> the code snippets given there into Maxima yet... and sometimes it's hard
> to find in the reference manual how to do certain things...
>
> Can anybody help me in finding this integral, possibly translating the
> code snippets from the previously mentioned thread into Maxima?
>
> I really would like to do this using Open Source Software...
>
> Thanks,
> Bart
>
> --
> "Share what you know. Learn what you don't."
> _______________________________________________
> Maxima mailing list
> Maxima at math.utexas.edu
> http://www.math.utexas.edu/mailman/listinfo/maxima
> .
>
Actually, the function on the first web site is
(%i59) f(x):= abs(2*x*sin(1/x) - cos(1/x));
! 1 1 !
(%o59) f(x) := !2 x sin(-) - cos(-)!
! x x !
(%i60) quad_qag(f(x),x,0,2/%pi,6);
***MESSAGE FROM ROUTINE DQAG IN LIBRARY SLATEC.
***INFORMATIVE MESSAGE, PROG CONTINUES, TRACEBACK REQUESTED
* ABNORMAL RETURN
* ERROR NUMBER = 1
*
***END OF MESSAGE
(%o60) [.6053696439940823, 8.447929351350849E-4, 24339, 1]
So the approximate value (to 8E-4) is .605369
Note that this agrees with the value calculated (up to 1e-5) by the
Mathematica routine described in the maple web site.
Note that to find the zeroes of the function 2*x*sin(1/x) - cos(1/x) is
easy since, substituting u = 1/x this reduces to the problem of finding
the roots of
g(u) = tan(u) - u/2.
The tan function is periodic of period %pi, so, for u > 0, there is
exactly one root of g(u) in each interval [a_n, b_n] = [((2*n+1)/2)*%pi,
((2*n+3)/2)*%pi] for n >=0
So a root of g in [a_n,b_n] corresponds to a root of f in [1/b_n,
1/a_n]. This is the basis of the routine on the maple website alluded to
above. That routine uses FindRoot in Mathematica which I think is a type
of Newton routine. One could design a similar routine in maxima. It may
be that maxima's find_root routine works better.
-sen
P.S. Note: I did this fast and I only checked things once, so I may have
made mistakes. In that case, maybe they can be easily corrected.