| Author |
Comment/Response |
vladimir
|
10/30/06 8:50pm
Hi. I am new to Mathematica. I am trying to solve the curve fitting equations with a trigonometric polynomial as the fitting model. The regression is done through least squares method. Here are the steps to find :
Data samples: x[i], i=0..N-1
Model: xm[i]=a+c*Cos[w*i]+s*Sin[w*i]
Sum of squares: sum=Sum[(x[i]-xm[i])^2,{i,0,N-1}]
The following equations needs to be solved symbolically:
D[sum,a]==0
D[sum,c]==0
D[sum,s]==0
Those of you who is well familiar with math and especially DSP, will recognize this problem as finding the descrete Fourier series coefficients. The difference from the DFT, is that the frequency parameter w is not equal to 2*Pi*k/N. Otherwise, the solutions for a,c, and s are well known.
OK, enough about background. I simplified my Mathematica worksheet to just one command
Solve[{D[Sum[(x[i]-a-c*Cos[w*i]-s*Sin[w*i])^2, {i,0,N-1}],a]==0,
D[Sum[(x[i]-a-c*Cos[w*i]-s*Sin[w*i])^2, {i,0,N-1}],c]==0,
D[Sum[(x[i]-a-c*Cos[w*i]-s*Sin[w*i])^2, {i,0,N-1}],s]==0},{a,c,s}]
When I push SHIFT-ENTER, there is no result, just {}. I played with the formula, and I understood that Mathematica does not like x[i] in Solve[], or, at least, it expects x[i] to be defined. I can not define x[i] since my goal is to get a generic symbolic result. x[i] is just a i-th sample of the input data. I also tried x[[i]] and x_i. Nothing helps. I quickly browsed through 1300 pages of "The Mathematica Book, 5" and could not find the answer. Please, help me to modify the above command to make Mathematica to give me the symbolic answer. Thanks in advance.
URL: , |
|