[Tutor] constructing semi-arbitrary functions

Oscar Benjamin oscar.j.benjamin at gmail.com
Tue Feb 18 01:03:22 CET 2014


On 17 February 2014 22:15, "André Walker-Loud <walksloud at gmail.com>"
<walksloud at gmail.com> wrote:
>> This particular case is easily solved:
>>
>> def f_lambda(x,pars):
>>     return lambda x: poly(x,*pars)
>>
>> You let the closure take care of pars and return a function that takes
>> exactly one argument x.
>
> Hi Oscar,
>
> This is the opposite of what I am trying to do.  In the example, x represents the data and pars represent the parameters I want to determine, so it is the pars which I need passed into the "func_code.co_varnames" part of f.

BTW if you're trying to fit the coefficients of a polynomial then a
general purpose optimisation function is probably not what you want to
use. I would probably solve (in a least squares sense and after
suitable scaling) the Vandermonde matrix.

(I can explain that more if desired.)


Oscar


More information about the Tutor mailing list