# TI-BASIC:Sinreg

Command Summary

Calculates the least-squares best fit sinusoidal curve through a set of points.

Command Syntax

SinReg [iterations, x-list, y-list, period, equation]

Press:

1. STAT to access the statistics menu
2. LEFT to access the CALC submenu
3. ALPHA C to select SinReg, or use arrows

TI-83/84/+/SE

1 byte

SinReg tries to fit a sine wave to a given list of points. To use it, you must first store the points to two lists: one of the x-coordinates and one of the y-coordinates, ordered so that the ith element of one list matches up with the ith element of the other list (i.e. the first element of the x-list and the first element of the y-list make up an ordered pair). L₁ and L₂ are the default lists used, and the List Editor (STAT > Edit...) is a useful window for entering the points.

SinReg requires that the lists contain at least 4 points. Also, if you do not provide two data points per cycle, the calculator may return a wrong answer. These conditions are an absolute minimum, and the command may fail to work even when they are met, and throw a ERR:SINGULAR MAT error. This is also likely to happen if the data are not actually periodic in nature.

In addition, to use SinReg in its simplest form, the x-coordinates must be sorted in increasing order, and the difference between consecutive x-coordinates must be the same throughout (i.e., x,,i+1,,-x,,i,, should be the same for all i). You can then call SinReg with no arguments, and it will attempt to fit a sine wave to the data in L₁ and L₂:

```:{1,2,3,4,5,6,7,8,9,10,11,12→L₁
:{21,24,34,46,58,67,72,70,61,50,40,27→L₂
:SinReg
```

On the home screen, or as the last line of a program, this will display the equation of the curve: you'll be shown the format, y=a*sin(b//x+c)+d, and the values of a, b, c and d. It will also be stored in the RegEQ variable, but you will not be able to use this variable in a program - accessing it just pastes the equation wherever your cursor was. Finally, the statistical variables a, b, c, and d will be set to the values computed as well. There are no correlation statistics available for SinReg even if Diagnostic Mode is turned on (see DiagnosticOn and DiagnosticOff).

A word of caution: the calculator assumes that Radian mode is enabled. If the calculator is set to Degree mode, the equation will still be in terms of radians: it will be correct, but values plugged in will give wrong answers. You will have to either switch to Radian mode, or multiply the values of b and c by 180/π.

You do not have to do the regression on L₁ and L₂, in which case you'll have to enter the names of the lists after the command. For example:

```:{1,2,3,4,5,6,7,8,9,10,11,12→MONTH
:{21,24,34,46,58,67,72,70,61,50,40,27→TEMP
:SinReg ∟MONTH,∟TEMP
```

Unlike the other regression commands, SinReg does not allow you to use a frequency list for data. You can get around this by adding repeating coordinates multiple times.

The optional argument iterations should come before the data lists, and if provided will change the amount of time and effort the calculator spends on the problem. The value should be an integer 1 to 16; larger numbers mean greater precision, but a longer calculation time. The default value is 3, and for good reason: with a high precision value, the calculation may take a minute to complete, or longer, depending on the complexity of the problem.

The optional argument period should be given after the data lists - this is the length of a complete cycle in the data, if known. You might know the exact value of the period, for example, when the calculation involves time - a complete cycle could be a day, a month, or a year. Providing this argument is strongly recommended whenever it is available: this removes conditions on the x-coordinates' order and increment, and makes the calculation much faster and more accurate. If you have previously done a SinReg fit and desire a refined estimate, the value 2π/b// can be given as the period.

Finally, you can enter an equation variable (such as Y₁) after the command, so that the curve's equation is stored to this variable automatically. This does not require you to supply the names of the lists, but if you do, the equation variable must come last. You can use polar, parametric, or sequential variables as well, but since the equation will be in terms of X anyway, this does not make much sense.

An example of SinReg with all the optional arguments:

```:{1,2,3,4,5,6,7,8,9,10,11,12→MONTH
:{21,24,34,46,58,67,72,70,61,50,40,27→TEMP
:SinReg 16,∟MONTH,∟TEMP,12,Y₁
```

The [wikipedia:Levenberg-Marquardt_algorithm Levenberg-Marquardt] nonlinear least-squares algorithm is used by SinReg.

# Error Conditions

• ERR:SINGULAR MAT is thrown if you don't provide the calculator at least 4 points, or two data points per cycle.