the grid search if i remember correctly implies finding zeros of a multivariate function in one direction iteratively, here is a newton implementation in julia, that is one part of the grid search algorithm:

```
function mynewton(f,df,x0,tol=1e-08,itermax=100) #here i give optional
# arguments, so later i don't need to write it in the function
xiplus1 = zero(eltype(x0)) #basically 0.0, but more adaptable
#good to remember that 1 and 1.0 are of distinct type, the first one is
#an integer, the second one is a float
xi = x0
#main loop
tolf=1000
iter_count=0
while (tolf>=tol) && (iter_count<=itermax) #the loop stops
# if the tolerance or the maximum number of iterations is achieved
xiplus1 = xi - f(xi)/df(xi)
tolf = abs(f(xiplus1))
iter_count+=1 #it adds 1 to the variable
xi = xiplus1
end
return xiplus1
end
```