Page tree

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Published by Scroll Versions from space DEV and version r0821

The following example demonstrates how the POW and SQRT functions work together to compute the hypotenuse of a right triangle using the Pythagorean theorem.

  • POW - X Y . In this case, 10 to the power of the previous one. See POW Function
  • SQRT - computes the square root of the input value. See SQRT Function.

The Pythagorean theorem states that in a right triangle the length of each side (x,y) and of the hypotenuse (z) can be represented as the following:

z2 = x 2 + y 2  

Therefore, the length of z can be expressed as the following:

z = sqrt(x 2  + y 2 )

Source:

The dataset below contains values for x and y:

 

XY
34
49
810
3040

Transformation:

You can use the following transformation to generate values for z2

Info

NOTE: Do not add this step to your recipe right now.

D trans
RawWrangletrue
p03Value'Z'
Typestep
WrangleTextderive type:single value:(POW(x,2) + POW(y,2)) as:'Z'
p01NameFormula type
p01ValueSingle row formula
p02NameFormula
p02Value(POW(x,2) + POW(y,2))
p03NameNew column name
SearchTermNew formula

You can see how column Z is generated as the sum of squares of the other two columns, which yields z2.

Now, edit the transformation to wrap the value computation in a SQRT function. This step is done to compute the value for z, which is the distance between the two points based on the Pythagorean theorem.

D trans
RawWrangletrue
p03Value'Z'
Typestep
WrangleTextderive type:single value:SQRT((POW(x,2) + POW(y,2))) as: 'Z'
p01NameFormula type
p01ValueSingle row formula
p02NameFormula
p02ValueSQRT((POW(x,2) + POW(y,2)))
p03NameNew column name
SearchTermNew formula

Results:

XYZ
345
499.848857801796104
81012.806248474865697
304050