# Using Newton's Method to solve system of equations

I am getting an error that just gets stuck formatting notepad, i don't think there's anything in my code that is wrong, but I'm never sure.

f[x_, y_] = xy^2 + x^3 y;
fx[x_, y_] = 2 xy^2 + y^3;
fy[x_, y_] = 2 x^2 y + 3 xy^2;

g[x_, y_] = x^2 y - xy^4;
gx[x_, y_] = 2 xy - y^4;
gy[x_, y_] = x^2 - 4 xy^3;

u = 1.6;
v = 0.7;
For[i = 0, i < 7, i++,
d = fx[u, v] gy[u, v] - fy[u, v] gx[u, v];
h = (g[u, v] fy[u, v] gy[u, v])/d;
k = (f[u, v] gx[u, v] - g[u, v] fx[u, v])/d;
u = u + h;
v = v + k;
Print[u, " ", v, " ", f[u, v], " ", g[u, v]]];

• Check you don't have xy (a new variable) when you mean x y (x * y). The syntax highlighting (colour of the variable names) should give you a clue. – mikado Sep 18 '16 at 22:36
• Instead of For and Print, use Table[], or even in this case NestList. – Michael E2 Sep 18 '16 at 23:31

The following errors:

Wrong: f[x_, y_] = xy^2 + x^3 y; Correctly: f[x_, y_] := x*y^2 + (x^3)*y;

I recommend to read: What is the difference between Set and SetDelayed?

Working code:

 Clear[f, fx, fy, g, gx, gy,d,h,k,u,v];
f[x_, y_] := x*y^2 + (x^3) y;

fx[x_, y_] := 2 x*y^2 + y^3;
fy[x_, y_] := 2 (x^2) y + 3 x*y^2;

g[x_, y_] := (x^2) y - x*y^4;
gx[x_, y_] := 2 x*y - y^4;
gy[x_, y_] := x^2 - 4 x*y^3;

u = 1.6;
v = 0.7;

For[i = 0, i < 7, i++,
d = fx[u, v] gy[u, v] - fy[u, v] gx[u, v];
h = (g[u, v] fy[u, v] gy[u, v])/d;
k = (f[u, v] gx[u, v] - g[u, v] fx[u, v])/d;
u = u + h;
v = v + k;
Print[u, " ", v, " ", f[u, v], " ", g[u, v]]
];