fit nonlinear model to data - better way to code it?
Subject: fit nonlinear model to data - better way to code it?
From: Raymond Toy
Date: Sat, 19 May 2012 13:19:44 -0700
On 5/18/12 10:45 PM, Ether Jones wrote:
>
> The following works:
>
> [p1,p2,p3]: ans[1];
> trendline: ''f(x);
>
> ... but the cure is worse than the disease:
>
> With that approach, I have to change the code in 4 separate places to
> add parameters to the model:
>
> 1) f(x):=p1+p2/(x-p3)$
> 2) guess: [-.05,-1,2]$
>
> 3) ans: minpack_lsquares(
> f(x)-y,
> [p1,p2,p3],
> guess)$
>
> 4) [p1,p2,p3]: ans[1];
>
>
> ... whereas in the original code I had to change it in only 3 places,
> all of which were contiguous:
>
> 1) p:[p1,p2,p3]$
> 2) f(x):=p[1]+p[2]/(x-p[3])$
> 3) guess: [-.05,-1,2]$
>
>
> What I'm looking for is a "cleaner" way to "declare" p as a 3-element
> list of variables; using three dummy variables seems awkward,
> especially as the number of parameters increases.
I think this is mainly because the interface to minpack_lsquares wants a
list of variable names. It's certainly possible to change the interface
so that you give a name of one variable that is a list.
I kind of don't like this, based on my experience with colnew. It was a
bit tricky to implement and a bit tricky for the user. Perhaps that's
just because I didn't know exactly how to do it.
Ray