NS Wave Quadrature Analysis

Vijay Stroup

University of Central Florida • November 6, 2021

Introduction

In a study conducted by John Cahn, John Mallet-Paret, and Erik van Vleck on "Traveling Wave Solutions for Systems of ODEs on a Two-Dimensional Spatial Lattice", they have deduced an function $\psi$ to represent an electrical impuluse in the human nervious system.
The goal of this project is to use different quadrature methods to determine the result of the function $\psi$ and to determine which method is best suited for solving the function.

Consider the function $\psi: \mathbb{R}\rightarrow\mathbb{R}$

$$ \psi(x) = \frac{1}2 + \frac{1}\pi \int_0^\infty \frac{A(s)sin(sx)}{s(A(s)^2 + c^2s^2)} ds + \frac{c}\pi \int_0^\infty \frac{cos(sx)}{A(s)^2 + c^2s^2} ds $$$$ A(s) = 1 + 2(1 - cos(s)) $$

We can use different methods of integration to estimate $\psi$ at different values of x and c.

The methods of quadrature approximation that will be used in this project will be the following:

Midpoint: $$\int_a^b f(x) dx \approx (b-a)f(\frac{b+a}2)$$

Trapezoidal: $$\int_a^b f(x) dx \approx \frac{b-a}2 (f(a)+f(b))$$

Simpson: $$\int_a^b f(x) dx \approx \frac{h}3 (f(a) + 4f(a+h) + f(a+2h)), \qquad h=\frac{b-a}2$$

In genearl, we can write a quadrature formula as $$\int_a^b f(x)dx \approx \sum_{i=1}^n w_i f(x_i)$$ where we want to choose weights $w_i$ and nodes so that the formula is as accurate as possible.

When doing quadrature analysis, we run into the problem of not knowing what the exact integral will be when comparing for error. Thus, we must use specific algorithms that do not require a compairson of the exact answer.

For the Midpoint rule, we can use the following equation to get the error of each iteration: $$|\int_a^b f(x) dx - M_n| \leq \frac{(b-a)^3}{24n^2} \max_{x \in [a,b]} |f''(x)|$$


For The Trapezoidal rule, we can use Richardson's Error Estimate to determine how accurate each iteration is. Richardson's Error Estimate is defined as: $$|\int_a^b f(x) dx - T_n| \leq \frac{(b-a)^3}{12n^2} \max_{x \in [a,b]} |f''(x)|$$


For Simpson's rule, we can use the error term defined as: $$|\int_a^b f(x) dx - S_n| \leq \frac{(b-a)^5}{180n^4} \max_{x \in [a,b]} |f^{(4)}(x)|$$

I think that Simpson's Rule will be the most accurate when approximating $\psi$. However with this, I think it will be quite a bit more slow than the Trapezoidal Rule which I think will be the $2^{nd}$ most accurate, with a lot more performance. So in the end, I think the Trapezoidal Rule will be the most effective for our problem.

For our function $\psi$, it is reasonable to vary c within the interval [0, 10] and then choose values of x that will capture a good amount of data over an interval $-l$ to $l$. We can determine this by plotting the function $\psi$ with a constant c, and then determine the bounds from there.

Things to think about when analyzing this problem are:

Analyis

We can first start off by visualizing the second and third integrand functions.
We can see both of them have the trigonometric functions sin and cos so we should expect the plots to be bounded to 1 and have some type of oscillation.
I will be utilizing the following libraries:

These libraries will provide all the functionality we will need for approximating the function $\psi$ at different values of x. Scipy does not come with a method for the midpoint rule, so we will have to create a function ourselves to evalute the function $\psi$ for the midpoint rule.

All calculations are done with python/numpy's default float32 datatype which has a machine percision of $1.19209*10^{-7}$.

In this analysis, I1 will be refered to as the integrand in the second term in $\psi$: $$\frac{A(s)sin(sx)}{s(A(s)^2 + c^2s^2)}$$

I2 is the integrand in the third term of $\psi$: $$\frac{cos(sx)}{A(s)^2 + c^2s^2}$$

