Manipulating Numerical Data

When you have numerical data, it is often convenient to find a simple formula that approximates it. For example, you can try to "fit" a line or curve through the points in your data.

Fitting curves to linear combinations of functions.

This generates a table of the numerical values of the exponential function. (RefLink[Table, paclet:ref/Table]) is discussed in "Making Tables of Values":

data=Table[Exp[x/5.],{x,7}]

This finds a least-squares fit to data of the form (Subscript[c, 1])+(Subscript[c, 2])x+(Subscript[c, 3])(x^2). The elements of data are assumed to correspond to values 1, 2, … of x:

Fit[data,{1,x,x^2},x]

This finds a fit of the form (Subscript[c, 1])+(Subscript[c, 2])x+(Subscript[c, 3])(x^3)+(Subscript[c, 4])(x^5):

Fit[data,{1,x,x^3,x^5},x]

This gives a table of x, y pairs:

data=Table[{x,Exp[Sin[x]]},{x,0.,1.,0.2}]

This finds a fit to the new data, of the form (Subscript[c, 1])+(Subscript[c, 2])sin(x)+(Subscript[c, 3])sin(2x):

Fit[%,{1,Sin[x],Sin[2x]},x]

Fitting data to general forms.

This finds the best parameters for a linear fit:

FindFit[data,a+b x+c x^2,{a,b,c},x]

This does a nonlinear fit:

FindFit[data,a+b^(c+d x),{a,b,c,d},x]

One common way of picking out "signals" in numerical data is to find the Fourier transform, or frequency spectrum, of the data.

Fourier transforms.

Here is a simple square pulse:

data={1,1,1,1,-1,-1,-1,-1}

This takes the Fourier transform of the pulse:

Fourier[data]

Note that the (RefLink[Fourier, paclet:ref/Fourier]) function in the Wolfram Language is defined with the sign convention typically used in the physical sciences—opposite to the one often used in electrical engineering. "Discrete Fourier Transforms" gives more details.