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, highest order first.
9
-
8
+
Construct a polynomial from its coefficients, lowest order first.
10
9
```julia
11
10
julia>Poly([1,0,3,4])
12
-
Poly(1x^3+3x^1+4)
13
-
```
14
-
15
-
Leading zeros are stripped.
16
-
17
-
```julia
18
-
julia>Poly([0,1,2,3])
19
-
Poly(1x^2+2x^1+3)
11
+
Poly(1+3x^2+4x^3)
20
12
```
21
13
22
14
An optional variable parameter can be added.
23
-
24
15
```julia
25
-
julia>Poly([1,2,3], 's')
26
-
Poly(s^2+2 s +3)
16
+
julia>Poly([1,2,3], :s)
17
+
Poly(1+2s +3s^2)
27
18
```
28
19
29
20
#### poly(r::AbstractVector)
30
21
Construct a polynomial from its roots. This is in contrast to the `Poly` constructor, which constructs a polynomial from its coefficients.
31
-
32
22
```julia
33
-
// Represents (x-1)*(x-2)*(x-3)
23
+
// Represents (x-1)*(x-2)*(x-3)
34
24
julia>poly([1,2,3])
35
-
Poly(1x^3+-6x^2+11x^1+-6)
25
+
Poly(-6+11x -6x^2+x^3)
36
26
```
37
27
38
28
#### +, -, *, /, ==
39
29
40
30
The usual arithmetic operators are overloaded to work on polynomials, and combinations of polynomials and scalars.
41
-
42
31
```julia
43
-
julia>a=Poly([1,2])
44
-
Poly(1x^1+2)
32
+
julia>p=Poly([1,2])
33
+
Poly(1+2x)
45
34
46
-
julia>b=Poly([1, 0, -1])
47
-
Poly(1x^2+-1)
35
+
julia>q=Poly([1, 0, -1])
36
+
Poly(1- x^2)
48
37
49
-
julia>2*a
50
-
Poly(2x^1+4)
38
+
julia>2p
39
+
Poly(2+4x)
51
40
52
-
julia>2+ a
53
-
Poly(1x^1+4)
41
+
julia>2+p
42
+
Poly(3+2x)
54
43
55
-
julia>a-b
56
-
Poly(-1x^2+1x^1+3)
44
+
julia>p-q
45
+
Poly(2x+x^2)
57
46
58
-
julia>a*b
59
-
Poly(1x^3+2x^2+-1x^1+-2)
47
+
julia>p*q
48
+
Poly(1+2x- x^2-2x^3)
60
49
61
-
julia>b/2
62
-
Poly(0.5x^2+-0.5)
50
+
julia>q/2
51
+
Poly(0.5-0.5x^2)
63
52
```
64
53
65
54
Note that operations involving polynomials with different variables will error.
66
55
67
56
```julia
68
-
julia>a=Poly([1,2,3], 'x');
69
-
julia>b=Poly([1,2,3], 's');
70
-
julia>a+b
57
+
julia>p=Poly([1,2, 3], :x)
58
+
julia>q=Poly([1,2, 3], :s)
59
+
julia>p+q
71
60
ERROR: Polynomials must have same variable.
72
61
```
73
62
@@ -76,26 +65,24 @@ Evaluate the polynomial `p` at `x`.
76
65
77
66
```julia
78
67
julia>polyval(Poly([1, 0, -1]), 0.1)
79
-
-0.99
68
+
0.99
80
69
```
81
70
82
71
#### polyint(p::Poly, k::Number=0)
83
72
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`.
84
-
85
73
```julia
86
74
julia>polyint(Poly([1, 0, -1]))
87
-
Poly(0.3333333333333333x^3+-1.0x^1)
75
+
Poly(x -0.3333333333333333x^3)
88
76
89
77
julia>polyint(Poly([1, 0, -1]), 2)
90
-
Poly(0.3333333333333333x^3+-1.0x^1+2.0)
78
+
Poly(2.0+x -0.3333333333333333x^3)
91
79
```
92
80
93
81
#### polyder(p::Poly)
94
82
Differentiate the polynomial `p` term by term. The order of the resulting polynomial is one lower than the order of `p`.
0 commit comments