Simpson's Rule in MATLAB: Single vs Composite

  • Context: MATLAB 
  • Thread starter Thread starter tironel
  • Start date Start date
  • Tags Tags
    Matlab
Click For Summary
SUMMARY

The discussion centers on implementing Simpson's Rule in MATLAB, specifically comparing the Composite 1/3 Simpson's Rule with a single application of Simpson's Rule. The user successfully programmed the Composite version but is uncertain about the implementation of the single application. It is confirmed that setting n=1 in the Composite function will yield results equivalent to a single application of Simpson's Rule. The provided MATLAB function, P_simpson13, calculates the integral using the Composite method.

PREREQUISITES
  • Understanding of numerical integration techniques, specifically Simpson's Rule
  • Proficiency in MATLAB programming
  • Familiarity with function handles in MATLAB
  • Knowledge of loop constructs in MATLAB
NEXT STEPS
  • Research the built-in MATLAB functions for numerical integration, such as integral
  • Learn how to implement a single application of Simpson's Rule in MATLAB
  • Explore error analysis in numerical integration methods
  • Investigate the differences between Composite Simpson's Rule and other numerical methods like Trapezoidal Rule
USEFUL FOR

Students and educators in mathematics or engineering fields, MATLAB programmers, and anyone interested in numerical methods for integration.

tironel
Messages
10
Reaction score
0
Ok I just completed a homework assignment by programming a Composite 1/3 Simpson's rule in matlab. However, I am asked to compare my results from a single application of Simpaon's rule with my results. I do not know how to program a single application of Simpson's rule in MATLAB or does MATLAB have a built in function? However I will attach my code below and if I set n=1 then it seems to me that it would be the same result as a single application of Simpson's rule, am I correct?

Code:
function F =P_simpson13(func,a,b,n)
%a=initial value
%b=end value
%n=number of double intervals of size 2h
 n = 2 * n;
h = (b - a) / n;
S = func(a); % S is continuing sum
 
for i = 1 : 2 : n-1 %all odd steps
    x = a + h .* i;
    S = S + 4 * func(x);
end
 
for i = 2 : 2 : n-2 %all even
    x = a + h .* i;
    S = S + 2 * func(x);
end
 
S = S + func(b);
F = h * S / 3;
 
F;
 
end
 
Physics news on Phys.org
You completed the assignment by copying the MATLAB code in the Simpson's Rule wiki virtually line by line?

I would guess that's why you don't know the answer to this question. Had you written it, you might have understood it better.
 

Similar threads

  • · Replies 3 ·
Replies
3
Views
18K
Replies
1
Views
2K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 8 ·
Replies
8
Views
3K
  • · Replies 4 ·
Replies
4
Views
3K
  • · Replies 6 ·
Replies
6
Views
2K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 5 ·
Replies
5
Views
4K
  • · Replies 8 ·
Replies
8
Views
3K