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

  • Thread starter Thread starter arizonian
  • Start date Start date
Click For Summary
SUMMARY

The discussion centers on implementing Simpson's 3/8 rule of integration using Matlab SV7. The provided code outlines the function simpson38(f,n,a,b), which calculates the integral of a function f over the interval from a to b using n points. A key correction identified is that the final sum should be multiplied by 3/8 instead of 1/8 to adhere to the 3/8 rule. Additionally, a user encountered an error with the initialization of x at a.

PREREQUISITES
  • Understanding of numerical integration methods, specifically Simpson's 3/8 rule.
  • Proficiency in Matlab SV7 programming.
  • Familiarity with function definitions and loops in Matlab.
  • Basic knowledge of mathematical concepts such as endpoints and weights in integration.
NEXT STEPS
  • Review the implementation of Simpson's 1/3 and 3/8 rules in Matlab.
  • Learn about error handling in Matlab to troubleshoot common coding issues.
  • Explore numerical integration techniques in other programming languages, such as C++.
  • Investigate optimization techniques for improving the performance of numerical methods in Matlab.
USEFUL FOR

Matlab programmers, students studying numerical methods, and anyone interested in implementing integration techniques in computational mathematics.

arizonian
Messages
18
Reaction score
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
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).
 
kakarukeys,

Thank you, you are spot on.

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

Similar threads

  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 12 ·
Replies
12
Views
2K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 2 ·
Replies
2
Views
915
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 25 ·
Replies
25
Views
2K
  • · Replies 29 ·
Replies
29
Views
4K
  • · Replies 97 ·
4
Replies
97
Views
6K
Replies
5
Views
1K