Taylor's way of expanding in powerseries

O Taylor aneptuse tis sunarthseis se dunamosaeires me thn me8odo twn Elaxistwn Tetragwnwn. Gia paradeigma gia na anaptu3ei thn Cos[x]  se dunamoseira gurw apo to 0 (ta3h epafhs 5) ekane ta e3hs:

1on. Xwrize to diasthma -0.5 mexri 0.5 se 5 isa merh kai sxhmatize ta e3hs zeugh {x, Cos[x]}

data = Table[{x, Cos[x]}, {x, -0.5, 0.5, (1/5)}] // N

dataplot = 
        ListPlot[data, 
          PlotStyle -> {PointSize[0.02], 
              RGBColor[1, 0, 0]}];

2on.  Katopin o Taylor orize to poluwnumo fitter[x] — tous suntelestes tou opoiou h8ele na prosdiorisei — kai sxhmatize to a8roisma twn tetragwnwn twn diaforwn (fitter[x] - ((Cos[x]))^2) .  To teleutaio sthn periptwsh auth einai h sunarthsh  6 metablhtwn sqerror[r,s,t,u,v,w} thn opoia h8ele na elaxistopoihsei.

fitter[x_] = 
      r + s x  + t (x^2) + u (x^3) + v (x^4) + w (x^5)

sqerror[r_, s_, t_, u_, v_, 
        w_] = (∑_(k = 1)^(Length[data]))(((fitter[data[[k, 1]]] - data[[k, 2]]))^2)

An anaptu3oume tis dunameis kai kopsoume (chop) tous  suntelestes pou einai sxedon mhden exoume sqerror[r, s, t, u, v, w]=

Expand[%] // Chop

3on.  Sthn sunexeia o Taylor epairne tis paragwgous ws pros r, s, t, u, v, w kai e8ete thn ka8e mia = 0, sxhmatizontas etsi ena susthma (sthn periptwsh mas) 6 e3iswsewn me 6 agnwstous.  Gia paradeigma h paragwgos ws pros r einai

Expand[D[sqerror[r, s, t, u, v, w], r]] == 0

kai to susthma lunetai me thn sunarthsh Solve, opou epishs kopsame tous suntelestes pou einai sxedon isoi me 0.

Solve[
{D[sqerror[r, s, t, u, v, w], r] == 0, 
          D[sqerror[r, s, t, u, v, w], s] == 0, 
          D[sqerror[r, s, t, u, v, w], t] == 0, 
          D[sqerror[r, s, t, u, v, w], u] == 0, 
          D[sqerror[r, s, t, u, v, w], v] == 0, 
          D[sqerror[r, s, t, u, v, w], w] == 0}
] // 
      Chop

H olh diadikasia einai enswmatwmenh sthn sunarthsh Fit pou mas dinei tous idious suntelestes.

Fit[data, {1,  x , (x^2), (x^3),  (x^4), (x^5)}, x] // Chop

Prose3te poso konta einai sto anaptugma ths Cos[x] se dunamoseires me thn arxh touu Ippodromou!

Series[Cos[x], {x, 0, 5}] // N

Fourier's crazy idea!!! The use of trig functions

H idia me8odos twn Elaxistwn Twtragwnwn xrhshmopoieitai kai gia thn proseggish mias sunarthshs me trigwnometrikes sunarthseis...

data = {{-3. , -0.1119}, {-2.5, -0.3986}, {-2. , -1.7359}, {-1.5, -2.6926}, {-1. , -1.6163}, {-0.5, -0.1308}, {0. , 0.0570}, {0.5, 0.2171}, {1. , 1.8582}, {1.5, 
          2.6742}, {2. , 1.8313}, {2.5, 0.7550}, {3. , 0.2831}}

dataplot = 
        ListPlot[data, 
          PlotStyle -> {PointSize[0.02], 
              RGBColor[1, 0, 0]}];

Clear[fitter, sqerror, s, t, r, x, k];
fitter[x_] = r Sin[x] + s Sin[2 x] + t Sin[3 x]

sqerror[r_, s_, 
          t_] = (∑_(k = 1)^(Length[data]))(((fitter[data[[k, 1]]] - data[[k, 2]]))^2);

Solve[{D[sqerror[r, s, t],  r] == 0, 
        D[sqerror[r, s, t],  s] == 0, 
        D[sqerror[r, s, t],  t] == 0}]

Clear[bestfit];
bestfit[x_] = 
      fitter[x] /. {r -> 1.97845, s -> 0.0475817, 
          t -> -0.663794}

\(\(fitplot = 
        Plot[bestfit[x], {x, \(-3\), 3}, 
          PlotStyle -> {{Thickness[0.01], RGBColor[0, 0, 1]}}, 
          DisplayFunction -> Identity];\)
\)
Show[dataplot, fitplot];

bestfit[x]

Fit[data, {Sin[x], Sin[2 x], Sin[3 x]}, x]