The two pieces of the function are represented graphically by two slanting lines. -2x for x between -(pi) and zero produces f(x) values +2(pi) to 0 as a line sloping from left to right downwards (negative gradient), and the other piece of the function produces values 0 to +2(pi) sloping from left to write upwards (positive gradient). The whole function represents a V shape. The point (0,0) is defined by both pieces. The sine function resembles this shape approximately for x values between -(pi) and +(pi). The whole of the function lies above the x-axis. Since sin x is 1 at x=(pi)/2 and -(pi)/2, but f(x) requires its value to be 2(pi) for these limits, then we must halve x in sin x and multiply sin x by 2(pi) to emulate f(x). That is, 2(pi)sin(x/2). When x=-(pi), this function becomes 2(pi)sin(-(pi)/2) = 2(pi); when x=0 it's zero; and when x=(pi), it becomes 2(pi). That would be a first approximation to f(x) as a harmonic function.
To proceed we note that the total range is 2(pi), the period of the function. The general infinite Fourier series becomes:
f(x)=a[0]+a[1]cos x + b[1]sin x + a[2]cos 2x + b[2]sin 2x +... to infinity, where I've used square brackets to distinguish between the different constants for the a and b series. This can be written compactly as:
f(x)=a[0]/2 + (sum for n between 1 and (infinity) of){a[n]cos(nx)+b[n]sin(nx)}, where:
a[0]=1/(pi)(integral over the period of)f(x)dx
a[n]=1/(pi)(integral over the period of)f(x)cos(nx)dx
b[n]=1/(pi)(integral over the period of)f(x)sin(nx)dx
But f(x) is in pieces so we must be careful about the limits of integration.
For the piecewise solution, we have to consider separately the left and right components of the function. By left I mean the the left leg of the V graph (where x is between -(pi) and zero) and the right leg (where x is between zero and (pi)). The period of the function, 2(pi), is split between the left and right components, each contributing a range of (pi).
It's useful to prepare for the integration process by writing down the required functions and their derivatives. x^2 has the derivative (dy/dx) 2x, which is the basis of the original function, f(x). We also need -(cos(nx))/n, for which dy/dx is (sin(nx)); (sin(nx))/n, for which dy/dx is cos(nx); 2 is dy/dx of 2x.
We'll be integrating by parts, so the formula (integral between limits A and B of)u.dv/dx.dx=[u.v](between A and B) - (integral between limits A and B of)v.du/dx.dx will be used, where u and v are functions of x.
From these we can see that, putting u=2x and v=(sin(nx))/n, (integral of)2xcos(nx)dx=(2xsin(nx))/n-(integral of)2(sin(nx))/n.dx = (2xsin(nx))/n+2cos(nx))/n^2. Also, putting u=2x and v=(cos(nx))/n, (integral of)2xsin(nx)dx=(2xcos(nx))/n-(integral of)2(cos(nx)/n.dx = (2xcos(nx))/n-2sin(nx))/n^2. These integrals are general and I've omitted limits because these will depend on whether we're looking at the left or right components of the function.
More to follow...