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

  • Thread starter Thread starter arizonian
  • Start date Start date
AI Thread Summary
The discussion revolves around issues with implementing Simpson's 3/8 rule in Matlab for numerical integration. The original code provided by the user has a misunderstanding regarding the weights assigned to the endpoints and middle points, specifically that the final sum should be multiplied by 3/8 instead of 1/8. A user pointed out that the code does not yield the correct answer, prompting a clarification on the weight distribution. Additionally, there are inquiries about errors related to the variable initialization in the code. Overall, the conversation highlights common pitfalls in coding numerical methods and the importance of correctly applying mathematical principles.
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
 
I multiplied the values first without the error limit. Got 19.38. rounded it off to 2 significant figures since the given data has 2 significant figures. So = 19. For error I used the above formula. It comes out about 1.48. Now my question is. Should I write the answer as 19±1.5 (rounding 1.48 to 2 significant figures) OR should I write it as 19±1. So in short, should the error have same number of significant figures as the mean value or should it have the same number of decimal places as...
Thread 'Minimum mass of a block'
Here we know that if block B is going to move up or just be at the verge of moving up ##Mg \sin \theta ## will act downwards and maximum static friction will act downwards ## \mu Mg \cos \theta ## Now what im confused by is how will we know " how quickly" block B reaches its maximum static friction value without any numbers, the suggested solution says that when block A is at its maximum extension, then block B will start to move up but with a certain set of values couldn't block A reach...
Thread 'Calculation of Tensile Forces in Piston-Type Water-Lifting Devices at Elevated Locations'
Figure 1 Overall Structure Diagram Figure 2: Top view of the piston when it is cylindrical A circular opening is created at a height of 5 meters above the water surface. Inside this opening is a sleeve-type piston with a cross-sectional area of 1 square meter. The piston is pulled to the right at a constant speed. The pulling force is(Figure 2): F = ρshg = 1000 × 1 × 5 × 10 = 50,000 N. Figure 3: Modifying the structure to incorporate a fixed internal piston When I modify the piston...
Back
Top