Solving Simpson's 3/8 Rule Problems with Matlab SV7

  • Thread starter arizonian
  • Start date
In summary, the conversation discusses a problem with the implementation of Simpson's 3/8 rule of integration in a computer program. The code is written in Matlab and uses a stepsize of h = (b-a)/n, where a and b are the endpoints and n is the number of points. The function f is the one being integrated and the final value is given by I. The conversation also mentions the weight given to the middle and end points, with the suggestion to multiply the final sum by 3/8 instead of just 1/8. Additionally, someone asks for help with implementing the 3/8 rule in C++ for calculating normal tables.
  • #1
arizonian
18
2
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
 
Physics news on Phys.org
  • #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).
 
  • #3
kakarukeys,

Thank you, you are spot on.

Bill
 
  • #4
why is x=a; showing an error when i tried to use this code
 
  • #5
Hello people i m looking or Simpsons 3/8th rule which can be used for Normal table calculation in C++...need urgent help
 

1. What is the Simpson's 3/8 rule and how is it used in Matlab SV7?

The Simpson's 3/8 rule is a numerical integration method used to approximate the area under a curve. In Matlab SV7, it is used by dividing the interval into subintervals and applying the formula to each subinterval to find the total area.

2. How do I use the Simpson's 3/8 rule in Matlab SV7?

To use the Simpson's 3/8 rule in Matlab SV7, you need to define the function that represents the curve, specify the interval of integration, and choose the number of subintervals. Then, you can use the "simpson" function in Matlab to calculate the approximate area under the curve.

3. What are the benefits of using the Simpson's 3/8 rule in Matlab SV7?

The Simpson's 3/8 rule in Matlab SV7 provides a more accurate estimation of the area under a curve compared to other numerical integration methods. It also allows for easy implementation and automation in solving complex integration problems.

4. Can the Simpson's 3/8 rule be used for any type of function in Matlab SV7?

Yes, the Simpson's 3/8 rule can be used for any continuous function in Matlab SV7. However, it may not always provide accurate results for functions with sharp corners or discontinuities.

5. How do I know if the Simpson's 3/8 rule is the best method for my integration problem in Matlab SV7?

The Simpson's 3/8 rule is most effective for functions that are smooth and continuous. If your function has sharp corners or discontinuities, it may be better to use other numerical integration methods or divide the interval into smaller subintervals for a more accurate result.

Similar threads

  • Introductory Physics Homework Help
Replies
3
Views
368
  • Introductory Physics Homework Help
Replies
25
Views
276
  • Introductory Physics Homework Help
Replies
29
Views
918
  • Introductory Physics Homework Help
3
Replies
97
Views
3K
Replies
5
Views
378
  • Introductory Physics Homework Help
Replies
3
Views
1K
  • Introductory Physics Homework Help
Replies
8
Views
400
  • Engineering and Comp Sci Homework Help
Replies
3
Views
807
  • Introductory Physics Homework Help
Replies
1
Views
996
  • Introductory Physics Homework Help
Replies
11
Views
588
Back
Top