minimal value of integral I have an integral 
$$\int_0^{\pi/2}\left(\cos(x)-ax\right)^2\,dx$$
and I need to know for which a the function is minimal. 
so I can take the derivative of the integral, but what should I do with the boundries of the integral? 
so I think this should work, but I'm not sure, and thats why asking:
(cos(pi/2) - a(pi/2))² - (cos(0)-a(0))²
Thanks in advance
 A: One way to see the problem is to find the minimal distance between the vector $x\mapsto\cos x$ and the subspace $\operatorname{span}(\operatorname{id})$ in the vector space of continuous functions over $[0,\frac \pi 2]$ endowed with the inner product
$$\langle f,g\rangle=\int_0^{\pi/2}f(x)g(x)dx$$
so we have to find $a$ such that
$$\langle \cos-a\operatorname{id},\operatorname{id}\rangle=\int_0^{\pi/2}x(\cos x-ax)dx=0$$
we find 
$$a=\frac{12}{\pi^3}(\pi-2)$$
A: I think firstly you solve the definite integral to find this function:
$$f(a)=\int_0^{\pi/2}(\cos(x)-ax)^2dx=(2-\pi)a+\frac{1}{4}\pi+\frac{1}{24}a^2\pi^3$$ then solve $f'(a)=0$ and also use the Second derivation test to find the proper possible $a$.
A: One could evaluate the integral directly and take a derivative, or vice-versa:
Regard this as a function of $a$; that is,
$$f(a) = \int_0^{\pi/2} (\cos x - ax)^2 dx$$
This can be differentiated with respect to $a$, giving
$$f'(a) = \int_0^{\pi/2} 2 (\cos x - ax) (-x) dx = 2 \int_0^{\pi/2} (ax^2 - x \cos x )dx$$
Now evaluate the integral by parts, to find
$$f'(a) = 2\left(a \frac{(\pi/2)^3}{3} - \frac 1 2 (\pi - 2)\right)$$
Likewise, the second derivative is given by
$$f''(a) = 2 \int_0^{\pi/2} x^2 dx > 0$$
Hence the only critical point is also a minimum.