Let's first start by visualizing the integrand functions I1 and I2. From this we may be able to draw some conclusions as to how $\psi$ should behave.

Here we observe I1 and I2 with c and x being set to 1. They have a maximum at s=0 and then it begins to dampen as we move away from 0.
I1 which is our sine function seems to dampen a lot faster than I2, the cosine. This may be an indicator that we may need to have a bigger upper bound for I2 to get roughly the same error as I1 when doing calculations.

Let us now start to vary c and x and see what time of result we get for I1 and I2.

We can easily see that when we increase x while keeping c constant at 1, our integrands' amplitudes of oscillation increase and thus, will increase the error. From this we should see that the error should grow from small to large or large to small.

When we then increase c, I1 and I2 then dampen very quickly. With this observation, the error when increasing c should decrease the error.

Let us now view what our functions will look like for small values of c.

When c is set to small values such as .1, we can see that it takes much longer for the integrands to dampen. This leads me to believe we will have a more dramatic effect of $\psi$ for small values of c.

We can now visualize $\psi(x), x\in[-20, 20]$ to get a better picture of what to expect from our approximations.
We will just use the basic quad method from scipy which is a general Gaussian quadrature method from Fortran's QUADPACK library to use as visualization of $\psi$.

Viewing the plot above, we can see what the function $\psi$ looks like in the interval $[-20, 20]$. If we look at the zoomed in figure on the right, we can see that there is this "steps" segment in our function. We can also observe from the original plot that the ends seem to be quite turbulent. This aligns with the observations we saw above when viewing I1 and I2 where with increasing x, we see the function having more sharper frequencies. It is also important to note that the function $\psi$ seems to be symmetrical, so we should expect results to reflect that as well.

Let's take a closer look at the ends of our interval where there seems to be lots of noise.

From the plot above, we see that there is fluctuations on the ends of our function that will cause the answer to keep changing and not converge to what we like. This is the main reason as to why we need to stop checking certain values of x depending on what we mark as our c value. We can do this by first plotting what $\psi$ will look like before we begin our calculations; and when we start, adjust our x interval to capture enough data without having to spend extra time doing unnecessary calculations.

Let us now observe what $\psi$ will look like for small values of c.

As c becomes small, the "steps" phenomenon becomes more apparent in our function. It is also observed that there are very extreme oscillations on the ends of our interval leading me to think that with small c values, the higher the error of our approximations will be.

Before we begin to approximate $\psi(x)$ with our different methods, we have to determine what is a proper interval of our integrals. From our visualization of $\psi(x)$ above, we know the ends of the intervals will have high error and plateau, so we should not include this in our calculations. Our goal is to identify the proper region dependent on the value of c, and then run our different algorithms and then compare their approximations and errors to determine which method is best suited for this problem.

Let us now begin to analyze the different quadrature methods mentioned in the introduction.

First we will define the function $\psi(x)$ along with getting the errors of each x value.

We can then create a function to return the value of $\psi$ along the xs defined above dependent on the method we pass to it.

And then a helper function for when we want to visualize our results.

Before we begin running our midpoint method, let's look to see what is a good endpoint for our integrand functions, because allthough we can take our integrals to very large numbers, it may not be worth the computation because of the dampening effect we saw eailer. Let's check the values of what we get when comparing an endpoint of 100 vs 100,000.

We can see that for I1, we can see that the integral bounded to 100 is very close to the integral bounded to 100,000. For I2, this is not the case and we will have to consider a larger limit of integration. Let's write a function that will tell us a good cutoff value for both I1 and I2's limits of integration such that the value of the next iteration has a difference of $10^{-4}$.

How this function works is we again use Gaussian quadrature method. We go from 1 to 1 million as our bounds of integration and do our integration method and keep track of previous values. When we reach two consecutive upper limits of integration where the value of the quadrature is less than our specified tolerance, we choose that as our upper limit since it will not improve.
We are able to do this because remembering what our integrand functions looked like from before, they dampen out over time, so when we reach two values that are closely related to each other, we can stop as it will be continous after that.

