Polynomial derivative: Difference between revisions

J
(J)
Line 355:
p = 1 + 1*x - 1*x^3 - 1*x^4
p' = 1 - 3*x^2 - 4*x^</pre>
 
=={{header|J}}==
 
Implementation:
<syntaxhighlight lang=J>pderiv=: -@(1 >. _1+#) {. (* i.@#)</syntaxhighlight>
 
Task examples:
<syntaxhighlight lang=J> pderiv 5
0
pderiv 4 _3
_3
pderiv _1 6 5
6 10
pderiv _4 3 _2 1
3 _4 3
pderiv 1 1 _1 _1
1 _2 _3</syntaxhighlight>
 
Note also that J's <code>p.</code> can be used to apply one of these polynomials to an argument. For example:
 
<syntaxhighlight lang=J> 5 p. 2 3 5 7
5 5 5 5
(pderiv 5) p. 2 3 5 7
0 0 0 0
4 _3 p. 2 3 5 7
_2 _5 _11 _17
(pderiv 4 _3) p. 2 3 5 7
_3 _3 _3 _3</syntaxhighlight>
 
 
=={{header|jq}}==
6,962

edits