Fitting a periodic function to data over [0,π]

3 replies · 2K views · last reply
ftft
Messages
21
Reaction score
0
My experience with data fitting is poor so I am in real need for help.
The potential in the following is periodic over [0,Pi]
Line plot over x from 0 to about 6.3 showing a periodic, flat-topped curve; y-axis labels read -9.74771, with the curve dipping to the lowest level near x = 0.3, 3.3 and 6.3.

I need to find a fitting function that I can use to perform further mathematics. Fourier series does not work, but a 40-degree polynomial give the following fit
Line plot of a periodic curve fitted through black data points, with y-axis values around -9.74771 to -9.74770 and x-axis from 0 to about 6.3; the curve has two deep dips and flat plateaus with wiggles near the right end.

However, the polynomial does not preserve its periodicity over the cycle. Could someone please advice what I should do to get a good fitting function for my data?
 
Fitting with a polynomial with degree larger than 3 is a really bad idea.

Why don't you try to fit this function with a combination of straight lines?? And why do Fourier series not work?
 
A set of straight lines for different ranges should fit best. A Fourier series should give reasonable approximations, but only if you include many terms.