I'm reading section 8.4 Some Examples of Boundary Value Problems in Brezis' Functional Analysis. At the beginning,
Consider the problem $$ (14) \quad \left\{\begin{array}{l} -u^{\prime \prime}+u=f \quad \text { on } I=(0,1), \\ u(0)=u(1)=0, \end{array}\right. $$ where $f$ is a given function (for example in $C(\bar{I})$ or more generally in $L^2(I)$ ). The boundary condition $u(0)=u(1)=0$ is called the (homogeneous) Dirichlet boundary condition.
Definition. A classical solution of (14) is a function $u \in C^2(\bar{I})$ satisfying (14) in the usual sense. A weak solution of (14) is a function $u \in H_0^1(I)$ satisfying $$ (15) \quad \int_I u^{\prime} v^{\prime}+\int_I u v=\int_I f v \quad \forall v \in H_0^1(I) . $$
Proposition 8.15. Given any $f \in L^2(I)$ there exists a unique solution $u \in H_0^1$ to (15). Furthermore, $u$ is obtained by $$ \min _{v \in H_0^1}\left\{\frac{1}{2} \int_I\left[ (v^{\prime})^2+v^2\right] - \int_I f v\right\}; $$ this is Dirichlet's principle.
Then
The method described above is extremely flexible and can be adapted to a multitude of problems. We indicate several examples frequently encountered. In each problem it is essential to specify precisely the function space and to find the appropriate weak formulation.
Example 1 (inhomogeneous Dirichlet condition). Consider the problem $$ (16) \quad \left\{\begin{array}{l} -u^{\prime \prime}+u=f \quad \text { on } I=(0,1), \\ u(0)=\alpha, u(1)=\beta, \end{array}\right. $$ with $\alpha, \beta \in \mathbb{R}$ given and $f$ a given function.
Proposition 8.16. Given $\alpha, \beta \in \mathbb{R}$ and $f \in L^2(I)$ there exists a unique function $u \in H^2(I)$ satisfying (16). Furthermore, $u$ is obtained by $$ \min _{\substack{v \in H^1(I) \\ v(0)=\alpha, v(1)=\beta}}\left\{\frac{1}{2} \int_I\left[ (v^{\prime})^2+v^2\right]-\int_I f v\right\} . $$ If, in addition, $f \in C(\bar{I})$ then $u \in C^2(\bar{I})$.
Proof. Fix any smooth function $u_0$ such that $u_0(0)=\alpha$ and $u_0(1)=\beta$. Introduce as new unknown $\tilde{u}=u-u_0$. Then $\tilde{u}$ satisfies $$ \left\{\begin{array}{l} -\tilde{u}^{\prime \prime}+\tilde{u}=f+u_0^{\prime \prime}-u_0 \quad \text { on } I, \\ \tilde{u}(0)=\tilde{u}(1)=0 . \end{array}\right. $$ We are reduced to the preceding problem for $\tilde{u}$.
It seems the function $u$ in Proposition 8.16 is a weak solution. Could you elaborate on the variational formulation of (16)? Thank you so much for your help!
Let $$ K := \{v \in H^1 (I) : v(0) = \alpha \text{ and } v(1) = \beta\}. $$
Then $K$ is a closed convex subset of $H^1 (I)$. We have $-u^{\prime \prime}+u=f$ on $I$ implies $$ -\int_I u'' (v-u) + \int_I u(v-u) = \int_I f(v-u) \quad \forall v \in K. $$
By integration by parts, $$ \int_I u'' (v-u) = u' (1) (v-u) (1) - u' (0) (v-u) (0) - \int_Iu' (v-u)'= - \int_Iu' (v-u)'. $$
Then we have the weak formulation $$ \int_I u' (v-u)' + \int_I u(v-u) = \int_I f(v-u) \quad \forall v \in K. $$