I’m new in Julia. I have to solve a non-linear equation, and I have found the NLsolve package.

function coolebrok(fric_fact)
1 ./sqrt(fric_fact[:]) + 2*log10(epsilon./. (3.7.*DD) + 2.51./(sqrt(fric_fact[:]).*max(Re, 1e-10)))
end

sol = nlsolve(coolebrok, ff[:]./10)

this is what i have writtend in my code. Consider that fric_fact has to be a vector of 703x1 elements. This code is not working. Where is the mistake? Consider that this equation is solvable with fsolve in Matlab.

Hello and welcome to the community consider formatting your code as code using triple back ticks ``` and include a running example that produces the error you are seeing. This makes it easier for people to help you.

From just looking at the code, you’re trying to compute sqrt(array) which does not work in Julia. To compute the element-wise sqare root, use broadcasting: sqrt.(array).

You might also want to let fric_fact be a Vector rather than a 703 x 1 Matrix so that you don’t have to write [:] everywhere.

Thanks baggepinnen.
I tried to modify the code how you said, but it still doesn’t work. I think it’s not a problem of the math, but it’s a problem of the solver.

function coolebrok(fric_fact)
1 ./sqrt.(fric_fact) + 2*log10(epsilon./(3.7.*DD) + 2.51./(sqrt.(fric_fact).*max(Re, 1e-10)))
end
initial_guess = ff[:]./10
sol = nlsolve(coolebrok, initial_guess)

If i write the code like that, the error is:

no method matching isless(::Float64, ::Matrix{Float64})

I also tried the solver LeastSquareOptim, which allows me to use the levenberg-marquardt algorithm which is the algorithm used in fsolve in Matlab.