1

I want to write a python program that evaluates the following integral using:

$$\int_{-1}^1 f(x)dx \approx \sum_{i=0}^n w(x_i)f(x_i) $$

In addition, I want to implement a linear transform of the interval with $\ x = mt +c$, such that I can evaluate the integral for any given interval [a,b] once I found appropriate weights and grid points. For this I researched the following transform:

$$ \frac{b-a}{2}\int_{-1}^1 f(\frac{b-a}{2}t + \frac{b+a}{2})dt = \int_{a}^b f(x)dx $$

However, what I am uncertain about is how to transform the weights. So for example, say I have three weights $\ w = (1 , 2 ,3) $ for which I want to numerically evaluate the integral. How would these transform using the linear transform? I tried rearranging for $\ t $ und plugging in the invidual weight $\ x $ values:

$$\ t = \frac{2x}{b-a}t - \frac{b+a}{b-a} $$

However, when I do a test run in python with the function $\ f(x) = x^2 $ I get different values for the integral, using different intervals under the given transform.

Any suggestions of where I went wrong would greatly be appreciated.

ABCCHEM
  • 99

1 Answers1

0

Let $g(t)=f(\frac{b-a}{2}t + \frac{b+a}{2})$ and apply the numerical method to $g$, hence

$$\int_{a}^b f(x)dx= \frac{b-a}{2}\int_{-1}^1 g(t)dt\approx\frac{b-a}{2}\sum_{i=0}^n w_i g(x_i)\\=\frac{b-a}{2}\sum_{i=0}^n w_i f(\frac{b-a}{2}x_i + \frac{b+a}{2})$$