Trying to solve a 3rd degree polynomial and feed those coefficients into a solver to determine x given y (at eft 6 hrs what density should I expect). Im using 7.9 so is there any good solvers that I could use from Apache Commons or a good way to roll my own?
from org.apache.commons.math3.fitting import PolynomialCurveFitter as pcf
from org.apache.commons.math3.fitting import WeightedObservedPoints as wop
eft = [0.0, 7, 15, 23]
dcw = [0.583,0.72, 2.82, 7.29]
fitter = pcf.create(2)
tstPoints = wop()
for i in range(4):
time = eft[i]
density = dcw[i]
coeff = fitter.fit(tstPoints.toList())
for i in range(len(coeff)):
@JordanCClark 's library seems to have the functionality you need (and up to 5th degree polynomials it looks like).
But if finding roots of a 3rd degree polynomial is all you need, there is a formula for it you could hardcode by hand. The hard part I imagine would be handling the potential imaginary numbers that can arise The Cubic Formula
If you’re not comfortable using someone else’s library and or handling the imaginary numbers, you can always try implementing your own version of Newton’s method or some other numerical approximation method for finding roots for which you can find the process online.
Since we converting an Excel sheet to Ignition were just using the goal seek option in Excel to solve for x given y using the coefficients. Is there a good way to implement this in Ignition using some existing library?
I haven’t verified this personally but this post in stackoverflow -
uses the brent Method in java for finding roots. Read the entire post as there’s some caveats - only finds roots within your interval range, and only that are more than an interval size apart (in his example, more than .01 apart).
You can try replicating his code. You can start off with