6

You could just go for the direct final answer of the integral: $$\int_{a}^{b}\vert {\sin(x)}\vert dx = 2\left(\left\lfloor\frac{b}{\pi}\right\rfloor - \left\lfloor\frac{a}{\pi}\right\rfloor\right) + \cos\left(\left\{\frac{a}{\pi}\right\}\pi\right) - \cos\left(\left\{\frac{b}{\pi}\right\}\pi\right)$$ where $\left\lfloor c\right\rfloor$ denotes the flooring ...


4

Ok, here comes the answer promised in the comment section. Let's start the other way round, going from a general grid to Gaussian grids and further constructions such as spectral elements. In grid methods, one basically selects a number of $N+1$ gridpoints $\{x_k\}_{k=0}^{N}$. As basis functions, one can use Lagrange polynomials constructed over these nodes, ...


4

from scipy.integrate import cumtrapz import numpy as np import matplotlib.pyplot as plt def f(x): return x*np.sin(1/x) if abs(x) > 1e-10 else x f = np.vectorize(f) X = np.arange(-0.5, .5, 0.001) fv = f(X) plt.plot(fv) F = cumtrapz(fv, x=X, initial=0) plt.plot(F);


4

Your integral can be written as $$ \int_a^b f(z)^2 h(z) dz \approx \sum_q f(z_q)^2 h(z_q) w_q $$ where I wrote some quadrature approximation. Now do another quadrature for $f(z)$ $$ f(z) = \int_0^z g(x) dx \approx \sum_q g(x_q) v_q $$ where $x_q \in [0,z]$ are some quadrature nodes and $v_q$ are corresponding weights. Write a function to compute $f(z)$ that ...


3

You need to use the so called Gauss–Jacobi quadrature with $\alpha = 0$ and $\beta = -\frac{1}{2}$. If you look at the error term, you see that you can integrate exactly for a degree up to $2n-1$ with a $n$ points scheme. EDIT to truly answer your question. You want to use this theorem about Gaussian quadrature, theorem 3.6.12 in [1] for a book reference. In ...


2

Disclaimer, I just look at the problem with $r_1=r_2=r_3=r=1$. But I expect, that one can generalize this approach for different $r_i$. I suggest the following mapping: Project the surfaces of an interior cube onto the surface of your superellipsoide. This divides the surface into 6 parts. Because of the symmetry, I will restrict this now to the mapping of ...


2

Let's consider the integral in 2D. Note that the domain where $f(x_1,x_2) = x_1 + x_2 - K$ is positive lies to the right of the dashed line $x_1+x_2=K$ in the sketch, so to account for the positive part function the domain of integration is restricted to the area to the right of the dashed line (shaded area in the sketch). The integral splits in 1D ...


2

Edit: Unfortunately I can not comment on your question. Perhaps someone can like my answer to get a reputation of 50. That's no joke! Anyway, you may use a Gauss Laguerre quadrature or Gauss Hermite quadrature to calculate it. The quadrature rules are designed for integration kernels of following form: Laguerre quadrature: $$\int_{0}^{\infty} e^{-x} f(x)\,dx ...


2

The reason you didn't find 2D quadrature is that we haven't implemented it yet. As to your compilation failure, this does the trick: #include <boost/math/quadrature/gauss_kronrod.hpp> #include <iostream> int main(int argc, char *argv[]) { using namespace boost::math::quadrature; auto f1 = [](double t, double s) { return std::exp(-(t*t+...


2

If you insist on using quad, a more efficient implementation would calculate the integrals over the segments of the subdivision with quad for best accuracy and then a cumulative sum for the anti-derivative value at each sample point. def f(x): return x*np.sin(1/x) X = np.arange(-0.5,0.5,0.001) DF = [ integrate.quad(f,a,b)[0] for a,b in zip(X[:-1],X[1:])...


2

Welcome to SE! For growing x, your function converges to 1-norm.cdf(0), which is $1-0.5=0.5$. Consequently, the integral is indeed divergent, just like Python told you;)


1

Why you are saying this integral even with linear interpolation is going to be zero? Are you familiar with VTK library? Basically, it's the procedure to calculate your integral on your surface: Calculate $u_{xx}$ on each point or vertex by using vtkGradientFilter. Do the integration over the surface by using vtkIntegrateAttributes. It should work. You can ...


Only top voted, non community-wiki answers of a minimum length are eligible