Using a complex numbers library -- Apache math

Hello all, I’m working on a sketch for generating fractals and would like to replace my hand-rolled complex math functions with a “proper” library :slight_smile:

I’ve downloaded the jar for Adobe Commons Math to “sketchbook home”/libraries/acm/library/ but I can’t see how to import the library. I’d appreciate any tips. Thanks!

Toby

1 Like

It sounds weird:

Drag the jar file on the source code of your sketch in processing and drop it there

2 Likes

Apache Commons Math. I guess this is the one you mean (links are always nice).

I’m no expert, but tried to install this just now and it worked. It’s explained how here:
How to Install a Contributed Library.

Look at the bottom on how to install non-Processing libraries. I did as suggested, except I called the folder “ApacheCommonsMath”, renamed the “commons-math3-3.6.1.jar” file to the same name, made a sub-folder named “library” and put it there.

Then started the Processing IDE and selected menu: Sketch - Import library - ApacheCommonsMath.

There was a long list of imports, but probably not all are neccessary, depending on what you use.

If there are examples included with the library, I don’t know how to get those installed. I made a quick test from the statistics page:

/** Apache Commons Math test
 
 https://commons.apache.org/proper/commons-math/userguide/stat.html
 
*/


import org.apache.commons.math3.stat.descriptive.*;

float[] inputArray = new float[10];

for ( int i=0; i<10; i++) {
  inputArray[i] = (float) i;
}

// Get a DescriptiveStatistics instance
DescriptiveStatistics stats = new DescriptiveStatistics();

// Add the data from the array
for ( int i = 0; i < inputArray.length; i++) {
  stats.addValue(inputArray[i]);
}

// Compute some statistics
double mean = stats.getMean();
double std = stats.getStandardDeviation();
double median = stats.getPercentile(50);

println(mean);
println(std);
println(median);

exit();
2 Likes

Thanks a lot Chrisir! Your suggestion worked, and it auto-created a folder called ‘code’ in my sketch’s folder.

best!
Toby

2 Likes

Thanks a million raron. I should have read How to Install a Contributed Library myself, so apologies for that. Your solution was perfect and I am mathing away! best, Toby.