function module¶
Utility functions¶
Functions complex_to_seq()
and seq_to_complex()
are useful to convert between the matrix representation of
complex numbers and Python complex
.
The function mean()
evaluates the mean of a sequence.
The function implicit()
will evaluate the solution
to \(fn(x) = 0\)
Module contents¶
-
complex_to_seq
(z)¶ Transform a complex number into a 4-element sequence
Parameters: z – a number If
z = x + yj
, then an array of the form[[x,-y],[y,x]]
can be used to representz
in matrix computations.- Examples::
>>> import numpy >>> z = 1 + 2j >>> function.complex_to_seq(z) (1.0, -2.0, 2.0, 1.0)
>>> m = numpy.array( function.complex_to_seq(z) ) >>> m.shape = (2,2) >>> print( m ) [[ 1. -2.] [ 2. 1.]]
-
seq_to_complex
(seq)¶ Transform a 4-element sequence into a complex number
Parameters: seq – a 4-element sequence Raises: RuntimeError – if seq
is ill-conditionedExamples:
>>> import numpy >>> seq = (1,-2,2,1) >>> z = function.seq_to_complex( seq ) >>> z (1+2j) >>> a = numpy.array((1,-2,2,1)) >>> a.shape = 2,2 >>> a array([[ 1, -2], [ 2, 1]]) >>> z = function.seq_to_complex(a) >>> z (1+2j)
-
mean
(seq, *args, **kwargs)¶ Return the arithmetic mean of the elements in seq
Parameters: If the elements of
seq
are uncertain numbers, an uncertain number is returned.Example
>>> seq = [ ureal(1,1), ureal(2,1), ureal(3,1) ] >>> function.mean(seq) ureal(2.0,0.5773502691896257,inf)
-
implicit
(fn, x_min, x_max, epsilon=1e-13)¶ Return the solution to \(fn(x) = 0\)
Parameters: x_min
andx_max
delimit a range containing a single root (ie, the function must cross the x-axis just once inside the range).Note
- A
RuntimeError
is raised if the search algorithm fails to converge. - An
AssertionError
is raised if preconditions are not satisfied.
Example:
>>> near_unity = ureal(1,0.05) >>> fn = lambda x: x**2 - near_unity >>> function.implicit(fn,0,2) ureal(1.0,0.025...,inf)
New in version 1.3.4.
- A