I have the following problem. The domain is $(0,1)$ and we consider a uniform triangulation on $\hat{\Omega}$ with elements $K_i = [i/N,(i+1)/N]$ and $X_h^1$ the linear finite element space. I wrote the following affine map to the reference element $\hat{K} = [0,1]$:
$$ x = x_i + \gamma (x_{i+1} - x_i),$$
the following basis function $\phi(x)$:
\begin{cases} \frac{x-x_{i-1}}{x_i-x_{i-1}} & x_{i-1} \leq x \leq x_i \\ \frac{x_{i+1}-x}{x_{i+1}-x_i} & x_i \leq x \leq x_{i+1} \\ 0, \end{cases}
end the following expression for the interpolant:
$$ \Pi_h^1 f(x) = \sum_{i=0}^{N+1} f(x_i) \phi_i(x). $$
I interpolated the function $f(x) = cos(2 \pi x)$ with a small program in Python and now I have a problem with the $L^2$-error defined as:
$$ ||f - \Pi_h^1 f(x)||^2 = \int_0^1 \left (f - \Pi_h^1 (f) \right )^2 dx$$
which can be decomposed into the sum of the integrals over each element of the mesh and each integral is computed on the reference element using the affine map. I have a problem with the part. I did something like this:
$$ \sum_{i=0}^{N_e} \left (\int_0^1 (f_e - \Pi_h^1 f_e) \right )^2 dx, $$
and even if this is correct, I do not know how to compute each integral on the reference element. Can somebody give me an hint, especially on how to compute $f$ on the reference element? In particular, I tried to wrote the integrand in the following way:
def func_ref(z, x, a, b):
return np.power((np.cos(x[a]) - np.cos(x[a]) * (1 - z) +
np.cos(x[b]) * z) * (x[b] - x[a]), 2)
where z
is the variable.
Thank you.