# Create Linear System from derivatives of variables and solve it [duplicate]

I have the following simply function:

f[x_, y_, z_] = (x - A)^2 + (y - B)^2 + (2*z - C)^2 + (5 + z + x -
D)^2 + (y - 2 + 2*x)^2 + (y - z + F)^2


I am looking for a simple way to have mathematica take the derivatives w.r.t to x,y,z, set them to zero, create a system of 3 equations with the three unknowns where the unknowns are moved to the left, and the constants to the right (I need to see the system outputted before it is solved). I know how to do this the standard way where I write things down one step at a time, but I was wondering if there is simpler way to do it, because I have to deal with a messier function.

• Maybe you can adapt what's in the begining here – corey979 Jun 9 '15 at 8:39
• do you mean like Solve[Table[\!$$\*SubscriptBox[\(\[PartialD]$$, $$q$$]$$f[x, y, z]$$\) == 0, {q, {x, y, z}}], {x, y, z}]? – Julian Jun 9 '15 at 8:42
• @julian Solve here doesn't work. I tried it ("his system cannot be solved with the methods available to Solve"). Also it is really hard to read the output of that table. – Cauchy Jun 9 '15 at 8:58
• Strange. Above code yields {{x -> 1/71 (-18 + 17 A - 13 B - 10 C + 12 D + 8 F), y -> 1/71 (43 - 13 A + 35 B + 16 C - 5 D - 27 F), z -> 1/71 (-49 - 5 A + 8 B + 28 C + 9 D + 6 F)}} for me (M10) – Julian Jun 9 '15 at 9:00
• The gradient is easily computed: df = D[f[x, y, z], {{x, y, z}, 1}]. Thread[df == 0] should yield a system of equations you can feed to Solve[]. – J. M.'s technical difficulties Jun 9 '15 at 10:05