Spike functions¶
AUTHORS:
William Stein (2007-07): initial version
Karl-Dieter Crisman (2009-09): adding documentation and doctests
- class sage.functions.spike_function.SpikeFunction(v, eps=1e-07)[source]¶
Bases:
object
Base class for spike functions.
INPUT:
v
– list of pairs (x, height)eps
– parameter that determines approximation to a true spike
OUTPUT: a function with spikes at each point
x
inv
with the given heightEXAMPLES:
sage: spike_function([(-3,4), (-1,1), (2,3)], 0.001) A spike function with spikes at [-3.0, -1.0, 2.0]
>>> from sage.all import * >>> spike_function([(-Integer(3),Integer(4)), (-Integer(1),Integer(1)), (Integer(2),Integer(3))], RealNumber('0.001')) A spike function with spikes at [-3.0, -1.0, 2.0]
Putting the spikes too close together may delete some:
sage: spike_function([(1,1), (1.01,4)], 0.1) Some overlapping spikes have been deleted. You might want to use a smaller value for eps. A spike function with spikes at [1.0]
>>> from sage.all import * >>> spike_function([(Integer(1),Integer(1)), (RealNumber('1.01'),Integer(4))], RealNumber('0.1')) Some overlapping spikes have been deleted. You might want to use a smaller value for eps. A spike function with spikes at [1.0]
Note this should normally be used indirectly via
spike_function
, but one can use it directly:sage: from sage.functions.spike_function import SpikeFunction sage: S = SpikeFunction([(0,1), (1,2), (pi,-5)]); S # needs sage.symbolic A spike function with spikes at [0.0, 1.0, 3.141592653589793] sage: S.support # needs sage.symbolic [0.0, 1.0, 3.141592653589793]
>>> from sage.all import * >>> from sage.functions.spike_function import SpikeFunction >>> S = SpikeFunction([(Integer(0),Integer(1)), (Integer(1),Integer(2)), (pi,-Integer(5))]); S # needs sage.symbolic A spike function with spikes at [0.0, 1.0, 3.141592653589793] >>> S.support # needs sage.symbolic [0.0, 1.0, 3.141592653589793]
- plot(xmin=None, xmax=None, **kwds)[source]¶
Special fast plot method for spike functions.
EXAMPLES:
sage: S = spike_function([(-1,1), (1,40)]) sage: P = plot(S) # needs sage.plot sage: P[0] # needs sage.plot Line defined by 8 points
>>> from sage.all import * >>> S = spike_function([(-Integer(1),Integer(1)), (Integer(1),Integer(40))]) >>> P = plot(S) # needs sage.plot >>> P[Integer(0)] # needs sage.plot Line defined by 8 points
- plot_fft_abs(samples=4096, xmin=None, xmax=None, **kwds)[source]¶
Plot of (absolute values of) Fast Fourier Transform of the spike function with given number of samples.
EXAMPLES:
sage: S = spike_function([(-3,4), (-1,1), (2,3)]); S A spike function with spikes at [-3.0, -1.0, 2.0] sage: P = S.plot_fft_abs(8) # needs sage.plot sage: p = P[0]; p.ydata # abs tol 1e-8 # needs sage.plot [5.0, 5.0, 3.367958691924177, 3.367958691924177, 4.123105625617661, 4.123105625617661, 4.759921664218055, 4.759921664218055]
>>> from sage.all import * >>> S = spike_function([(-Integer(3),Integer(4)), (-Integer(1),Integer(1)), (Integer(2),Integer(3))]); S A spike function with spikes at [-3.0, -1.0, 2.0] >>> P = S.plot_fft_abs(Integer(8)) # needs sage.plot >>> p = P[Integer(0)]; p.ydata # abs tol 1e-8 # needs sage.plot [5.0, 5.0, 3.367958691924177, 3.367958691924177, 4.123105625617661, 4.123105625617661, 4.759921664218055, 4.759921664218055]
- plot_fft_arg(samples=4096, xmin=None, xmax=None, **kwds)[source]¶
Plot of (absolute values of) Fast Fourier Transform of the spike function with given number of samples.
EXAMPLES:
sage: S = spike_function([(-3,4), (-1,1), (2,3)]); S A spike function with spikes at [-3.0, -1.0, 2.0] sage: P = S.plot_fft_arg(8) # needs sage.plot sage: p = P[0]; p.ydata # abs tol 1e-8 # needs sage.plot [0.0, 0.0, -0.211524990023434, -0.211524990023434, 0.244978663126864, 0.244978663126864, -0.149106180027477, -0.149106180027477]
>>> from sage.all import * >>> S = spike_function([(-Integer(3),Integer(4)), (-Integer(1),Integer(1)), (Integer(2),Integer(3))]); S A spike function with spikes at [-3.0, -1.0, 2.0] >>> P = S.plot_fft_arg(Integer(8)) # needs sage.plot >>> p = P[Integer(0)]; p.ydata # abs tol 1e-8 # needs sage.plot [0.0, 0.0, -0.211524990023434, -0.211524990023434, 0.244978663126864, 0.244978663126864, -0.149106180027477, -0.149106180027477]
- vector(samples=65536, xmin=None, xmax=None)[source]¶
Create a sampling vector of the spike function in question.
EXAMPLES:
sage: S = spike_function([(-3,4), (-1,1), (2,3)],0.001); S A spike function with spikes at [-3.0, -1.0, 2.0] sage: S.vector(16) # needs sage.modules (4.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0)
>>> from sage.all import * >>> S = spike_function([(-Integer(3),Integer(4)), (-Integer(1),Integer(1)), (Integer(2),Integer(3))],RealNumber('0.001')); S A spike function with spikes at [-3.0, -1.0, 2.0] >>> S.vector(Integer(16)) # needs sage.modules (4.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0)
- sage.functions.spike_function.spike_function[source]¶
alias of
SpikeFunction