Exp-07

8
Course No: EEE 212 Experiment No: 07 Name of the experiment: NUMERICAL INTEGRATION Name: Md. Arifur Rahman Date of performance: 29-04-2015 Student ID: 1206130 Date of submission: 06-04-2015 Department: EEE Level 2 / Term 2 Section: B ( B-2 ) Partner’s ID: 1206121 Group No:15

description

Experiment 7 pdf for MATLAB report

Transcript of Exp-07

  • Course No: EEE 212

    Experiment No: 07

    Name of the experiment:

    NUMERICAL INTEGRATION

    Name: Md. Arifur Rahman

    Date of performance: 29-04-2015 Student ID: 1206130

    Date of submission: 06-04-2015 Department: EEE

    Level 2 / Term 2

    Section: B ( B-2 )

    Partners ID: 1206121

    Group No:15

  • EXERCISE 1 -

    Integrate the function tabulated in Table over the interval

    from x=1.6 to x=3.8 using composite trapezoidal rule with (a) h=0.2,

    (b) h=0.4 and (c) h=0.6

    X f(X) X f(X)

    1.6 4.953 2.8 16.445

    1.8 6.05 3.0 20.086

    2.0 7.389 3.2 24.533

    2.2 9.025 3.4 29.964

    2.4 11.023 3.6 36.598

    2.6 13.468 3.8 44.701

    The data in Table 7.1 are for f (x) = ex . Find the true value of the integral and compare this with those found in (a), (b) and (c).

    Solution clear all; clc;

    close all;

    x = [1.6 1.8 2.0 2.2 2.4 2.6

    2.8 3.0 3.2 3.4 3.6 3.8];

    y = [4.953 6.05 7.389 9.025

    11.023 13.468 16.445 20.086

    24.533 29.964 36.598 44.701];

    n = length(x)-1;

    actual = 39.748152;

    sum = (y(1) + y(n+1))/2;

    for j = 2 : n

    sum = sum + y(j);

    end

    h = 0.2;

    integral = h * sum;

    error = abs(actual - integral);

    fprintf('Actual Result =

    39.748152\n');

    fprintf('\nFor h = 0.2

    calculated result = %f',

    integral);

    fprintf('\nFor h = 0.2 error

    calculated = %f', error);

    h = 0.4;

    integral = h * sum;

  • error = abs(actual - integral);

    fprintf('\nFor h = 0.4

    calculated result = %f',

    integral);

    fprintf('\nFor h = 0.4 error

    calculated = %f', error);

    h = 0.6;

    integral = h * sum;

    error = abs(actual - integral);

    fprintf('\nFor h = 0.6

    calculated result = %f',

    integral);

    fprintf('\nFor h = 0.6 error

    calculated = %f', error);

    EXERCISE 2 (a) Integrate the function tabulated in Table 7.1 over the interval

    from x=1.6 to x=3.6 using Simpsons composite 1/3 rule. (b) Integrate the function tabulated in Table 7.1 over the interval

    from x=1.6 to x=3.4 using Simpsons composite 3/8 rule.

    Solution (a)

    clear all;

    clc;

    close all;

    x = [1.6 1.8 2.0 2.2 2.4 2.6

    2.8 3.0 3.2 3.4 3.6];

    y = [4.953 6.05 7.389 9.025

    11.023 13.468 16.445 20.086

    24.533 29.964 36.598];

    n = length(x)-1;

    h = ( x(n+1) - x(1) )/n;

    % Simpson 1/3 method

    integral = 0;

    for i = 1:2:n-1

    integral = integral +

    (y(i)+4*y(i+1)+y(i+2));

    end

    integral = (h/3)*integral

    (b)

    clear all;

    clc;

    close all;

    x = [1.6 1.8 2.0 2.2 2.4 2.6

    2.8 3.0 3.2 3.4];

  • y = [4.953 6.05 7.389 9.025

    11.023 13.468 16.445 20.086

    24.533 29.964];

    n = length(x)-1;

    h = ( x(n+1) - x(1) )/n;

    %Simpson 3/8 method

    sum = 0;

    for i = 1:3:n-2

    sum = sum + y(i) +

    3*y(i+1) + 3*y(i+2) +

    y(i+3);

    end

    integral = ((3*h)/8) * sum

    EXERCISE 3

    Solution (a)(i)

    clear all;

    clc;

    close all;

    a = -1;

    b = 1;

    n = 12;

    h = (b-a)/n;

    x = a;

    f = inline('(1+X^2)^-1');

    sum = f(x);

    for i = 2:n

    x = x + h;

    sum = sum + 2*f(x);

    end

    x = b;

    sum = sum + f(x);

    integral = (h/2) * sum

    (a)(ii)

    clear all;

    clc;

    close all;

    a = 0;

    b = 4;

    n = 12;

  • h = (b-a)/n;

    x = a;

    f = inline('(X^2)*exp(-X)');

    sum = f(x);

    for i = 2:n

    x = x + h;

    sum = sum + 2*f(x);

    end

    x = b;

    sum = sum + f(x);

    integral = (h/2) * sum

    (b) Simpsons composite 1/3 rule

    clear all;

    clc;

    close all;

    % 3(b)

    a = -1;

    b = 1;

    n = 12;

    h = (b-a)/n;

    x = a;

    f = inline('(1+X^2)^-1');

    sum = 0;

    for i = 1:2:n-1

    sum = sum + f(x+(i-1)*h) +

    4*f(x+i*h) + f(x+(i+1)*h);

    end

    integral = (h/3) * sum

    (b) Simpsons composite 3/8 rule

    clear all;

    clc;

    close all;

    a = 0;

    b = 4;

    n = 12;

    h = (b-a)/n;

    x = a;

    f = inline('(X^2)*exp(-X)');

    sum = 0;

    for i = 1:3:n-2

    sum = sum + f(x+(i-1)*h) +

    3*f(x+i*h) + 3*f(x+(i+1)*h) +

    f(x+(i+2)*h);

    end

  • integral = (3*h/8) * sum

    EXERCISE 4

    Solution clear all;

    clc;

    close all;

    a = 0;

    b = 2;

    toler = 0.249916*1e-3;

    h = b-a;

    f = inline('X*exp(-2*X^2)');

    m1 = (f(b) + f(a))/2;

    it1 = h*m1;

    it0 = 0;

    i = 1;

    while abs(it1-it0) > toler

    x = a + h/2;

    for j = 1:i

    m1 = m1 + f(x);

    x = x + h;

    end

    i = 2*i;

    h = h/2;

    it0 = it1;

    it1 = h * m1;

    end

    integral = it1

    EXERCISE 5

    Solution clear all;

    close all;

    clc;

    format long;

    actual = pi/4;

    toler = 0.0001;

    a = 0;

    b = pi/2;

  • h = b-a;

    sum = ((sin(16*x1))^2)/2;

    it1 = h*sum;

    diff = 1;

    i = 1;

    while diff > toler

    x = a + h/2;

    for j=1:i

    sum = sum +

    ((sin(16*x))^2);

    x = x+h;

    end

    i = i*2;

    h = h/2;

    it0 = it1;

    it1 = h*sum;

    diff = abs(it1-it0);

    end

    Cal_value = it1

    deviation = ((abs(actual-

    it1))/actual)*100