Results 1 to 2 of 2

Math Help - Error problem

  1. #1
    Newbie
    Joined
    Feb 2010
    Posts
    24

    Error problem

    I want to compute x within 0.1% relative error with Simpson method, these are my m-files. Which command i should add for this?


    function
    simps(a, b, n)


    %simps(a, b, n) approximates the integral of a function f(x) in the
    %interval [a;b] by the composite simpson rule
    %n is the number of subintervals




    h = (b-a)/n;

    sum_even = 0;

    for i = 1:n/2-1
    x(i) = a + 2*i*h;
    sum_even = sum_even + f(x(i));
    end

    sum_odd = 0;

    for i = 1:n/2
    x(i) = a + (2*i-1)*h;
    sum_odd = sum_odd + f(x(i));
    end

    integral = h*(f(a)+ 2*sum_even + 4*sum_odd +f(b))/3





    function y = f(x)
    y=1/x;


    Follow Math Help Forum on Facebook and Google+

  2. #2
    Grand Panjandrum
    Joined
    Nov 2005
    From
    someplace
    Posts
    14,972
    Thanks
    4
    Quote Originally Posted by chronicals View Post
    I want to compute x within 0.1% relative error with Simpson method, these are my m-files. Which command i should add for this?


    function
    simps(a, b, n)


    %simps(a, b, n) approximates the integral of a function f(x) in the
    %interval [a;b] by the composite simpson rule
    %n is the number of subintervals




    h = (b-a)/n;

    sum_even = 0;

    for i = 1:n/2-1
    x(i) = a + 2*i*h;
    sum_even = sum_even + f(x(i));
    end

    sum_odd = 0;

    for i = 1:n/2
    x(i) = a + (2*i-1)*h;
    sum_odd = sum_odd + f(x(i));
    end

    integral = h*(f(a)+ 2*sum_even + 4*sum_odd +f(b))/3





    function y = f(x)
    y=1/x;


    You know the error bound for the composite Simpson's rule:

    |\varepsilon|<\frac{M(b-a)^5}{180n^4}

    where M is a bound on the absolute value of the fourth derivative of f(x) on [a,b]

    Now use the information you have and this bound on the error to obtain a bound on the relative error as a function on n ...

    An alternative method is to use your function to estimate the integral for a number of values of n and use these to determine when the relative error is small enough.

    CB
    Follow Math Help Forum on Facebook and Google+

Similar Math Help Forum Discussions

  1. best fit, minimizing point-to-line error, not y error
    Posted in the Advanced Applied Math Forum
    Replies: 1
    Last Post: March 4th 2011, 05:16 AM
  2. Maximum Error Problem
    Posted in the Calculus Forum
    Replies: 2
    Last Post: August 6th 2010, 04:05 PM
  3. Replies: 1
    Last Post: December 10th 2009, 10:48 PM
  4. new NR error problem
    Posted in the Math Software Forum
    Replies: 1
    Last Post: November 11th 2009, 02:24 AM
  5. Replies: 0
    Last Post: April 1st 2009, 04:22 AM

Search Tags


/mathhelpforum @mathhelpforum