Skip to content

Commit e453943

Browse files
committed
Merge pull request #1 from daviddelaat/patch-1
Update README.md
2 parents f5faf58 + 5da040f commit e453943

File tree

1 file changed

+30
-43
lines changed

1 file changed

+30
-43
lines changed

README.md

Lines changed: 30 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,73 +1,62 @@
11
# Polynomial
22

3-
Basic arithmetic, integration, differentiation, evaluation, and root finding over dense polynomials.
3+
Basic arithmetic, integration, differentiation, evaluation, and root finding over dense univariate polynomials.
44

55
[![Build Status](https://travis-ci.org/vtjnash/Polynomial.jl.png?branch=master)](https://travis-ci.org/vtjnash/Polynomial.jl)
66

77
#### Poly{T<:Number}(a::Vector)
8-
Construct a polynomial from its coefficients, highest order first.
9-
8+
Construct a polynomial from its coefficients, lowest order first.
109
```julia
1110
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)
2012
```
2113

2214
An optional variable parameter can be added.
23-
2415
```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)
2718
```
2819

2920
#### poly(r::AbstractVector)
3021
Construct a polynomial from its roots. This is in contrast to the `Poly` constructor, which constructs a polynomial from its coefficients.
31-
3222
```julia
33-
// Represents (x - 1)*(x-2)*(x-3)
23+
// Represents (x-1)*(x-2)*(x-3)
3424
julia> poly([1,2,3])
35-
Poly(1x^3 + -6x^2 + 11x^1 + -6)
25+
Poly(-6 + 11x - 6x^2 + x^3)
3626
```
3727

3828
#### +, -, *, /, ==
3929

4030
The usual arithmetic operators are overloaded to work on polynomials, and combinations of polynomials and scalars.
41-
4231
```julia
43-
julia> a = Poly([1,2])
44-
Poly(1x^1 + 2)
32+
julia> p = Poly([1,2])
33+
Poly(1 + 2x)
4534

46-
julia> b = Poly([1, 0, -1])
47-
Poly(1x^2 + -1)
35+
julia> q = Poly([1, 0, -1])
36+
Poly(1 - x^2)
4837

49-
julia> 2*a
50-
Poly(2x^1 + 4)
38+
julia> 2p
39+
Poly(2 + 4x)
5140

52-
julia> 2 + a
53-
Poly(1x^1 + 4)
41+
julia> 2+p
42+
Poly(3 + 2x)
5443

55-
julia> a - b
56-
Poly(-1x^2 + 1x^1 + 3)
44+
julia> p - q
45+
Poly(2x + x^2)
5746

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)
6049

61-
julia> b/2
62-
Poly(0.5x^2 + -0.5)
50+
julia> q/2
51+
Poly(0.5 - 0.5x^2)
6352
```
6453

6554
Note that operations involving polynomials with different variables will error.
6655

6756
```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
7160
ERROR: Polynomials must have same variable.
7261
```
7362

@@ -76,26 +65,24 @@ Evaluate the polynomial `p` at `x`.
7665

7766
```julia
7867
julia> polyval(Poly([1, 0, -1]), 0.1)
79-
-0.99
68+
0.99
8069
```
8170

8271
#### polyint(p::Poly, k::Number=0)
8372
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-
8573
```julia
8674
julia> polyint(Poly([1, 0, -1]))
87-
Poly(0.3333333333333333x^3 + -1.0x^1)
75+
Poly(x - 0.3333333333333333x^3)
8876

8977
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)
9179
```
9280

9381
#### polyder(p::Poly)
9482
Differentiate the polynomial `p` term by term. The order of the resulting polynomial is one lower than the order of `p`.
95-
9683
```julia
9784
julia> polyder(Poly([1, 3, -1]))
98-
Poly(2x^1 + 3)
85+
Poly(3 - 2x)
9986
```
10087

10188
#### roots(p::Poly)
@@ -109,10 +96,10 @@ julia> roots(Poly([1, 0, -1]))
10996

11097
julia> roots(Poly([1, 0, 1]))
11198
2-element Array{Complex{Float64},1}:
112-
0.0-1.0im
11399
0.0+1.0im
100+
0.0-1.0im
114101

115-
julia> roots(Poly([1, 0, 0]))
102+
julia> roots(Poly([0, 0, 1]))
116103
2-element Array{Float64,1}:
117104
0.0
118105
0.0

0 commit comments

Comments
 (0)