There are several problems with the code. e.g. xs // 2
. In Mathematica, //
is the postfix form of function application so xs // 2
evaluates to 2[xs]
. Take a look at this and this to get more familiar with Mathematica.
From the code it looks like you are trying to implement cube root finding using the Newton-Raphson method. Here is one way to do that.
Need to find the value of x for which the function f is zero.
f[x_, n_] := x^3 - n
Generic Newton-Raphson method
newtonRaphson[func_, guess_, precision_: 0.0001] :=
NestWhile[# - func[#]/func'[#] &, guess, Abs[func@#] > precision &]
Cube root of 3
newtonRaphson[Curry[f][3], 1.0] (* 1.44225 *)
Cube root of 10
newtonRaphson[Curry[f][10], 1.0] (* 2.15443 *)