MathGroup Archive 2006

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Solve, D, and summations

  • To: mathgroup at smc.vnet.net
  • Subject: [mg64060] Re: [mg64054] Solve, D, and summations
  • From: Bob Hanlon <hanlonr at cox.net>
  • Date: Sun, 29 Jan 2006 23:10:15 -0500 (EST)
  • Reply-to: hanlonr at cox.net
  • Sender: owner-wri-mathgroup at wolfram.com

n=10;
{x,y}=Thread[Table[{t=Random[],5t+3},{n}]];

S=Sum[(y[[i]]-b0-b1*x[[i]])^2,{i,n}];

Solve[{D[S,b0]==0,D[S,b1]==0},{b0,b1}]

{{b0 -> 3.0000000000000004, b1 -> 4.999999999999999}}


Bob Hanlon

> 
> From: misha <iamisha1 at comcast.net>
To: mathgroup at smc.vnet.net
> Subject: [mg64060] [mg64054] Solve, D, and summations
> 
> I am (still) a new user of Mathematica and want to solve for the 
> (easiest case) least squares estimators.
> 
> As usual, I want to choose b_0 and b_1 to minimize S, where S is the sum 
> of squared differences.  i.e.,
> 
> In [1]:= S = sum{1,...,n}[y_i - b_0 - (b_1)*x_i]^2
> 
> Out [1]= sum{1,...,n}[y_i - b_0 - (b_1)*x_i]^2
> 
> After defining this function as above, which gave me the expression as I 
> expected, I then wrote,
> 
> In [2]:= Solve[{D[S, b_0]==0, D[S, b_1]==0}, {b_0, b_1}]
> 
> But got
> 
> Out [2]= {}
> 
> I also tried it this way:
> 
> In [3]:= S[b_0, b_1] = sum{1,...,n}[y_i - b_0 - (b_1)*x_i]^2
> 
> Out [3]= sum{1,...,n}[y_i - b_0 - (b_1)*x_i]^2
> 
> In [4]:= Solve[{D[S, b_0]==0, D[S, b_1]==0}, {b_0, b_1}]
> 
> But got
> 
> Out [4]= {{}}
> 
> Is it the 'n' in the summation that is giving me the problem?
> 
> I also tried this:
> 
> In [5]:= D[S, b_0]
> 
> Out [5]= sum{1,...,n}-2*[y_i - b_0 - (b_1)*x_i]
> 
> (as expected)
> 
> In [6]:= D[S, b_1]
> 
> Out [6]= sum{1,...,n}-2*x_i*[y_i - b_0 - (b_1)*x_i]
> 
> After which I copied the returned expressions, set them to zero, and 
> used Solve as below:
> 
> In [7]:= Solve[{sum{1,...,n}-2*[y_i - b_0 - (b_1)*x_i]
> ==0, sum{1,...,n}-2*x_i*[y_i - b_0 - (b_1)*x_i]==0}, {b_0, b_1}]
> 
> But, again, I got
> 
> Out [7]= {}
> 
> Thank you
> 
> 


  • Prev by Date: Re: Solve, D, and summations
  • Next by Date: Re: General--A Minor Annoyance
  • Previous by thread: Re: Solve, D, and summations
  • Next by thread: Re: Solve, D, and summations