Movslope

Description

movslope(vx, vy[, n]) function returns a vector to calculate the moving slope at each point with a window width of n and (n-1)/2 points on either side of the point.

The slope at point i with a width of k is:

b=\frac{ \sum_{n=i_1}^{i_2} (x_n-\bar{x})(y_n-\bar{y}) }{ \sum_{n=i_1}^{i_2} (x_n-\bar{x})^2 }

Where i_1=i-(k-1)/2\,\!, i_2=i+(k-1)/2\,\!, \bar{x}=\sum_{n=i_1}^{i_2} x_n and \bar{y}=\sum_{n=i_1}^{i_2} y_n

Syntax

vector movslope(vx, vy[, n])

Parameters

vx

Input vector for independent variable

vy

Input vector for dependent variable

n

Input integer for window width
n should be an integer greater than 1. If n is an even number, it will be set to n+1 internally. When n is omitted, the function returns a vector of one value which is the linear fit slope of the input.

Return

Return the moving slopes at each point with a window width of n.
The first and last (n-1)/2 points of the output vector are missing values.

Note: If there are missing values in vx or vy, the slopes related to these points in the n window will be missing values. If a slope is infinite, it will be shown as a missing value.

Example

//Col(C) will be filled with slopes at each points.
//First and last two cells are missing values.
col(C)=movslope(col(A),col(B),5);
//Col(C) only has a numeric cell, which is the slope for all the points.
col(C)=movslope(col(A),col(B));

See Also

Diff