Question: Differentiate a set of equations

I want to differentiate the following (example) sum with respect to each variable.

foo:=sum(x[i]^2,i=1..3);

By hand I solved it like that:

g1:=diff(foo,x[1])=0;
g2:=diff(foo,x[2])=0;
g3:=diff(foo,x[3])=0;
solve({g1,g2,g3}, [x[1], x[2], x[3]]);

This works for i=1..3 but later I want to have it approach infinity. I don't have that much time to do it by hand -- what's a cleaner solution?

Please Wait...