You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Construct a polynomial from its coefficients, lowest order first.
10
+
9
11
```julia
10
12
julia>Poly([1,0,3,4])
11
13
Poly(1+3x^2+4x^3)
12
14
```
13
15
14
16
An optional variable parameter can be added.
17
+
15
18
```julia
16
19
julia>Poly([1,2,3], :s)
17
20
Poly(1+2s +3s^2)
18
21
```
19
22
20
23
#### poly(r::AbstractVector)
21
-
Construct a polynomial from its roots. This is in contrast to the `Poly` constructor, which constructs a polynomial from its coefficients.
24
+
25
+
Construct a polynomial from its roots. This is in contrast to the
26
+
`Poly` constructor, which constructs a polynomial from its
27
+
coefficients.
28
+
22
29
```julia
23
30
// Represents (x-1)*(x-2)*(x-3)
24
31
julia>poly([1,2,3])
25
32
Poly(-6+11x -6x^2+ x^3)
26
33
```
27
34
28
-
#### +, -, *, /, ==
35
+
#### +, -, *, /, div, ==
29
36
30
37
The usual arithmetic operators are overloaded to work on polynomials, and combinations of polynomials and scalars.
31
38
```julia
@@ -44,22 +51,27 @@ Poly(3 + 2x)
44
51
julia> p - q
45
52
Poly(2x + x^2)
46
53
47
-
julia> p*q
54
+
julia> p*q
48
55
Poly(1+2x - x^2-2x^3)
49
56
50
-
julia> q/2
57
+
julia> q/2
51
58
Poly(0.5-0.5x^2)
59
+
60
+
julia> q ÷ p # `div`, also `rem` and `divrem`
61
+
Poly(0.25-0.5x)
52
62
```
53
63
54
64
Note that operations involving polynomials with different variables will error.
65
+
55
66
```julia
56
67
julia> p =Poly([1, 2, 3], :x)
57
68
julia> q =Poly([1, 2, 3], :s)
58
69
julia> p + q
59
70
ERROR: Polynomials must have same variable.
60
71
```
61
72
62
-
To get the degree of the polynomial use `degree` method
73
+
To get the degree of the polynomial use the `degree` method
74
+
63
75
```
64
76
julia> degree(p)
65
77
1
@@ -72,15 +84,29 @@ julia> degree(p-p)
72
84
```
73
85
74
86
#### polyval(p::Poly, x::Number)
87
+
75
88
Evaluate the polynomial `p` at `x`.
76
89
77
90
```julia
78
-
julia>polyval(Poly([1, 0, -1]), 0.1)
91
+
julia> p =Poly([1, 0, -1])
92
+
julia>polyval(p, 0.1)
79
93
0.99
80
94
```
81
95
96
+
A call method is also available:
97
+
98
+
```julia
99
+
julia>p(0.1)
100
+
0.99
101
+
```
102
+
103
+
82
104
#### polyint(p::Poly, k::Number=0)
83
-
Integrate the polynomial `p` term by term, optionally adding constant term `k`. The order of the resulting polynomial is one higher than the order of `p`.
105
+
106
+
Integrate the polynomial `p` term by term, optionally adding constant
107
+
term `k`. The order of the resulting polynomial is one higher than the
108
+
order of `p`.
109
+
84
110
```julia
85
111
julia>polyint(Poly([1, 0, -1]))
86
112
Poly(x -0.3333333333333333x^3)
@@ -90,14 +116,20 @@ Poly(2.0 + x - 0.3333333333333333x^3)
90
116
```
91
117
92
118
#### polyder(p::Poly)
93
-
Differentiate the polynomial `p` term by term. The order of the resulting polynomial is one lower than the order of `p`.
119
+
120
+
Differentiate the polynomial `p` term by term. The order of the
121
+
resulting polynomial is one lower than the order of `p`.
122
+
94
123
```julia
95
124
julia>polyder(Poly([1, 3, -1]))
96
125
Poly(3-2x)
97
126
```
98
127
99
128
#### roots(p::Poly)
100
-
Return the roots (zeros) of `p`, with multiplicity. The number of roots returned is equal to the order of `p`. The returned roots may be real or complex.
129
+
130
+
Return the roots (zeros) of `p`, with multiplicity. The number of
131
+
roots returned is equal to the order of `p`. By design, this is not type-stable,
0 commit comments