# Optimization using NETLink failing [closed]

I define a function called f[x], which gives a numerical result interacting with an external free software called FEMM, using NETLink.

This function works properly and the following codes give the expected result:

Plot[f[x],{x,0,30},MaxRecursion->0,PlotPoints->30]


I try to do some optimization using this function. In order to do that I use

NMinimize[f[x],x,Method->"RandomSearch"]


But an error appears as below:

"error: attempt to perform arithmetic on global x' (a nil value)".

What could be the cause of this problem?

• I'm not sure without the full definition of f, but try defining ff[x_?NumericQ]:=f[x] and optimizing ff` instead. – xzczd Mar 21 '17 at 6:56