In the example above with having c=1, x=1, and a tolerance of $10^{-4}$, we get our limits of integration to be 13 and 43 for I1 and I2 respectively. This function necessary to have so that we do not cut our calculations short, nor do we make unnecessary calculations causing our runtime to be longer.

Midpoint

First thing we want to do as stated above is view what $\psi$ will look like for a certain value of c. Let's pick c=1 to start.

From the plot above, let's use the x interval of $[-10, 10]$.

We can see that for I1, we can see that the integral bounded to 100 is very close to the integral bounded to 100,000. For I2, this is not the case and we will have to consider a larger limit of integration. Let's write a function that will tell us a good cutoff value for both I1 and I2's limits of integration such that the value of the next iteration has a difference of $10^{-4}$.

In the top plot, we have our approximations for the value of $\psi$ over $x\in[-10, 10]$. The values also seem to be oscillating which should be apparent from the trig functions embedded in $\psi$.
It is also important to note the large error spike of I2 around 0. If we take a look back at what I2 is: $$\frac{cos(sx)}{A(s)^2 + c^2s^2}$$ We see that $cos(0)=1$ which is at it's maximum with a large amplitude.

Let's view our results for midpoint with small values of c.

From the plot above, let's use the x interval from $[-5, 5]$.

As expected in our hypotheis, the overall error is much larger when c is small.

Trapezoid

From above when plotting $\psi$ to determine our bounds for x when c=1, we got that a good domain for that is $[-10, 10]$.

From the above we see that we get similar results to the midpoint rule, however one big thing to notice is that the runtime for trapezoid was much faster. So as of now, trapezoid is our best method.

Let's also look at small value of c using the trapezoid method. Also from above, we found that for c=.1, we can restrict our domain to $[-5, 5]$.

Again, our results are very similar to the midpoint rule and like before, the error is higher with lower values of c.

Simpson

Observing the table as a result of Simpson's method, we can see that the error is very small compared to the midpoint and trapezoid methods. Although this result took longer, in my opinion, the little extra time it took to compute the results are worth it for the substantial decrease in the error.

Again, let's see what happens with Simpson's rule for small values of c.

For small values of c, it appears that Simpson's rule is not that much better, and even worse than the midpoint and trapezoidal rules.

Results

Let us first compare our approximated results to our plot eailer of $\psi$.

From the compairson above, we can see that midpoint does horribly for this problem. Going forward in our results, we will not consider the midpoint rule for deciding which method is best for approximating $\psi$.

Let's see how long it takes to run each of our methods from $[-10, 10]$.

From our results it is clear that trapezoid is the fastest and simpson being about 2x as long computation time as trapezoid. This falls inline with the introductory hypothesis as the trapezoid is much faster to solve.
Let's also test the other part of our hypothesis: simpson will have less error than trapezoid.

From the results above, we see that, on average, Simpson has a 184.306% error difference from trapezoid. It is also important to note the percent difference from the time inspection was 70.6398%.

We can also inspect the statistics of both dataframes.

Conclusion

From our results, just viewing the approximation of midpoint turned out to be very off. From there, we took a deeper dive into comparing the Trapezoid Rule vs Simpson's Rule. We considered the case of $x\in[-10, 10]$ and saw an average execution time of $3.69s\pm0.0713s$ for the Trapezoidal Rule, and $7.72s\pm1.09s$ runtime for Simpson's Rule. This is a 70.6398% difference. We then took a look at the average error associated with each method using the Richard's Error Estimate. It was found that the average error for the Trapezoidal Rule was $0.080362\pm0.180290$ while the average error for Simpson's Rule was $0.003282\pm0.014318$. The percent difference of the errors is 184.306%.
So although the Trapezoidal Rule was 71% faster executing, Simpson's Rule gave a 184% more accurate answer. This result is what was not first initially predicted as the magnitude of the error was much more of an influence than the runtime of each of the methods.
The same holds true when looking at small values of c, the only thing is that the error is more substantial due to multiple "steps" phenomenon.
Overall, I believe that Simpson's Rule is the best quadrature approximation method for this problem.