C, MathLink or Java, J/Link
- To: mathgroup at smc.vnet.net
- Subject: [mg28055] C, MathLink or Java, J/Link
- From: "Ersek, Ted R" <ErsekTR at navair.navy.mil>
- Date: Thu, 29 Mar 2001 03:24:20 -0500 (EST)
- Sender: owner-wri-mathgroup at wolfram.com
I am working on an algorithm and am puzzled about which way to proceed. I
always knew my algorithm would run much faster if I wrote it in C and used
Math Link. I recently decided to become proficient in C and MathLink so I
could do just that. But then I read in Todd Gayley's J/Link User Guide that
-- Java is the ideal language for writing programs that use the
computational services of Mathematica.
-- You can use Mathematica to in effect, write a Java program in
Mathematica.
-- Essentially anything you can do from Java you can now do from
Mathematica, perhaps even more easily.
-- Java is fast, robust, portable, and an excellent general-purpose
programming language.
-- Java with J/Link is easier than using the traditional MathLink interface
from C or C++.
-- The syntax and intricacies of the Java language are not relevant, since
you will be writing Mathematica programs, not Java ones.
After reading all these great things about Java and J/Link I am wondering if
I should write my program using Java and J/Link. Can anyone provide advice?
-----------------------------------
In case you are curious this is what I am trying to do:
Several months ago I started writing a Mathematica package that would try to
find all roots of a function f[x] over a real interval {x, xmin, xmax}. For
efficiency sake I only consider values for (x) that are machine numbers.
Rather than call the built-in function FindRoot a number of times I thought
it would be more efficient to develop an algorithm from the ground up. I
came up with an algorithm that starts off taking equally spaced samples, but
switches to Brent's method as a change in the sign of f[x] is found. I then
take more samples where the function does interesting things that may head
towards a root. Once the set of samples is sufficiently dense I make use of
Newton's method or secant method where roots are likely. However if these
methods recommend a new guess outside the interval where a root is likely to
reside, I use a Golden Section find minimum step instead. I also use a
Golden Section step if it the interval containing the approximate root is
converging too slowly. If f[xn] is not sufficiently close to zero after a
while I assume there is not a root in the neighborhood.
--------------------
Regards,
Ted Ersek
Download Mathematica tips, tricks from
http://www.verbeia.com/mathematica/tips/Tricks.html