# Forecast

## Description

Minimum Origin Version Required: 2019 SR0

This function performs linear regression on a group of XY data to calculate or predict Y at the given X value. The Y value is predicted as $a + bx$:

where,

$b = \frac{\sum{(x-\bar{x})(y-\bar{y})}}{\sum{(x-\bar{x})^2}}$

$a = \bar{y} - b \bar{x}$

$\bar{x}$ and $\bar{y}$ are the means of x and y.

## Syntax

double Forecast( double x, vector vx, vector vy)


## Parameters

x

The x coordinate(s) for calculating y coordinate(s).

vx

The source x coordinates used for linear regression.

vy

The source y coordinates used for linear regression.

## Return

Return the calculated or predicted y coordinate at specified x coordinate.

## Example

newbook;
worksheet -a 2;
col(a)={0:0.5:10};
col(b)=10*col(a)-20*rnd();
col(c)={20:1:25};
col(d)=forecast(col(c),col(a),col(b));