On 10/17/10, Julien Martin <balteo at gmail.com> wrote:
> I am working with the least squares method, I would like to differentiate a
> sum as follows and I am having problems.
> What I want to achieve:
> -define a sum
> -differentiate it with respect to "a" and "b" respectively.
> -solve the resulting system.
>
> *exp:sum((y_i-a*x_i-b)^2,i,1,n);
> one:diff(exp,a,1)=0;
> two:diff(exp,b,1)=0;
> linsolve([one, two], [a,b]);
Subscripted variables are denoted by square brackets in Maxima.
x_i is just an arbitrary symbol, x[i] is a subscripted variable.
By default, Maxima doesn't assume sum is linear.
Try declare(sum, linear).
Also try expand(foo) where foo is your derivative expression.
Naming a user variable exp is probably going to eventually
lead to obscure problems since exp is the exponential function.
If you want to solve least squares problems in general,
take a look at the lsquares package.
?? lsquares finds some info about that.
HTH
Robert Dodier