1. Trang chủ
  2. » Đề thi

TO FIND INTEGRAL BY THE GAUS METHOD USING MATLAB LAP TRINHMATLABTINH TICH PHAN BANG PP GAUSS

8 5 0

Đang tải... (xem toàn văn)

THÔNG TIN TÀI LIỆU

Nội dung

% Used to display the gauss points and their weights for i=1:n dispsprintf' x%i=%1.15f',i,xn,i end disp' ' dispsprintf' Evaluation Constants\n' for i=1:n dispsprintf' c%i=%1.15f',i,cn,i [r]

(1)Project:THE COMPOSITE GAUSS QUADRATURE WITH UP TO NODES THE MINH TRAN http://maths-minhthe.violet.vn Summary of Gauss Quadrature Rule of Integration We have the Gauss quadrature rule of approximating integrals of the form This also background to find approximating integrals by MATLAB programs b I = ∫ f ( x )dx a where f (x) is called the integrand, a = lower limit of integration b = upper limit of integration Figure Integration of a function Gauss Quadrature Rule Background: General n -point rules would approximate the integral b ∫ f ( x)dx ≈ c f ( x1 ) + c f ( x ) + + c n f ( x n ) a Arguments and weighing factors for n-point Gauss quadrature rules (18) (2) In handbooks (see Table 1), coefficients and points given for points Gauss quadrature rule are given for integrals of the form n −1 i =1 ∫ g ( x)dx ≈ ∑ ci g ( xi ) We can calculate a sample to find ci and xi with n = by using the following formula: −1 i =1 ∫ g ( x)dx ≈ ∑ ci g ( xi ) We take f(x) from { 1, x , x } , x , so 1 : = c1 + c x : = c x + c x 1 2   2 => Solutions : x : / = c x + c x 1 2  x : = c x + c x 1 2  c1 = c =    x1 = −0.577350269  x = 0.577350269 Similarly, we have found the following: Table Weighting factors c and function arguments x used in Gauss quadrature formulas Points Weighs , ci Points, xi c1 = 1.000000000 x1 = −0.577350269 c = 1.000000000 x = 0.577350269 c1 = 0.555555556 x1 = −0.774596669 c = 0.888888889 x = 0.000000000 c3 = 0.555555556 x3 = 0.774596669 c1 = 0.347854845 x1 = −0.861136312 c = 0.652145155 x = −0.339981044 c3 = 0.652145155 x3 = 0.339981044 (3) c = 0.347854845 x = 0.861136312 c1 = 0.236926885 x1 = −0.906179846 c = 0.478628670 x = −0.538469310 c3 = 0.568888889 x3 = 0.000000000 c = 0.478628670 x = 0.538469310 c5 = 0.236926885 x5 = 0.906179846 c1 = 0.171324492 x1 = −0.932469514 c = 0.360761573 x = −0.661209386 c3 = 0.467913935 x3 = −0.238619186 c = 0.467913935 x = 0.238619186 c5 = 0.360761573 x5 = 0.661209386 c6 = 0.171324492 x6 = 0.932469514 APPLICATION AND PROGRAMMING Applying the formula above, we can write a MATLAB program to find the following integral: 10 ∫ (3x − x − 1)dx The MATLAB program: clear; %The composite Gauss quadrature with up to nodes f= @(x) (3*x^5-2*x^3-1) ; % f(x), the function to calcualate integral % a, The lower limit of integration a=input('Please input the lower limit of integration a = '); % b, The upper limit of integration b=input('Please input the lower limit of integration b = '); % n, The maximum number of Gauss points n=input('Please input a natural number from though of intervals n = '); disp(' ') (4) disp(' ') disp(sprintf(' THE MATLAB PROGRAM RUN AS FOLLOW: ')) disp(' ') %********************************************************************** % This displays title information fprintf( 2, ' SCIENTIFIC RESEARCH\n') fprintf(2, ' Coding Project in Applied Mathematics\n') fprintf(2, ' THE MINH TRAN\n') disp(sprintf('\n\n n')) fprintf(2,' Project: THE COMPOSITE GAUSS QUADRATURE WITH UP TO NODES\n') disp(sprintf('\n\n n')) % Displays what inputs are being used disp(sprintf('\n\n********************************Input Data**********************************\n')) disp(sprintf(' f(x), Integral function')) disp(sprintf(' a = %g, Lower limit of integration ',a)) disp(sprintf(' b = %g, Upper limit of integration ',b)) disp(sprintf(' n = %g, Number of Gauss Points, 1-6\n',n)) format short g % To calculate coefficients ci and points xi x = zeros(6,6) ; c = zeros(6,6) ; i=1 ; x(i,1) = 0.0 ; c(i,1) = 2.0 ; i=2 ; x(i,1) = -0.5773502691896260 ; x(i,2) = -x(i,1) ; c(i,1) = 1.0 ; c(i,2) = 1.0 ; i=3 ; x(i,1) = -0.7745966692414830 ; x(i,2) = 0.0 ; x(i,3) = -x(i,1) ; c(i,1) = 0.5555555555555560 ; c(i,2) = 0.8888888888888890 ; c(i,3) = c(i,1) ; i=4 ; x(i,1) = -0.8611363115940530 ; x(i,2) = -0.3399810435848560 ; x(i,3) = -x(i,2) ; x(i,4) = -x(i,1) ; c(i,1) = 0.3478548451374540 ; (5) c(i,2) = 0.6521451548625460 ; c(i,3) = c(i,2) ; c(i,4) = c(i,1) ; i=5 ; x(i,1) = -0.9061798459386640 ; x(i,2) = -0.5384693101056830 ; x(i,3) = 0.0 ; x(i,4) = -x(i,2) ; x(i,5) = -x(i,1) ; c(i,1) = 0.2369368850561890 ; c(i,2) = 0.4786386704993660 ; c(i,3) = 0.5688888888888890 ; c(i,4) = c(i,2) ; c(i,5) = c(i,1) ; i=6 ; x(i,1) = -.9324695142032520 ; x(i,2) = -.6612093864662650 ; x(i,3) = -.2386191860831970 ; x(i,4) = -x(i,3) ; x(i,5) = -x(i,2) ; x(i,6) = -x(i,1) ; c(i,1) = 0.1713244923791700 ; c(i,2) = 0.3607615730481390 ; c(i,3) = 0.4679139345726910 ; c(i,4) = c(i,3) ; c(i,5) = c(i,2) ; c(i,6) = c(i,1) ; % Used to display the gauss points and their weights for i=1:n disp(sprintf(' x%i=%1.15f',i,x(n,i))) end disp(' ') disp(sprintf(' Evaluation Constants\n')) for i=1:n disp(sprintf(' c%i=%1.15f',i,c(n,i))) end % Transform the evaluation points to fit the interval disp(' ') disp('2) The evaluation points are definted for the interval [-1,1] Transform them') disp(' to fit [a,b] This is done by the following formula') disp(' ') disp(' xnew = (b-a)/2 * x + (b+a)/2') disp(' ') disp(sprintf(' Transformed Evaluation Locations\n')) % Transform the locations for i=1:n tr(i)=(b-a)/2*x(n,i)+(b+a)/2 ; disp(sprintf(' x%i=%1.15f',i,tr(i))) end (6) % Apply the Gaussian procedure disp(' ') disp('3) The approximation is calculated as follows:') disp(' ') disp(' app = sum(i=1,n) c(i)*f(x(i))') app = ; disp(' ') % The approximation of Gaussian integration for i=1:n-1 app = app + c(n,i)*f(tr(i)) ; disp(sprintf(' %1.15f * %g',c(n,i),f(tr(i)))) end app = app + c(n,n)*f(tr(n)) ; disp(sprintf(' + %1.15f * %g',c(n,n),f(tr(n)))) disp(sprintf(' ')) disp(sprintf(' %g',app)) % The result disp(' ') disp('4) The approximation must be transformed to fit the [a,b] interval.') disp(' ') disp(' Thus, the approximation of integration on [a,b] with the conditions:') disp(sprintf(' a = %g, Lower limit of integration ',a)) disp(sprintf(' b = %g, Upper limit of integration ',b)) disp(sprintf(' n = %g, Number of Gauss Points\n',n)) disp(' ') disp(' app = (b-a)/2 * app') disp(sprintf(' = %g * %g',(b-a)/2,app)) % also transform the approximation app = (b-a)/2 * app ; disp(sprintf(' = %g',app)) disp(sprintf('\n\n********************************The end**********************************\n')) disp(' ') disp(' THANK YOU AND HAVE A GOOD DAY ! ') The result Please input the lower limit of integration a = Please input the lower limit of integration b = 10 Please input a natural number from though of intervals n = THE MATLAB PROGRAM RUN AS FOLLOW: -n Project: THE COMPOSITE GAUSS QUADRATURE WITH UP TO NODES (7) -n ********************************Input Data********************************** f(x), Integral function a = 1, Lower limit of integration b = 10, Upper limit of integration n = 6, Number of Gauss Points, 1-6 x1=-0.932469514203252 x2=-0.661209386466265 x3=-0.238619186083197 x4=0.238619186083197 x5=0.661209386466265 x6=0.932469514203252 Evaluation Constants c1=0.171324492379170 c2=0.360761573048139 c3=0.467913934572691 c4=0.467913934572691 c5=0.360761573048139 c6=0.171324492379170 2) The evaluation points are definted for the interval [-1,1] Transform them to fit [a,b] This is done by the following formula xnew = (b-a)/2 * x + (b+a)/2 Transformed Evaluation Locations x1=1.303887186085366 x2=2.524557760901808 x3=4.426213662625614 x4=6.573786337374386 x5=8.475442239098193 x6=9.696112813914635 3) The approximation is calculated as follows: app = sum(i=1,n) c(i)*f(x(i)) 0.171324492379170 * 5.87279 0.360761573048139 * 274.464 0.467913934572691 * 4922.2 0.467913934572691 * 36260.6 0.360761573048139 * 129981 + 0.171324492379170 * 255280 -109998 4) The approximation must be transformed to fit the [a,b] interval (8) Thus, the approximation of integration on [a,b] with the conditions: a = 1, Lower limit of integration b = 10, Upper limit of integration n = 6, Number of Gauss Points app = (b-a)/2 * app = 4.5 * 109998 = 494991 ********************************The end********************************** THANK YOU AND HAVE A GOOD DAY ! The MATHEMATICA program: ‡ 10 I3 x5 − x3 − 1M  x 494991 (9)

Ngày đăng: 06/06/2021, 03:35

TỪ KHÓA LIÊN QUAN

TÀI LIỆU CÙNG NGƯỜI DÙNG

TÀI LIỆU LIÊN QUAN

w