Hello,
I have a set of equations of the form (or close to this form):
(1) A = Bx + Cy
(2) D = Ez + Fy
(3) G = Ht + Iy
…
(n) 1 = x + y + z + t + …
Some complicating factors:
The number of equations is flexible but I believe that it will always be a linear system.
The equality is actually a range (ie 0 <= A <= 1, 0.5 <= D <= 1.5, etc.) and any solution within the range which satisfies the system is valid.
The number of terms in each linear equation is variable.
There is no guarantee a solution exists.
I’m 99% sure these will all boil down to a linear system BUT if it turns out to be non-linear what is the play?
All capital letters are constants or knowns and the lower case letters are variables. What is the best way to import this into KNIME and solve for the variables?
A colleague suggested looking at the optimization workflow examples in KNIME but I figured I’d also post this question since I didn’t see it on the forum.
Hi.
One approach would be to leverage the Java library Apache commons math 3 in a Java Snippet node.
See Math – The Commons Math User Guide - Linear Algebra
One can add the library under the “Additional Bundles” tab of the Java Snippet configuration dialog.
I threw together a quick example that allows one to specify the columns containing equation terms, as well the column containing the constants. The solution (if there is one) is output as a variable called coefficients (a comma-separated string of doubles (currently, variables of type double array aren’t fully supported in version 4.3)). The corresponding column names are output as a variable called termColsString. The input columns must be of type double. The example attached solves the following system of linear equations:
2x + 3y - 2z = 1
-x + 7y + 6x = -2
4x - 3y - 5z = 1
Here’s the corresponding input table:
and the output variables:
Sorry I don’t have time to add refinements like error checking or gracefully alerting when there is no solution, etc. Also, I haven’t had time to extensively test the solution. In any case, hope this helps / gets you started.
-Don solving system of linear eqns.knwf (21.7 KB)