~ubuntu-branches/ubuntu/feisty/python-numpy/feisty

« back to all changes in this revision

Viewing changes to numpy/lib/tests/test_polynomial.py

  • Committer: Bazaar Package Importer
  • Author(s): Matthias Klose
  • Date: 2006-07-12 10:00:24 UTC
  • Revision ID: james.westby@ubuntu.com-20060712100024-5lw9q2yczlisqcrt
Tags: upstream-0.9.8
ImportĀ upstreamĀ versionĀ 0.9.8

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
"""
 
2
>>> import numpy.core as nx
 
3
>>> from numpy.lib.polynomial import poly1d, polydiv
 
4
 
 
5
>>> p = poly1d([1.,2,3])
 
6
>>> p
 
7
poly1d([ 1.,  2.,  3.])
 
8
>>> print p
 
9
   2
 
10
1 x + 2 x + 3
 
11
>>> q = poly1d([3.,2,1])
 
12
>>> q
 
13
poly1d([ 3.,  2.,  1.])
 
14
>>> print q
 
15
   2
 
16
3 x + 2 x + 1
 
17
 
 
18
>>> p(0)
 
19
3.0
 
20
>>> p(5)
 
21
38.0
 
22
>>> q(0)
 
23
1.0
 
24
>>> q(5)
 
25
86.0
 
26
 
 
27
>>> p * q
 
28
poly1d([  3.,   8.,  14.,   8.,   3.])
 
29
>>> p / q
 
30
(poly1d([ 0.33333333]), poly1d([ 1.33333333,  2.66666667]))
 
31
>>> p + q
 
32
poly1d([ 4.,  4.,  4.])
 
33
>>> p - q
 
34
poly1d([-2.,  0.,  2.])
 
35
>>> p ** 4
 
36
poly1d([   1.,    8.,   36.,  104.,  214.,  312.,  324.,  216.,   81.])
 
37
 
 
38
>>> p(q)
 
39
poly1d([  9.,  12.,  16.,   8.,   6.])
 
40
>>> q(p)
 
41
poly1d([  3.,  12.,  32.,  40.,  34.])
 
42
 
 
43
>>> nx.asarray(p)
 
44
array([ 1.,  2.,  3.])
 
45
>>> len(p)
 
46
2
 
47
 
 
48
>>> p[0], p[1], p[2], p[3]
 
49
(3.0, 2.0, 1.0, 0)
 
50
 
 
51
>>> p.integ()
 
52
poly1d([ 0.33333333,  1.        ,  3.        ,  0.        ])
 
53
>>> p.integ(1)
 
54
poly1d([ 0.33333333,  1.        ,  3.        ,  0.        ])
 
55
>>> p.integ(5)
 
56
poly1d([ 0.00039683,  0.00277778,  0.025     ,  0.        ,  0.        ,
 
57
        0.        ,  0.        ,  0.        ])
 
58
>>> p.deriv()
 
59
poly1d([ 2.,  2.])
 
60
>>> p.deriv(2)
 
61
poly1d([ 2.])
 
62
 
 
63
>>> q = poly1d([1.,2,3], variable='y')
 
64
>>> print q
 
65
   2
 
66
1 y + 2 y + 3
 
67
>>> q = poly1d([1.,2,3], variable='lambda')
 
68
>>> print q
 
69
        2
 
70
1 lambda + 2 lambda + 3
 
71
 
 
72
>>> polydiv(poly1d([1,0,-1]), poly1d([1,1]))
 
73
(poly1d([ 1., -1.]), poly1d([ 0.]))
 
74
"""
 
75
 
 
76
from numpy.testing import *
 
77
 
 
78
class test_docs(NumpyTestCase):
 
79
    def check_doctests(self): return self.rundocs()
 
80
 
 
81
if __name__ == "__main__":
 
82
    ScipyTest().run()