@@ -17,6 +17,8 @@ will help the compiler infer the return type.
17
17
differentiate(p::AbstractArray{<:AbstractPolynomialLike, N}, vs, deg::Union{Int, Val}=1) where N
18
18
19
19
Differentiate the polynomials in `p` by the variables of the vector or tuple of variable `vs` and return an array of dimension `N+deg`.
20
+ If `p` is an `AbstractVector` this returns the Jacobian of `p` where the i-th row containts the partial
21
+ derivaties of `p[i]`.
20
22
21
23
### Examples
22
24
@@ -25,6 +27,7 @@ p = 3x^2*y + x + 2y + 1
25
27
differentiate(p, x) # should return 6xy + 1
26
28
differentiate(p, x, Val{1}()) # equivalent to the above
27
29
differentiate(p, (x, y)) # should return [6xy+1, 3x^2+1]
30
+ differentiate( [x^2+y, z^2+4x], [x, y, z]) # should return [2x 1 0; 4 0 2z]
28
31
```
29
32
"""
30
33
function differentiate end
@@ -40,11 +43,11 @@ differentiate(p::RationalPoly, v::AbstractVariable) = (differentiate(p.num, v) *
40
43
const ARPL = Union{APL, RationalPoly}
41
44
42
45
function differentiate (ps:: AbstractArray{PT} , xs:: AbstractArray ) where {PT <: ARPL }
43
- differentiate .(reshape (ps, (1 , size (ps)... )), reshape (xs, :))
46
+ differentiate .(reshape (ps, (size (ps)... , 1 )), reshape (xs, 1 , :))
44
47
end
45
48
46
49
function differentiate (ps:: AbstractArray{PT} , xs:: Tuple ) where {PT <: ARPL }
47
- differentiate .( reshape ( ps, ( 1 , size (ps) ... )), xs )
50
+ differentiate ( ps, collect (xs) )
48
51
end
49
52
50
53
0 commit comments