Question

Use Gaussian Quadrature to find the value of the integral of: f(x) = 79.13 / ( 5.30 + 2.24 * X * X) between X= -0.62 and X= 1(e) ANSWER SECTION: SELECTIONS FOR BLANK NUMBER 1 (a) -53.595 b) -26.7975 29.6857 (d) 53.595 (e) 26.7975 SELECTIONS FOR BLANKMultiple choices

0 0
Add a comment Improve this question Transcribed image text
Answer #1


Answer Section Selection For Blank Number 1 + @ 26.7975 Selection For Blank Number 2 » @ 26.9188 Selection for Blomk Number 3 %Matlab code for finding integration using Simpson Trapizoidal and Guassian Quadrature method clear all close all Function foend err=1; nn=4; while err>=0.0000005 v_trapl=trapizoidal(func, a, b, nn); v_trap2=trapizoidal (func, a, b, nn+1); err=abs( (loop for Riemann integration for i=2: length(xx)-1 xxl=xx (i); val=val+dx*double(func(xx1)); end val=val+dx* (0.5*double(funcy=cos((2*(0:N)+1) *pi/(2*N+2 ) ) +(0.27/N1)*sin(pi*xu*N/N2); % Legendre-Gauss Vandermonde Matrix L=zeros(N1,N2); DerivativeIntegration using Gaussian quadrature method =26.79 7483434492722 For N=3 Integration using Gaussian quadrature method =26.91

%Matlab code for finding integration using Simpson Trapizoidal and Guassian
%Quadrature method
clear all
close all

%Function for which integration have to find
func=@(x) 79.13./(5.30+2.24.*x.*x);

fprintf('Function for which integration have to find f(x)=')
disp(func)
%Upper and lower limit of integration
a=-0.62; b=1.55;
fprintf('Upper limit a=%f and lower limit b= %f.\n',a,b)
%All n values
n=[2 3 4 6];

%Exact integral value
ext_int=integral(func,a,b);
fprintf('Exact integral value is %f.\n',ext_int)

for i=1:length(n)
  
    %integration using Gaussian Quadrature method
    v_Gauss(i)=Gaussian_quadrature(func,a,b,n(i));
    %Printing the result
    fprintf('For N=%d\n',n(i))
    fprintf('\tIntegration using Gaussian quadrature method =%2.15f\n\n',v_Gauss(i))
  
end

%Function for which integration have to find
func=@(x) 63.52./(4.07+2.23.*x.*x);
%All n values
n=[4 8];

fprintf('Function for which integration have to find f(x)=')
disp(func)
%Upper and lower limit of integration
a=-0.15; b=1.56;
fprintf('Upper limit a=%f and lower limit b= %f.\n',a,b)

for i=1:length(n)
  
    %integration using Gaussian Quadrature method
    v_trap(i)=trapizoidal(func,a,b,n(i));
    %Printing the result
    fprintf('For N=%d\n',n(i))
    fprintf('\tIntegration using Trapizoidal method =%2.15f\n\n',v_trap(i))
  
end

err=1; nn=4;
while err>=0.0000005
    v_trap1=trapizoidal(func,a,b,nn);
    v_trap2=trapizoidal(func,a,b,nn+1);
    err=abs((v_trap2-v_trap1)/v_trap2);
    nn=nn+1;
end
fprintf('In Trapizoidal method Final result in this process is %f with n=%d\n',v_trap2,nn)

%Function for which integration have to find
func=@(x) 59.18./(8.79+1.24.*x.*x);
%All n values
n=[4 8];

fprintf('Function for which integration have to find f(x)=')
disp(func)
%Upper and lower limit of integration
a=-0.92; b=1.37;
fprintf('Upper limit a=%f and lower limit b= %f.\n',a,b)

for i=1:length(n)
  
    %integration using Gaussian Quadrature method
    v_simp(i)=simpson(func,a,b,n(i));
    %Printing the result
    fprintf('For N=%d\n',n(i))
    fprintf('\tIntegration using Simpson method =%2.15f\n\n',v_simp(i))
  
end

err=1; nn=4;
while err>=0.0000005
    v_trap1=simpson(func,a,b,nn);
    v_trap2=simpson(func,a,b,nn+2);
    err=abs((v_trap2-v_trap1)/v_trap2);
    nn=nn+1;
end
fprintf('In Trapizoidal method Final result in this process is %f with n=%d\n',v_trap2,nn)

%%Matlab function for Trapizoidal integration
function val=trapizoidal(func,a,b,N)
    % func is the function for integration
    % a is the lower limit of integration
    % b is the upper limit of integration
    % N number of rectangles to be used
    val=0;
    %splits interval a to b into N+1 subintervals
    xx=linspace(a,b,N+1);
    dx=xx(2)-xx(1); %x interval
    %loop for Riemann integration
        for i=2:length(xx)-1
            xx1=xx(i);
            val=val+dx*double(func(xx1));
        end
       val=val+dx*(0.5*double(func(xx(1)))+0.5*double(func(xx(end))));
end

%%Matlab function for Simpson integration
function val=simpson(func,a,b,N)
    % func is the function for integration
    % a is the lower limit of integration
    % b is the upper limit of integration
    % N number of rectangles to be used
    %splits interval a to b into N+1 subintervals
    xx=linspace(a,b,N+1);
    dx=xx(2)-xx(1); %x interval
    val=(dx/3)*(double(func(xx(1)))+double(func(xx(end))));
    %loop for Riemann integration
        for i=2:length(xx)-1
            xx1=xx(i);
            if mod(i,2)==0
                val=val+(dx/3)*4*double(func(xx1));
            else
                val=val+(dx/3)*2*double(func(xx1));
              
            end
        end    
end


%Function for Gaussian quadrature
function val=Gaussian_quadrature(func,a,b,N)

%
% This script is for computing definite integrals using Legendre-Gauss
% Quadrature. Computes the Legendre-Gauss nodes and weights on an interval
% [a,b] with truncation order N
%
% Suppose you have a continuous function f(x) which is defined on [a,b]
% which you can evaluate at any x in [a,b]. Simply evaluate it at all of
% the values contained in the x vector to obtain a vector f. Then compute
% the definite integral using sum(f.*w);
%
    N=N-1;
    N1=N+1; N2=N+2;

    xu=linspace(-1,1,N1)';

    % Initial guess
    y=cos((2*(0:N)'+1)*pi/(2*N+2))+(0.27/N1)*sin(pi*xu*N/N2);

    % Legendre-Gauss Vandermonde Matrix
    L=zeros(N1,N2);

    % Derivative of LGVM
    Lp=zeros(N1,N2);

    % Compute the zeros of the N+1 Legendre Polynomial
    % using the recursion relation and the Newton-Raphson method

    y0=2;

    % Iterate until new points are uniformly within epsilon of old points
    while max(abs(y-y0))>eps


        L(:,1)=1;
        Lp(:,1)=0;

        L(:,2)=y;
        Lp(:,2)=1;

        for k=2:N1
            L(:,k+1)=( (2*k-1)*y.*L(:,k)-(k-1)*L(:,k-1) )/k;
        end

        Lp=(N2)*( L(:,N1)-y.*L(:,N2) )./(1-y.^2);

        y0=y;
        y=y0-L(:,N2)./Lp;

    end

    % Linear map from[-1,1] to [a,b]
    x=(a*(1-y)+b*(1+y))/2;    

    % Compute the weights
    w=(b-a)./((1-y.^2).*Lp.^2)*(N2/N1)^2;
  
    val=0;
    for ii=1:length(x)
        val=val+w(ii)*func(x(ii));
    end
end
%%%%%%%%%%%%%%%%%%%%%%%% End of Code %%%%%%%%%%%%%%%%%%%%%%%

Add a comment
Know the answer?
Add Answer to:
Multiple choices Use Gaussian Quadrature to find the value of the integral of: f(x) = 79.13...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT