$30
The deliverables for this exercise are:
• Your own code file gauss quad weight.c as defined above. Be sure to print the zeroes and weights with at least 15 digits of precision. Your code should make use of the following functions from previous problems:
– getLegendreCoeff
– getLegendreZero
– gaussianElimination
III.1 Exercise #4. Comparing Uniform vs to Gausssian Grid Integrals
It’s now time to put the pieces together and integrate a few functions on the interval [−1,1]. This depends heavily on the code you wrote in the previous problem. Modify the integration program to again evaluate
=?
=?
=? (17)
but this time use Gaussian integration for N = 2,4,8.··· ,s32 and plot error in comparison with the trapezoidal rule. You will want to keep the Trapezoid rule method to be able to make comparisons between Gaussian integration for N point with Trapezoidal rule for 2N points.
The deliverables for this exercise are:
• Your own code file test integrate.c as defined above: give the integrals from -1 to 1 of x8, cos(πx/2), 1/(x2+1) using the Trapezoidal rule and Gaussian quadrature with N = 2 to 32. Be sure to print the integrals with 15 digits of precision. Your code should make use of the following functions from previous problems:
– getLegendreCoeff
– getLegendreZero
– gaussianElimination
• Three plots: One for each integral that gives relative errors of integration against the exact answer as a function N for the Trapezoidal and the Gaussian quadrature. . Be sure to include labels on the axes. Use the naming convention:
– x8err.pdf for the integral of x8.
– cosPIxerr.pdf for the integral of cos(πx/2).
– x2p1inverr.pdf for the integral of 1/(x2 + 1).
Next extend this to multi-dimensional integrals (The next problem we will do some really hard multiple integral using GPUs and parallelization with OpenACC!)
As a quick refresher, a multiple dimensional integrals
) (18)
Applying Gaussian integration to each integral is straight forward,
(19)
N N
≈ XXwiwjg(xi,yj)
(20)
j=1 i=1
This is just a nested loop for a 1d integrals over the x-coordinate and the y-coordinated. Note that the weights wi and the value of xi and yj are exactly the same as in the one dimensional example. This approximation generalizes trivially and dimension on a “hyper-cubic” cell.
III.2 Integrating a few multiple double Integrals
This problem should seem familiar: we’re going to integrate a few problems on the interval [−1,1], except in multiple dimensions. Write a main program test integrate 2d.c that performs the following three integrals using Gaussian integration for N = 2 to 24 in the sum:
] =? (21) + 2 =? (22) ) =? (23)
You can test you code against Mathematica. (Don’t be shy about getting help with Mathematica!)