mghandi
mghandi

Reputation: 275

Derivative of series in mathematica

I have an equation like:

y= Sum[ i x[i] , {i,10}]

and I want to calculate the derivative :

D[y,x[i]] -> = i 

How can I do that in mathematica ?

I can do D[y, x[3]] and it gives me 3 but if I enter D[y, x[i]] it returns 0 but I expect i.

Is there a way to define the parametric derivative for series like the above in Mathematica ?

Upvotes: 1

Views: 1290

Answers (2)

soegaard
soegaard

Reputation: 31145

Here is a few things to consider.

  1. The notation x_3 does not mean x with index 3. It means three times x_. You should use Subscript[x,3] instead.

  2. Your y is: Sum[n * Subscript[x, n], {n, 1, 5}]

  3. You can now find the partial deriviative: D[Sum[n * Subscript[x, n], {n, 1, 5}], Subscript[x, 2]] gives 2.

  4. D[Sum[Subscript[x, n], {n, 1, 5}], Subscript[x, j]] gives 0. The reason is that Subscript[x, j] is considered a variable.

Upvotes: 1

b.gatessucks
b.gatessucks

Reputation: 1242

Probably not the best way to think about your problem, anyway :

Build the list of your variables :

vars = Table[Symbol["x" <> ToString[i]], {i, 1, 10}]
(* {x1, x2, x3, x4, x5, x6, x7, x8, x9, x10} *)

Build your function :

expr = Dot[Range[10], vars]
(* x1 + 10 x10 + 2 x2 + 3 x3 + 4 x4 + 5 x5 + 6 x6 + 7 x7 + 8 x8 + 9 x9 *)

Take the derivatives :

D[expr, #] & /@ vars 
(* {1, 2, 3, 4, 5, 6, 7, 8, 9, 10} *)

Upvotes: 1

Related Questions