1

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 ?

agentp
  • 6,849
  • 2
  • 19
  • 37
mghandi
  • 275
  • 1
  • 9
  • 1
    sugest you fix your notation .. y = Sum[i x[i], {i, 10}] ; D[y,x[3]]-> 3 ; D[y,x[i]] -> 0 – agentp Dec 28 '12 at 21:24
  • 1
    The correct reult is not "i", but rather "i if i is an integer in range 1:10 and zero otherwise." That should give a clue why this isn't a trivial thing to implement. – agentp Dec 28 '12 at 21:29

2 Answers2

1

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} *)
b.gatessucks
  • 1,242
  • 1
  • 15
  • 19
1

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.

soegaard
  • 30,661
  • 4
  • 57
  • 106