USING MATLAB Number 5 - 13
Posted: Tue Jul 12, 2022 12:47 pm
USING MATLAB Number 5 - 13
Introduction Consider the integral of function f(x) from a to b I=∫abf(x)dx. To find a numerical (approximate) value of I, one may need to divide the interval/domain [a,b] into a set of N subintervals/segments by employing the points a=x1,x2,x3,⋯,xN,xN+1=b I=∫abf(x)dx=∫x1=ax2f(x)dx+∫x2x3f(x)dx+⋯+∫xNxN+1=bf(x)dx=k=1∑N∫xkxk+1f(x)dx and then apply a numerical integration method to each segment. One popular numerical integration method is the Gaussian quadrature rule that is stated as ∫xkxk+1f(x)dx≈2xk+1−xki=1∑nwif(2xk+1−xkξi+2xk+1+xk), where n is the number of Gauss points, ξi the abscissas and wi the weight factors. Table 1 displays the abscissas and weight factors for the first three values of n. Table 1: Abscissas and weight factors for Gaussian integration In this assignment, the integrand and the limits are given by f(x)ab=sin(πx/10)m,=0 m,=10 m,
and the segments are of the same length h=(b−a)/N. It is noted that h is called the grid size. Your tasks are to apply the Gaussian quadrature with n=3 to evaluate the integral I for several values of N, and compare the obtained values with the analytical solution. Requirements For this assessment item, you must perform hand calculations: 1. Find the analytical (exact) value of the integral I. 2. Apply the 3-point Gaussian quadrature to evaluate the integral I for N=1 (the entire domain) and N=2 (the domain divided into 2 segments). 3. Calculate the percentage error ϵ=∣Iexact ∣∣Iapprox −Iexact ∣×100% for each N value. In (7), Iapprox and Iexact are the approximate and exact values of the integral I, respectively. 4. Report the approximate solutions rounded to four decimal places and the corresponding percentage errors rounded to two significant figures.
ment 4. 6. Applies the 3-point Gaussian quadrature to evaluate the integral I for values of N from 1 to 40 in increments of 1 (i.e. N:1,2,3,⋯,39,40 ), where loops are implemented in the code. There are three loops in total (one for N, one for equation (2) and one for equation (3)). Verify the answers by comparing the results obtained at N=1 and N=2 with those from Requirement 5. 7. Applies the 3-point Gaussian quadrature to evaluate the integral I for values of N from 1 to 40 in increments of 1, where the part of the code for solving equation (3) is vectorised (scalar-based calculations replaced with matrix-based calculations). Verify the answers by using the results from Requirement 6 . 8. Applies the 3-point Gaussian quadrature to evaluate the integral I for values of N from 1 to 40 in increments of 1 , where the parts of the code for solving equations (3) and (2) are vectorised. Verify the answers by using the results from Requirement 7 . 9. Plots the approximate solutions (from Requirement 6 or 7 ) as a function of the grid size h. Also display the exact solution Iexact on the same graph for comparison purposes. 10. Plots the corresponding percentage errors as a function of the grid size h. 11. Produces an ASCII file that stores the grid sizes, the approximate values of I and the corresponding percentage errors from Requirement 6 or 7 , where the task of writing data is conducted using loops (loop-based code) and the values are rounded to 3 significant figures for the grid sizes and the errors, and to ten decimal places for the approximate solutions.
12. Produces an ASCII file that stores the values of N, the approximate values of I and the corresponding percentage errors from Requirement 6 or 7 , where the task of writing data is implemented without using loops (vectorised code) and the values are rounded to fourteen decimal places for the approximate solutions and two significant figures for the errors. 13. Has appropriate comments throughout. You must submit pseudocode for Requirement 6 .
Introduction Consider the integral of function f(x) from a to b I=∫abf(x)dx. To find a numerical (approximate) value of I, one may need to divide the interval/domain [a,b] into a set of N subintervals/segments by employing the points a=x1,x2,x3,⋯,xN,xN+1=b I=∫abf(x)dx=∫x1=ax2f(x)dx+∫x2x3f(x)dx+⋯+∫xNxN+1=bf(x)dx=k=1∑N∫xkxk+1f(x)dx and then apply a numerical integration method to each segment. One popular numerical integration method is the Gaussian quadrature rule that is stated as ∫xkxk+1f(x)dx≈2xk+1−xki=1∑nwif(2xk+1−xkξi+2xk+1+xk), where n is the number of Gauss points, ξi the abscissas and wi the weight factors. Table 1 displays the abscissas and weight factors for the first three values of n. Table 1: Abscissas and weight factors for Gaussian integration In this assignment, the integrand and the limits are given by f(x)ab=sin(πx/10)m,=0 m,=10 m,
and the segments are of the same length h=(b−a)/N. It is noted that h is called the grid size. Your tasks are to apply the Gaussian quadrature with n=3 to evaluate the integral I for several values of N, and compare the obtained values with the analytical solution. Requirements For this assessment item, you must perform hand calculations: 1. Find the analytical (exact) value of the integral I. 2. Apply the 3-point Gaussian quadrature to evaluate the integral I for N=1 (the entire domain) and N=2 (the domain divided into 2 segments). 3. Calculate the percentage error ϵ=∣Iexact ∣∣Iapprox −Iexact ∣×100% for each N value. In (7), Iapprox and Iexact are the approximate and exact values of the integral I, respectively. 4. Report the approximate solutions rounded to four decimal places and the corresponding percentage errors rounded to two significant figures.
ment 4. 6. Applies the 3-point Gaussian quadrature to evaluate the integral I for values of N from 1 to 40 in increments of 1 (i.e. N:1,2,3,⋯,39,40 ), where loops are implemented in the code. There are three loops in total (one for N, one for equation (2) and one for equation (3)). Verify the answers by comparing the results obtained at N=1 and N=2 with those from Requirement 5. 7. Applies the 3-point Gaussian quadrature to evaluate the integral I for values of N from 1 to 40 in increments of 1, where the part of the code for solving equation (3) is vectorised (scalar-based calculations replaced with matrix-based calculations). Verify the answers by using the results from Requirement 6 . 8. Applies the 3-point Gaussian quadrature to evaluate the integral I for values of N from 1 to 40 in increments of 1 , where the parts of the code for solving equations (3) and (2) are vectorised. Verify the answers by using the results from Requirement 7 . 9. Plots the approximate solutions (from Requirement 6 or 7 ) as a function of the grid size h. Also display the exact solution Iexact on the same graph for comparison purposes. 10. Plots the corresponding percentage errors as a function of the grid size h. 11. Produces an ASCII file that stores the grid sizes, the approximate values of I and the corresponding percentage errors from Requirement 6 or 7 , where the task of writing data is conducted using loops (loop-based code) and the values are rounded to 3 significant figures for the grid sizes and the errors, and to ten decimal places for the approximate solutions.
12. Produces an ASCII file that stores the values of N, the approximate values of I and the corresponding percentage errors from Requirement 6 or 7 , where the task of writing data is implemented without using loops (vectorised code) and the values are rounded to fourteen decimal places for the approximate solutions and two significant figures for the errors. 13. Has appropriate comments throughout. You must submit pseudocode for Requirement 6 .