0
$\begingroup$

A problem asks to integrate the function $f(x) = \frac{x}{1+x^4}$ on $[-1, 2]$ using the Midpoint rule and the Trapezoidal rule, which I did in MATLAB. Then it asks to determine the value of this integral exactly up to 10 decimal places, after which it asks to do a log-log plot of the absolute value of the truncation error of each method as a function of $h$ (the step size) and explain how to spot the order of convergence of each method from the plot. I attempted to do all this with the Midpoint rule, and hence come my questions:

  • For the Midpoint rule, the error term is $\frac{h^3}{24} f''(c)$, with $c\in [-1,2]$. So I took the 3rd derivative of $f$, set it to $0$ and found the real roots of the function. I found that the greatest value of $f''$, in absolute value, which is $8$, is attained at $c=0$. So I set the error term function to be $g(h)=\frac13 h^3$. Is this correct?
  • In MATLAB, I chose the range for $h$ as follows
h = logspace(0.001,0.1);
y = 1/3 * h.^3;
loglog(h,y,'-s')
grid on

which gave the following picture

From which we can see that the ordinates axis increases at about the same rate as the abscissa axis. So the order of convergence must be linear. Is this correct?

  • Lastly, I wasn't able to get the value of the integral to 10 decimal places even with $N=9600\cdot8$ ($h=3.9063 \times 10^{-5}$) with the Trapezoidal method. I'm reluctant to increase $N$ because MATLAB already takes about 10 minutes to do this, and my computer is very fast. What is it that I'm doing wrong? Why is MATLAB so slow in this case? I estimated it would need to do no more than 1,000,000 operations to perform this approximation.
$\endgroup$
2
  • 1
    $\begingroup$ Notice that since this is an odd function, the integral from $-1$ to $1$ is $0$. So you should just find the integral on the interval $[1,2]$. That should cut down the computation time. $\endgroup$ – John Wayland Bales Aug 18 '18 at 23:13
  • $\begingroup$ This shortens the computation time, yet it looks like $N=72600$ is still not enough for the 10-digit precision. I'm wondering how come the computation process takes MATLAB several minutes to complete. It doesn't look like many billion operations are needed. $\endgroup$ – sequence Aug 19 '18 at 0:34
1
$\begingroup$

For the second part IMO you misunderstood the task. I believe you were asked to compute the exact value by solving the integral, $$ \int_{-1}^2\frac{x}{1+x^4}dx=\frac12\int_{1}^2\frac{d(x^2)}{1+(x^2)^2}dx=\frac12(\arctan(4)-\arctan(1))≈0.270\,209\,750\,135\,292 $$

Using that value as reference you get the errors of the methods as

error plot

where due to the accumulation of floating point noise there is an additional $\mu/h$ resp. $\mu N$ error term and the error is minimal where the method error $\sim N^{-2}$ is in balance with it, that is, $N\sim \sqrt[3]{1/\mu}$, which is with $\mu=10^{-16}$ at a scale of $10^5$.

$\endgroup$

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.