Derivatives (rate of change)

Version 5

    Description:

     

    This calculation computes the approximate rate of change at each point of a function f(x), using finite differences.

     

    Example Calculation:

     

    //The below calculation is a second order approximation of the derivative of f(x)

    //If the current row is the first row, then use forward difference to compute the endpoint

    IF FIRST()==0 THEN

        -0.5*(LOOKUP(SUM([f(x)]),2)-4*LOOKUP(SUM([f(x)]),1)+3*SUM([f(x)]))/(LOOKUP(SUM([x]),1)-SUM([x]))

    //If the current row is the last row, then use backward difference to compute the endpoint

    ELSEIF LAST()==0 THEN

         0.5*(LOOKUP(SUM([f(x)]),-2)-4*LOOKUP(SUM([f(x)]),-1)+3*SUM([f(x)]))/(SUM([x])-LOOKUP(SUM([x]),-1))

    //Otherwise use the second order centered difference

    ELSE

         0.5*(LOOKUP(SUM([f(x)]),1)-LOOKUP(SUM([f(x)]),-1)) /(SUM([x])-LOOKUP(SUM([x]),-1))

    END

     

    Inputs and Setup:


    [x] - A numerical field.

    [f(x)] - Another numerical field.

    - Each [x] value in the partition must correspond to a single [f(x)] value in the partition.

    - No two consecutive [x] values can be the same (otherwise we divide by zero).

     

    Partitioning and Addressing:

     

    Compute using a field that partitions your data into the points in the view.

    Alternately, if you wish to use all of the available points, you can turn off Aggregate Measures and compute using Table (Across).

     


    Comments:

     

    For interior points, the calculation uses a second-order accurate centered difference formula.  This doesn't work for the endpoints (because we don't have data beyond the endpoints), so instead we use a forward or backward difference to compute derivatives there.

     

    If the difference between [x] values is too small compared to the difference in [f(x)] values, we may see some numerical instability.

     

    Related Functions:

     

    Notes:

    20130325 Tyler Martin: Used second-order forward and backward differences to compute endpoints, resulting in a second order accurate approximation at all points!


    20130320 Jonathan Drummey: Edited checks for first and last rows in partition so they don't fail if [x] has same value as first row, also optimized LOOKUP(agg,0) with agg. Also updated the workbook (which is a Tableau version 8 workbook).

     

     

    Further Reading/Examples:

     

    Wikipedia page on Numerical Differentiation