1
$\begingroup$

The following is related to a question a asked a few days back 1, but now I would like to focus on just one part of the problem.

I have problems computing the integral over the reference element:

$$ \int_{0}^1 (f - \Pi_h^1(f))^2 dx. $$

I think I understood how to use the basis functions on the reference element and what the values of $f$ should be for the interpolant. The problem is with the first $f$ in the integrand. How can I map it? If the affine map is $x = x_j + \gamma (x_{j+1} - x_j)$ I can substitute it into $f$ and obtain

$$ f(x(\gamma)) = cos(2 \pi (x_j + \gamma (x_{j+1} - x_j))). $$

How can I continue? I was following these beautiful notes on page $49$ but that is very simple.

Using Python to do this I ended up with this:

def func_ref(z, x, a, b):
    cos_a = np.cos(2*np.pi*x[a])
    cos_b = np.cos(2*np.pi*x[b])
    return np.power((cos_a - cos_a * (1 - z) + cos_b * z) * (x[b] - x[a]), 2)

where x is simply the vector containing the nodes, a and b would be the left and right neighbor, z the variable of integration. The first term, $\mathbf{cos_a}$ should be the first $f$ of the integrand but I do not know/understand how to do this. Thank you.

Possible solution:

Is it correct to write

$$ \int_{0}^1 (cos(2\pi (x_i + \gamma (x_{i+1} - x_i)) - cos(x_i)(1-\gamma) + cos(x_{j+1})\gamma)^2 (x_{i+1} - x_i) d \gamma $$

and integrate with respect to $\gamma$?

$\endgroup$
  • $\begingroup$ Do you want to do numerical integration or analytic integration? If you want to do analytic integration then you will have to use sympy. If you want to do numeric integration then you will have to select a quadrature method such as Gauss Legendre. $\endgroup$ – Vikram Dec 17 '16 at 17:04
  • $\begingroup$ @Vikram Thanks for the answer. I am not restricted to do one or the other. If I use sympy can I use the solution I have written? The point is if it is correct or not? $\endgroup$ – wrong_path Dec 17 '16 at 17:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.