NLsolve seems to work fine with anonymous functions:
julia> using NLsolve
julia> f! = function (x, fvec)
fvec[1] = (x[1]+3)*(x[2]^3-7)+18
fvec[2] = sin(x[2]*exp(x[1])-1)
end
(anonymous function)
julia> g! = function (x, fjac)
fjac[1, 1] = x[2]^3-7
fjac[1, 2] = 3*x[2]^2*(x[1]+3)
u = exp(x[1])*cos(x[2]*exp(x[1])-1)
fjac[2, 1] = x[2]*u
fjac[2, 2] = u
end
(anonymous function)
julia> nlsolve(f!, g!, [0.1; 1.2])
Results of Nonlinear Solver Algorithm
* Algorithm: Trust-region with dogleg and autoscaling
* Starting Point: [0.1,1.2]
* Zero: [-3.7818e-16,1.0]
* Inf-norm of residuals: 0.000000
* Iterations: 4
* Convergence: true
* |x - x'| < 0.0e+00: false
* |f(x)| < 1.0e-08: true
* Function Calls (f): 5
* Jacobian Calls (df/dx): 5
That's just the example in the NLsolve README but with anonymous functions.
On Tue, Apr 28, 2015 at 10:04 AM, 'Antoine Messager' via julia-users <
[email protected]> wrote:
> Both ideas you have given are working. Wonderful! I just need to figure
> out which one is the fastest, the @gensym out of the creation of the
> function probably.
> Thank you very much!
> Antoine.
>
>
> Le lundi 27 avril 2015 15:49:56 UTC+1, Antoine Messager a écrit :
>>
>> Dear all,
>>
>> I need to create a lot of systems of equation, find some characteristics
>> of each system and store the system if of interest. Each system is created
>> under the same name. It works fine for the first 1000 systems but after the
>> program starts to be too slow. I have tried to use the garbage collector
>> each time I create a new system but it did not speed up the code. I don't
>> know what to do, I don't understand where it could come from.
>>
>> Cheers,
>> Antoine
>>
>