# Using a complex numbers library -- Apache math

**URL:** https://discourse.processing.org/t/using-a-complex-numbers-library-apache-math/11771
**Category:** Libraries
**Created:** [June 2, 2019, 9:23am UTC](https://discourse.processing.org/t/using-a-complex-numbers-library-apache-math/11771 "2019-06-02T09:23:47Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![toby](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/toby/32/5434_2.png) [@toby](https://discourse.processing.org/u/toby)
#### Post date: [June 2, 2019, 9:23am UTC](https://discourse.processing.org/t/using-a-complex-numbers-library-apache-math/11771/1 "2019-06-02T09:23:47Z")

</div>

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 🙂

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

---

<div class="post-metadata">

### Author: ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)
#### Post date: [June 2, 2019, 10:49am UTC](https://discourse.processing.org/t/using-a-complex-numbers-library-apache-math/11771/2 "2019-06-02T10:49:06Z")

</div>

It sounds weird:

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

---

<div class="post-metadata">

### Author: ![raron](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/raron/32/13651_2.png) [@raron](https://discourse.processing.org/u/raron)
#### Post date: [June 2, 2019, 10:49am UTC](https://discourse.processing.org/t/using-a-complex-numbers-library-apache-math/11771/3 "2019-06-02T10:49:48Z")

</div>

Apache [Commons Math](https://commons.apache.org/proper/commons-math/index.html). 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](https://github.com/processing/processing/wiki/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:

```auto
/** 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();

```

---

<div class="post-metadata">

### Author: ![toby](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/toby/32/5434_2.png) [@toby](https://discourse.processing.org/u/toby)
#### Post date: [June 2, 2019, 6:07pm UTC](https://discourse.processing.org/t/using-a-complex-numbers-library-apache-math/11771/4 "2019-06-02T18:07:57Z")

</div>

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

best!  
Toby

---

<div class="post-metadata">

### Author: ![toby](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/toby/32/5434_2.png) [@toby](https://discourse.processing.org/u/toby)
#### Post date: [June 2, 2019, 6:10pm UTC](https://discourse.processing.org/t/using-a-complex-numbers-library-apache-math/11771/5 "2019-06-02T18:10:02Z")

</div>

Thanks a million raron. I should have read [How to Install a Contributed Library](https://github.com/processing/processing/wiki/How-to-Install-a-Contributed-Library) myself, so apologies for that. Your solution was perfect and I am mathing away! best, Toby.
