1. Not finding help here? Sign up for a free 30min 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!

Simpson's 3/8's rule

  1. Nov 19, 2004 #1
    I am having problems in Numerical Methods with Simpson's 3/8 rule of integration. Of course, this is computer driven. The code that I have written for Matlab (SV7) goes as such:

    1) function simpson38(f,n,a,b)
    2) h = (b-a)/n;
    3) x = a;
    4) sum = f(x);
    5) for i = 1:3:(n-3)
    6) x = x + h;
    7) sum = sum + 3 * f(x);
    8) x = x + h;
    9) sum = sum + 3 * f(x);
    10) x = x + h
    11) sum = sum + 2* f(x);
    12) end
    13) x = x + h;
    14) sum = sum + 3 * f(x);
    15) x = x + h;
    16) sum = sum + 3 * f(x);
    17) x = x + h
    18) sum = sum + f(b);
    19) I = (b-a) * sum/(8*n)


    f = the function to be integrated, n = number of points, h = the stepsize, i is a counter, and sum is the sum of the values. a and b are the endpoints. I = the final integrated value.

    If I am reading the book right, the middle points are given a weight of 3/8 each, with the end points given a weight of 1/8. With that in mind, line 11 should be weighted 2/8 (end point from 2 directions) unless it is the final endpoint.

    What am I missing?

    Thanks
    Bill
     
  2. jcsd
  3. Nov 19, 2004 #2
    Tell me the problem. The code does not give correct answer?
    I think you need to multiply your final sum by 3/8 not just 1/8 (hence the name 3/8 rule).
     
  4. Nov 19, 2004 #3
    kakarukeys,

    Thank you, you are spot on.

    Bill
     
  5. Nov 10, 2011 #4
    why is x=a; showing an error when i tried to use this code
     
  6. Nov 2, 2012 #5
    Hello people i m looking or Simpsons 3/8th rule which can be used for Normal table calculation in C++....need urgent help
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Have something to add?



Similar Discussions: Simpson's 3/8's rule
  1. Lifting the Simpsons (Replies: 4)

  2. M/s^3 to m/s^2 (Replies: 3)

Loading...