# Spline Fitting (Cubic) (G Dataflow)

Uses cubic spline fitting to smooth an input data set.

## y

Dependent values. y must contain at least two points.

## x

Independent values. x must be the same size as y. The elements of x must be in ascending order.

## weight

Weights for the observations.

weight must be the same size as y. The elements in weight cannot be 0. If an element in weight is less than 0, this node uses the absolute value of the element. If you do not wire an input to weight, this node sets all elements in weight to 1.

## smoothness

Smoothness for each interval between two contiguous data points.

The larger the smoothness, the smoother the curve. The number of elements in smoothness n - 1, where n is the length of y. If smoothness is unwired, this node sets all elements of smoothness to 1.

## error in

Error conditions that occur before this node runs.

The node responds to this input according to standard error behavior.

Standard Error Behavior

Many nodes provide an error in input and an error out output so that the node can respond to and communicate errors that occur while code is running. The value of error in specifies whether an error occurred before the node runs. Most nodes respond to values of error in in a standard, predictable way.

error in does not contain an error error in contains an error
If no error occurred before the node runs, the node begins execution normally.

If no error occurs while the node runs, it returns no error. If an error does occur while the node runs, it returns that error information as error out.

If an error occurred before the node runs, the node does not execute. Instead, it returns the error in value as error out.

Default: No error

## balance parameter

Balance between the smoothness of the cubic spline fit and the accuracy with which it fits the observations.

balance parameter must fall within the range [0, 1]. If balance parameter is 0, the cubic spline fit is equivalent to a linear fit. If balance parameter is 1, the cubic spline fit interpolates between the data points. If balance parameter is out of the range [0, 1], this node calculates an appropriate value for balance parameter automatically according to the values of x.

How balance parameter Affects the Fit Result

The following graph shows the fit results when balance parameter takes different values, where p is balance parameter.

## best cubic spline fit

Y-values of the fitted model.

## error out

Error information.

The node produces this output according to standard error behavior.

Standard Error Behavior

Many nodes provide an error in input and an error out output so that the node can respond to and communicate errors that occur while code is running. The value of error in specifies whether an error occurred before the node runs. Most nodes respond to values of error in in a standard, predictable way.

error in does not contain an error error in contains an error
If no error occurred before the node runs, the node begins execution normally.

If no error occurs while the node runs, it returns no error. If an error does occur while the node runs, it returns that error information as error out.

If an error occurred before the node runs, the node does not execute. Instead, it returns the error in value as error out.

## Algorithm for Calculating the Cubic Spline Fit

This node fits the observations (x, y) by minimizing the following function:

$p\underset{i=1}{\overset{n-1}{\sum }}{w}_{i}{\left({y}_{i}-f\left({x}_{i}\right)\right)}^{2}+\left(1-p\right){\int }_{{x}_{0}}^{{x}_{n-1}}\lambda \left(x\right){\left(f"\left(x\right)\right)}^{2}dx$

where

• p is balance parameter
• wi is the ith element of weight
• yi is the ith element of y
• xi is the ith element of x
• f''(x) is the second-order derivative of the cubic spline function, f(x)
• $\lambda \left(x\right)$ is the piecewise constant function $\lambda \left(x\right)={\lambda }_{i},{x}_{i}\le x<{x}_{i+1}$, for i = 0, 1, ..., n - 2
• ${\lambda }_{i}$ is the ith element of smoothness

Where This Node Can Run:

Desktop OS: Windows

FPGA: Not supported

Web Server: Not supported in VIs that run in a web application