Parametrize NLsolve function


#1

Hello,
I want to solve a function using NLsolve, which has parameters. I do not want to pass them using global variables.

Simplified example:

using NLsolve
function f!(F, x)
    global a, b
    F[1] = a * sin(x[1]) + b
end
a = 1.0
b = 0.5
nlsolve(f!, [ 0.])

How can I solve this problem without using global variables?


#2
function f!(F,x,a,b)
   F[1] = a * sin(x[1]) + b
 end 
a = 1.0
b = 0.5 
nlsolve((F,x) ->f!(F,x,a,b), [ 0.])

Should do the trick.


#3

Thanks! This works nicely. :slight_smile: