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

Thông tin cơ bản

Định dạng
Số trang 8
Dung lượng 62,22 KB

Các công cụ chuyển đổi và chỉnh sửa cho tài liệu này

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]

Trang 1

Project:THE COMPOSITE GAUSS QUADRATURE WITH UP TO 6 NODES

THE MINH TRAN http://maths-minhthe.violet.vn

1 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

a

dx

x

f

I

where

f (x ) is called the integrand,

a = lower limit of integration

b = upper limit of integration

Figure 1 Integration of a function

Gauss Quadrature Rule

Background:

General n -point rules would approximate the integral

) (

) ( )

( )

b

a

x f c x

f c x f c dx x

∫ (18)

Arguments and weighing factors for n-point Gauss quadrature rules

Trang 2

In handbooks (see Table 1), coefficients and points given for 6 points Gauss quadrature rule are given for integrals of the form

1

) ( )

(

n

i

i

c dx x

g

We can calculate a sample to find ci and xi with n = 2 by using the following formula:

∫ ∑

1

1

2

1

) ( )

(

i

i

c dx x

g

We take f(x) from { 2 3 }

, , ,

1 x x x , so

+

=

+

=

+

=

+

=

3 2 2 3 1 1

3

2 2 2 2 1 1

2

2 2 1 1

2 1

0

:

3

/

2

:

0

:

2

:

1

x c x

c

x

x c x c

x

x c x c

x

c c

=> Solutions :

=

=

=

=

577350269

0

577350269

0 1 1

2 1 2 1

x x c c

Similarly, we have found the following:

Table 1

Weighting factors c and function arguments x used in Gauss quadrature formulas

Points Weighs , ci Points, xi

2

3

4

000000000

1

1 =

c

000000000

1

2 =

c

555555556

0

1 =

c

888888889

0

2 =

c

555555556

0

3 =

c

347854845

0

1 =

c

652145155

0

2 =

c

652145155

0

3 =

c

577350269

0

1 = −

x

577350269

0

2 =

x

774596669

0

1 = −

x

000000000

0

2 =

x

774596669

0

3 =

x

861136312

0

1 = −

x

339981044

0

2 = −

x

339981044

0

3 =

x

Trang 3

5

6

347854845

0

4 =

c

236926885

0

1 =

c

478628670

0

2 =

c

568888889

0

3 =

c

478628670

0

4 =

c

236926885

0

5 =

c

171324492

0

1 =

c

360761573

0

2 =

c

467913935

0

3 =

c

467913935

0

4 =

c

360761573

0

5 =

c

171324492

0

6 =

c

861136312

0

4 =

x

906179846

0

1 = −

x

538469310

0

2 = −

x

000000000

0

3 =

x

538469310

0

4 =

x

906179846

0

5 =

x

932469514

0

1 = −

x

661209386

0

2 = −

x

238619186

0

3 = −

x

238619186

0

4 =

x

661209386

0

5 =

x

932469514

0

6 =

x

2 APPLICATION AND PROGRAMMING

Applying the formula above, we can write a MATLAB program to find the following integral:

dx x

x 2 1 ) 3

(

10

1

3

5 − −

The MATLAB program:

clear;

%The composite Gauss quadrature with up to 6 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 1 though 6 of intervals n = ');

disp(' ')

Trang 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 6 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 ciand 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 ;

Trang 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

Trang 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 = 0 ;

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 = 1

Please input the lower limit of integration b = 10

Please input a natural number from 1 though 6 of intervals n = 6

THE MATLAB PROGRAM RUN AS FOLLOW:

-n Project: THE COMPOSITE GAUSS QUADRATURE WITH UP TO 6 NODES

Trang 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

Trang 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:

1

10

494991

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

🧩 Sản phẩm bạn có thể quan tâm

w