1. Limited time only! Sign up for a free 30min personal tutor trial with Chegg Tutors
    Dismiss Notice
Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Computing Integral Programming

  1. Dec 7, 2014 #1
    • Thread moved from a technical section, so is missing the homework template
    I have a question set for programming to compute integral for the following unknown function using composite rectangle method, trapezoidal rule and simpsons rule.

    [tex]\int_{0}^{1.8} f(x) dx[/tex]

    for h=0.3 and h=0.4

    I have a table of results for f(x) and x as follows
    x=0, 0.3, 0.6, 0.9, 0.12, 0.15, 0.18
    f(x)=0.5, 0.6, 0.8, 1.3, 2, 3.2, 4.8

    My interval is 6 using the formula n=1.8-0/0.3 for the first case. I am just wondering how I should approach this problem in my programming.

    For the rectangle method does anyone have a step by step guide of how this would be done analytically. Surely this would also require the user to enter all values for f(x) too or they be read from a file in some way? I am mainly struggling because I am not sure how to implement this into my program which is in FORTRAN. I have not even thought about how to tackle the trapezoidal or simpson rule yet! Ideally they should be all within one program where the user selects the method of approximation.

    Thanks for any advice
  2. jcsd
  3. Dec 7, 2014 #2


    Staff: Mentor

    I don't know the composite rectangle method. I'm familiar with using rectangles, where you use either the left endpoint of each subinterval or the right endpoint.
    Are you also given a table of results for h = 0.4? Also, a stepsize of 0.4 is problematic, since 0.4 doesn't divide 1.8 evenly.
    No, the number of subintervals is 6.
    The right side of your formula should be written as (1.8 - 0)/0.3. Otherwise, due to the order of operations, what you wrote is 1.8 - (0/0.3) = 1.8.
    Are you asking how you should do the calculations? The term analytically implies the opposite of integrating numerically; i.e., by finding the antiderivative of your function and evaluating it at the two endpoints.
  4. Dec 7, 2014 #3


    User Avatar
    Homework Helper

    For ##h = 0.3##.

    You should numerically estimate the integral using the composite trapezoidal rule. This will give you a good idea of the the correct answer at first.

    Then, you should notice that the step size causes there to be an even number of segments (6) and an odd number of data points (7). This tells you that a Simpson's 1/3 approach would be most appropriate.

    Write functions in FORTRAN that return the values for the respective methods (trapezoidal/Simpson's).

    For ##h = 0.4##.

    There is a serious problem. You can't even numerically estimate the integral with the composite trapezoidal rule using unequal step sizes for each segment. This is because the step size makes your data obsolete.

    A step size of ##0.6## would prove more interesting.
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Have something to add?
Draft saved Draft deleted