Question on Comparison and Checking

Hi everyone,

Using Rule of Engine, how can I compare columns and check if the value is true or false.

For instance I need to check if the calculations for a volume of sphere is correct.

Column A is the Radius
Column B is Pie (3.142)
Column C is the volume of the sphere

Formula: 4/3 * Pie * Radius ^3
my formula is : if (4/3 * Column A^3 * Column B) == Column C => True Else False

Hi @Hey_Matthew , this cannot be done with the Rule Engine as unfortunately it cannot perform calculations, but can only handle comparisons between columns and literals.

If you are using KNIME 5.3 or later, the new Expression node is ideally suited for this.

You can give it the following formula:

if (4/3* $["Column B"]* pow($["Column A"],3) = $["Column C"], TRUE, FALSE)

or, in fact because you simply want to return the logical result you could write it more simply as:

4/3* $["Column B"]* pow($["Column A"],3) = $["Column C"]

Note, that the Expression node also has a constant for Pi, so you don’t need it as a separate column. For example, if you had columns named “Radius” and “Volume of Sphere” you could write it as:

4/3 * PI * pow($["Radius"],3) = $["Volume of Sphere"]

If you need to allow for small rounding errors, you could write it like this:

abs(4/3 * PI * pow($["radius"],3) - $["volume of sphere"] ) < 0.00001
2 Likes

Try this. Rounding errors are tricky. As @takbb said, the Column Expressions node is more elegant, but requires a small bit of “coding”.
Volume of Sphere.knwf (121.0 KB)


1 Like

Thank you so much! It really helps in the given formula.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.