lsquares fitting and constrains for parameters (looking for positive values of parameters)
Subject: lsquares fitting and constrains for parameters (looking for positive values of parameters)
From: Raymond Toy
Date: Sun, 15 Jan 2012 18:21:36 -0800
On 1/15/12 5:43 PM, gwpublic at wp.pl wrote:
> Hello,
>
> I use least squares method to fit functions to data :
>
> load(lsquares)$
> DataM: matrix( [1,1], [4,4], [10,9] );
> lsquares_estimates (DataM, [x,y], y = a2*x**2 + a1*x + a0, [a2,a1,a0],
> iprint=[-1,0]);
>
> Maxima finds negative solutions:
>
> (%i) grind(%);
> (%o) [[a2 = -1/54,a1 = 59/54,a0 = -2/27]]$
>
> What should I do to constrain parameters ?
> To be more specific :
>
> * I must ensure all are positive : a2>=0 a1>=0 a0>=0
> * would be nice to specify upper limits as well : a2<maxa2 a1<maxa1 a0<maxa0
> * Maybe other constrains if solution can handle any predicate.
>
> But only "must" is to make them positive.
>
> I've tried : "assume()", but with no success.
>
If you do not need a symbolic solution, you might be interested in
fmin_cobyla, which will produce the minimum of a function subject to
equality or inequality constraints.
Use "? fmin_cobyla" for more information.
Ray