bparkis
(B P)
1
I want to differentiate expressions such as yᵢ = ∑j aᵢⱼ xⱼ with respect to an indexed variable. For example ∂yᵢ/∂aᵢₖ = xₖ.
A more involved example:
fₖ = xₖ ∑i ∑j g(aᵢⱼ, xⱼ)
∂fₖ/∂xₙ = δₙₖ ∑i ∑j g(aᵢⱼ, xⱼ) + xₖ ∑i ∑j D₂ g(aᵢⱼ, xⱼ) δₙⱼ
= δₙₖ ∑i ∑j g(aᵢⱼ, xⱼ) + xₖ ∑i D₂ g(aᵢₙ, xₙ)
where D₂ g is the derivative of g with respect to its second parameter, and δ is the Kronecker delta.
How can I get Mathematica to give me these results? When I put in
f = D[(Sum[a[i, j] * x[j], {j, 1, n}]), x[k]]
FullSimplify[f, Assumptions -> {Integer[i], Integer[j], Integer[k]}]
It just gives me ∑j aᵢⱼ δjk, in other words it fails to simplify the sum. (I want it to give just aᵢₖ).
mroge02
(Michael Rogers)
2
Try this:
Assuming[
1 <= k <= n && k \[Element] Integers,
ff = D[(Sum[a[i, j]*x[j], {j, 1, n}]), x[k]] // Simplify
]
(* a[i, k] *)
bparkis
(B P)
3
Thank you! I’m very new to Mathematica. When I try the same method for my more involved example, it gives the wrong answer:
Assuming[
1 <= k <= N && k \[Element] Integers
&& 1 <= n <= N && n \[Element] Integers,
ff = D[x[k] * Sum[Sum[g[a[i, j],x[j]], {j, 1, N}], {i, 1, N}], x[n]] // Simplify
]
The result it gives is xₖ ∑i D₂ g(aᵢₙ, xₙ) which is only half the answer, omitting the δₙₖ ∑i ∑j g(aᵢⱼ, xⱼ) term. What am I doing wrong?
Is it making an incorrect assumption that n != k? How do I tell it not to assume that?
I suppose that it is because x[k] does not contain x[n], and then it is treated as a constant. This seems to work:
Assuming[
1 <= k <= N && 1 <= n <= N && (k | n | N) \[Element] Integers,
ff = D[If[k == n, x[n], x[k]]*
Sum[Sum[g[a[i, j], x[j]], {j, 1, N}],
{i, 1, N}], x[n]] // Simplify]