@@ -17,6 +17,8 @@ will help the compiler infer the return type.
1717 differentiate(p::AbstractArray{<:AbstractPolynomialLike, N}, vs, deg::Union{Int, Val}=1) where N
1818
1919Differentiate 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]`.
2022
2123### Examples
2224
@@ -25,6 +27,7 @@ p = 3x^2*y + x + 2y + 1
2527differentiate(p, x) # should return 6xy + 1
2628differentiate(p, x, Val{1}()) # equivalent to the above
2729differentiate(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]
2831```
2932"""
3033function differentiate end
@@ -40,11 +43,11 @@ differentiate(p::RationalPoly, v::AbstractVariable) = (differentiate(p.num, v) *
4043const ARPL = Union{APL, RationalPoly}
4144
4245function 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 , :))
4447end
4548
4649function differentiate (ps:: AbstractArray{PT} , xs:: Tuple ) where {PT <: ARPL }
47- differentiate .( reshape ( ps, ( 1 , size (ps) ... )), xs )
50+ differentiate ( ps, collect (xs) )
4851end
4952
5053
0 commit comments