fourier: Determining and Graphing Fourier Approximation

Description Usage Arguments Details Value Note Author(s) References Examples

View source: R/fourier.R

Description

The Fourier approximation is determined for any function on domain (0, 2π) and then graphed.

Usage

1
fourier(f, order = 3, ...)

Arguments

f

The function to be approximated by Fourier analysis.

order

Integer; the order of the Fourier transformation.

...

Optional arguments to be passed to the plot function (see par).

Details

The numerical output consists of a_0/2, a_1, ..., a_n, b_1, ..., b_2. The equation is (constant) + a_1 cos(x) + ... + a_n cos(n x) + b_1 sin(x) + ... + b_n sin(n x).

Value

constant

The constant term.

cosine.coefficients

The coefficients for the cosine terms.

sine.coefficients

The coefficients for the sine terms.

Note

The formulas computed within fourier are based on the textbook by Larson (2013).

Author(s)

Steven T. Garren, James Madison University, Harrisonburg, Virginia, USA

References

Larson, R. (2013) Elementary Linear Algebra, 7th edition.

Examples

1
2
3
4
5
6
par( mfrow=c(2,2) )
fourier( function(x){ exp(-x)*(x-pi) }, 4 )
fourier( function(x){ exp(-x) }, 7 )
fourier( function(x){ (x-pi) }, 5 )
fourier( function(x){ (x-pi)^2 } )
par( mfrow=c(1,1) )

Example output

$constant
[1] -0.342076

$cosine.coefficients
[1] -0.5009337 -0.2384993 -0.1256040 -0.0754238

$sine.coefficients
[1] -0.3420760 -0.3499125 -0.2814973 -0.2269386

$approximation
[1] "g(x) = -0.342 - 0.501 cos x - 0.342 sin x - 0.238 cos 2x - 0.35 sin 2x - 0.126 cos 3x - 0.281 sin 3x - 0.0754 cos 4x - 0.227 sin 4x"

$constant
[1] 0.1588577

$cosine.coefficients
[1] 0.158857730 0.063543092 0.031771546 0.018689145 0.012219825 0.008586904
[7] 0.006354309

$sine.coefficients
[1] 0.15885773 0.12708618 0.09531464 0.07475658 0.06109913 0.05152143 0.04448016

$approximation
[1] "g(x) = 0.159 + 0.159 cos x + 0.159 sin x + 0.0635 cos 2x + 0.127 sin 2x + 0.0318 cos 3x + 0.0953 sin 3x + 0.0187 cos 4x + 0.0748 sin 4x + 0.0122 cos 5x + 0.0611 sin 5x + 0.00859 cos 6x + 0.0515 sin 6x + 0.00635 cos 7x + 0.0445 sin 7x"

$constant
[1] 0

$cosine.coefficients
[1] 0 0 0 0 0

$sine.coefficients
[1] -2.0000000 -1.0000000 -0.6666667 -0.5000000 -0.4000000

$approximation
[1] "g(x) = - 2 sin x - 1 sin 2x - 0.667 sin 3x - 0.5 sin 4x - 0.4 sin 5x"

$constant
[1] 3.289868

$cosine.coefficients
[1] 4.0000000 1.0000000 0.4444444

$sine.coefficients
[1] 0 0 0

$approximation
[1] "g(x) = 3.29 + 4 cos x + 1 cos 2x + 0.444 cos 3x"

jmuOutlier documentation built on Aug. 6, 2019, 1:03 a.m.