We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpOther Libraries › How to use math commons library within processing
Page Index Toggle Pages: 1
How to use math commons library within processing? (Read 1698 times)
How to use math commons library within processing?
Dec 12th, 2009, 7:57pm
 
MODIFIED:
I just got processing to recognize the library in that it is now listed under the sketch/import library tab.  Problem now is that it doesn't seem to recognize the functions.  I get errors like "The function nextDouble() does not exist, etc.  Any ideas.  Oh, I did have to change the folder names to exclude any hypens and periods.  Does that matter?

ORIGINAL:
Hi.  I am interested in using some of the advanced math capabilities of the math commons (java-based) library.  The website for it is:

commons.apache.org/math/

I imagine this is easy to do since it's java-based, but I'm new both to java and processing.  Anybody know how to download the files (which version I need), where to put them and how to include them in processing programs?  

Also, if I make an application using them, will the appropriate functions automatically be included so the end user wouldn't have to download the math commons library?

Sorry for so many separate questions in a single post.  I'm looking forward to tapping into, and learning from the vast experience of this user group Smiley
Re: How to use math commons library within processing?
Reply #1 - Dec 13th, 2009, 6:20am
 
do you have the correct imports at the top of your file?
(import org.apache.commons.math.random;)

do the methods work if you use fully qualified names in your code?
(org.apache.commons.math.random.nextDouble())

(you need one or the other, not both. and the first is a lot less typing)
Re: How to use math commons library within processing?
Reply #2 - Dec 14th, 2009, 1:09pm
 
Hi drtimo

I suspect that the problem is that you only have the source files for the apache math commons library.

What you actually need is a jar file created from the source.

I have created the necessary jar file which if you click on the link below and select save file will be yours.
www.lagers.org.uk/temp/acm.jar

How to use it with Processing
Inside the Processing sketch folder there will be a folder called libraries inside that create a folder called acm and inside that create a folder called library inside that folder place the acm.jar file you saved.

Now open Processing and select Skecth>Import Library and select acm.

This will give you full access to all the apache commons libraries.

Oh by the way the jar file is ~760kB and when used in Processing will put 37 import statements - it's a BIG library.

Smiley
Re: How to use math commons library within processing?
Reply #3 - Dec 15th, 2009, 8:23pm
 
Thanks so much for the replies.  Answer to the first question by koogy about if I put the full import line in is yes.  And it wasn't working still.
I will try the recommended .jar files from Quark and update you guys on my success toward the weekend when I manage to find the time to get back to the project.  Thanks so much for the replies.
Re: How to use math commons library within processing?
Reply #4 - Dec 15th, 2009, 9:08pm
 
Ok, so I did everything recommended, and it seems like the library might be working now, and that perhaps I just don't know how to use yet.  I attempted to use the polynomial fitter with the following code:

int degree = 3;
PolynomialFitter fitter = new PolynomialFitter(degree, new LevenbergMarquardtOptimizer());
fitter.addObservedPoint(1, -1.00, 2.0211700);
fitter.addObservedPoint(1, -0.99, 2.2232134);
fitter.addObservedPoint(1, -0.98, 2.0998527);
fitter.addObservedPoint(1, -0.97, 2.0211192);
fitter.addObservedPoint(1,  0.99, -2.434581);
PolynomialFunction fitted = fitter.fit();

I get an error reading:
Unhandled exception type OptimizationException

Any ideas?
Re: How to use math commons library within processing?
Reply #5 - Dec 16th, 2009, 12:19am
 
you need a try catch around that block of code to catch and handle errors it may produce.

this is more of a java question than a processing question so have a read of the sun java tutorials on exceptions. but for the moment

try {
 // the code that declares itself to throw the exception
 ...
} catch (Exception e) {
 // error reporting
 println("Error: " + e);
 e.printStackTrace();
 System.exit();
}
Page Index Toggle Pages: 1