# Testing the "org.apache.commons.math3.analysis.interpolation"

**URL:** <https://forum.inductiveautomation.com/t/testing-the-org-apache-commons-math3-analysis-interpolation/74601>\
**Category:** Ignition\
**Tags:** ignition81, perspective\
**Created:** [June 5, 2023, 11:15pm UTC](https://forum.inductiveautomation.com/t/testing-the-org-apache-commons-math3-analysis-interpolation/74601 "2023-06-05T23:15:01Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![uy\_huynh](https://avatars.discourse-cdn.com/v4/letter/u/54ee81/32.png) [@uy\_huynh](https://forum.inductiveautomation.com/u/uy_huynh)\
**Post date:** [June 5, 2023, 11:15pm UTC](https://forum.inductiveautomation.com/t/testing-the-org-apache-commons-math3-analysis-interpolation/74601/1 "2023-06-05T23:15:01Z")

</div>

Hi all,  
I'm trying to test the math3 interpolation to find a desired interpolated value based on a x input. I've got the following code:

```auto
import system
	from org.apache.commons.math3.analysis.interpolation import LinearInterpolator
	from org.apache.commons.math3.analysis.polynomials import PolynomialSplineFunction
	
	# Example data points
	x_data = [18, 19, 20, 21, 22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42] # Replace with your x values
	y_data = [35,39,43,44,45,47,49,51,52,52,53,54,55,55,56,57,57,58,58,59,59,59,60,60,60] # Replace with your y values
	
	# Create a linear interpolator
	interpolator = LinearInterpolator()
	interpolation_function = interpolator.interpolate(x_data, y_data)
	
	# Find the value on the curve at a given point
	x_value = 18 # Replace with the desired x value
	interpolated_value = interpolation_function.value(x_value)
	
	# Print the interpolated value
	system.tag.writeAsync("[default]site_lathe/graph/DesiredRecovery",interpolated_value)

```

It worked!  
Then, I changed the xvalue = 18 to something like x\_value = system.tag.read(" a path to a memory float tag"), and error in gateway said:

org.python.core.PyException: TypeError: value(): 1st arg can't be coerced to org.apache.commons.math3.analysis.differentiation.DerivativeStructure, double

Any advises will be much appreciated!

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [June 5, 2023, 11:38pm UTC](https://forum.inductiveautomation.com/t/testing-the-org-apache-commons-math3-analysis-interpolation/74601/2 "2023-06-05T23:38:58Z")

</div>

Ignition's tag reading functions return [Qualified Value](https://docs.inductiveautomation.com/display/DOC81/Scripting+Object+Reference#ScriptingObjectReference-QualifiedValue) objects. You probably want something more like: `x_value = system.tag.read(" a path to a memory float tag").value`

---

<div class="post-metadata">

**Author:** ![uy\_huynh](https://avatars.discourse-cdn.com/v4/letter/u/54ee81/32.png) [@uy\_huynh](https://forum.inductiveautomation.com/u/uy_huynh)\
**Post date:** [June 5, 2023, 11:50pm UTC](https://forum.inductiveautomation.com/t/testing-the-org-apache-commons-math3-analysis-interpolation/74601/3 "2023-06-05T23:50:50Z")

</div>

Spot on PGriffith!

---

<div class="post-metadata">

**Author:** ![Rahul\_Bhakte1](https://avatars.discourse-cdn.com/v4/letter/r/c89c15/32.png) [@Rahul\_Bhakte1](https://forum.inductiveautomation.com/u/Rahul_Bhakte1)\
**Post date:** [July 18, 2024, 11:37am UTC](https://forum.inductiveautomation.com/t/testing-the-org-apache-commons-math3-analysis-interpolation/74601/4 "2024-07-18T11:37:32Z")

</div>

Hello folks,  
Just need some clarity.  
I found below lines code in one of the Ignition exchange projects.

```python
# Java Imports
from org.apache.commons.math3.ml.clustering import Clusterable
from org.apache.commons.math3.ml.clustering.evaluation import ClusterEvaluator
from org.apache.commons.math3.ml.clustering.evaluation import SumOfClusterVariances
from org.apache.commons.math3.ml.clustering import CentroidCluster

```

I have doubt that are these lines pointing to apache website or these libraries are already in Ignition? If yes then where are they located?

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [July 18, 2024, 1:22pm UTC](https://forum.inductiveautomation.com/t/testing-the-org-apache-commons-math3-analysis-interpolation/74601/5 "2024-07-18T13:22:59Z")

</div>

These math libraries are automatically included in Ignition, specifically for use in scripting. They're on the filesystem on the gateway, but you shouldn't do anything to those files on disk. The import statement simply loads the data that's already there into the current scripting scope, it's not fetching anything over the network.

---

<div class="post-metadata">

**Author:** ![Rahul\_Bhakte1](https://avatars.discourse-cdn.com/v4/letter/r/c89c15/32.png) [@Rahul\_Bhakte1](https://forum.inductiveautomation.com/u/Rahul_Bhakte1)\
**Post date:** [July 22, 2024, 9:48am UTC](https://forum.inductiveautomation.com/t/testing-the-org-apache-commons-math3-analysis-interpolation/74601/6 "2024-07-22T09:48:02Z")

</div>

Got it. Thank you @paul-griffith
