Results 1 to 8 of 8

Math Help - Reinmann Integration m file error? :F

  1. #1
    Junior Member
    Joined
    Apr 2010
    Posts
    59

    Reinmann Integration m file error? :F

    Hey all,

    Iv written a m file on Reimann Integration:

    function [i] = in(a,b,n)
    % integrates increasing function
    h = (b-a)/n;
    l = a+h*(0:n-1);
    u = l+h;
    U = h*sum(u^2)
    L = h*sum(1^2)
    U - L
    end

    It doesn't work... I want it to give a Lower Bound and an Upper bound as i use more strips, n.

    Any help?
    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 ramdrop View Post
    Hey all,

    Iv written a m file on Reimann Integration:

    function [i] = in(a,b,n)
    % integrates increasing function
    h = (b-a)/n;
    l = a+h*(0:n-1);
    u = l+h;
    U = h*sum(u^2)
    L = h*sum(1^2) <-- one squared won't work
    U - L
    end

    It doesn't work... I want it to give a Lower Bound and an Upper bound as i use more strips, n.

    Any help?
    CB
    Follow Math Help Forum on Facebook and Google+

  3. #3
    Junior Member
    Joined
    Apr 2010
    Posts
    59
    Doesn't work with any function. If i had Sin(u), and then Sin(1)
    Follow Math Help Forum on Facebook and Google+

  4. #4
    Grand Panjandrum
    Joined
    Nov 2005
    From
    someplace
    Posts
    14,972
    Thanks
    4
    Try this:

    Code:
    function [II,Lo,Up] = in(a,b,n)
    % integrates increasing function
      h = (b-a)/n;
      lo = a+h*(0:n-1);
      up = lo+h;
      Up = h*sum(up.^2);
      Lo = h*sum(lo.^2);
      II=(Up+Lo)/2;
    end
    CB
    Follow Math Help Forum on Facebook and Google+

  5. #5
    Junior Member
    Joined
    Apr 2010
    Posts
    59
    That works, for example I type:

    in(1,5,10) and get 41.4400

    but im still unsure of the actual function, because inside the m-file I don't see a function defined, or am i being stupid?
    Follow Math Help Forum on Facebook and Google+

  6. #6
    Grand Panjandrum
    Joined
    Nov 2005
    From
    someplace
    Posts
    14,972
    Thanks
    4
    Quote Originally Posted by ramdrop View Post
    That works, for example I type:

    in(1,5,10) and get 41.4400

    but im still unsure of the actual function, because inside the m-file I don't see a function defined, or am i being stupid?
    These lines evaluate the Upper and Lower integrals respectivly:

    Code:
      Up = h*sum(up.^2);
      Lo = h*sum(lo.^2);
    So here we are attempting to evaluste the integral of f(x)=x^2

    CB
    Follow Math Help Forum on Facebook and Google+

  7. #7
    Junior Member
    Joined
    Apr 2010
    Posts
    59
    Im still not really understanding it, I find MATLAB so difficult although it is a very effective tool to use.

    I see what you mean by the function x , if I was say, to use exp(x) function, The way I see it is the "up / lo" is defined as "x", so I would put in, exp(lo) and exp(up) or something?

    With the actual command 'in(1,5,10)' thats integrating the function between limits 5 and 1 , subtracting the 1st limit from the 5th limit as you normally would do.

    The 'n' in this case is suppose to be the number of strips, but not seeing how, or where this affects it. I know its suppose to make it more accurate or something, so Il try with say, 100 strips and see, it should ultimately get closer to the Integral.

    Im also trying to, (after iv typed the command) I want it to show "Up = ...." and Lo = "....", and mathematically I work out the integral to be between, then when I up the value of 'n' the "bounds" get closer together, how would i write this?
    Follow Math Help Forum on Facebook and Google+

  8. #8
    Grand Panjandrum
    Joined
    Nov 2005
    From
    someplace
    Posts
    14,972
    Thanks
    4
    Quote Originally Posted by ramdrop View Post
    Im still not really understanding it, I find MATLAB so difficult although it is a very effective tool to use.

    I see what you mean by the function x , if I was say, to use exp(x) function, The way I see it is the "up / lo" is defined as "x", so I would put in, exp(lo) and exp(up) or something?

    With the actual command 'in(1,5,10)' thats integrating the function between limits 5 and 1 , subtracting the 1st limit from the 5th limit as you normally would do.

    The 'n' in this case is suppose to be the number of strips, but not seeing how, or where this affects it. I know its suppose to make it more accurate or something, so Il try with say, 100 strips and see, it should ultimately get closer to the Integral.

    Im also trying to, (after iv typed the command) I want it to show "Up = ...." and Lo = "....", and mathematically I work out the integral to be between, then when I up the value of 'n' the "bounds" get closer together, how would i write this?
    Function definition for integrating exp(x) from a to b using n subintervals:

    Code:
    function [II,Lo,Up] = Riemann(a,b,n)
    % integrates increasing function
      h = (b-a)/n;
      lo = a+h*(0:n-1);
      up = lo+h;
      Up = h*sum(exp(up));
      Lo = h*sum(exp(lo));
      II=(Up+Lo)/2;
    end
    Calling code and results:

    Code:
    >> [II,Lo,Up]=Riemann(1,5,2000)
    II =
      145.6949
    Lo =
      145.5492
    Up =
      145.8406
    >>
    Actual integral is exp(5)-exp(1)=145.6949

    CB
    Follow Math Help Forum on Facebook and Google+

Similar Math Help Forum Discussions

  1. Integration: Error Function
    Posted in the Calculus Forum
    Replies: 3
    Last Post: April 1st 2010, 10:25 PM
  2. Error in Integration....
    Posted in the Calculus Forum
    Replies: 9
    Last Post: March 7th 2010, 05:10 AM
  3. Reinmann sum problem?
    Posted in the Calculus Forum
    Replies: 2
    Last Post: February 11th 2010, 08:47 PM
  4. Mat lab - Referencing M-file in another M-file
    Posted in the Math Software Forum
    Replies: 5
    Last Post: December 16th 2009, 03:53 AM
  5. Integration of quadratic denominaters error
    Posted in the Calculus Forum
    Replies: 3
    Last Post: February 22nd 2009, 02:04 AM

Search Tags


/mathhelpforum @mathhelpforum