Simpson's Method for Computing Relative Error of x

Click For Summary
SUMMARY

The discussion focuses on using Simpson's Method to compute the relative error of a function x within 0.1%. The provided MATLAB code outlines the implementation of the composite Simpson rule for numerical integration. To achieve an accurate error estimate, the integration should be performed with two different step sizes, h and h/2, and the relative difference between the two results should be calculated. This approach ensures that the desired precision is met effectively.

PREREQUISITES
  • Understanding of numerical integration techniques, specifically Simpson's Method.
  • Familiarity with MATLAB programming, particularly function definitions and loops.
  • Knowledge of relative error calculation in numerical methods.
  • Basic understanding of function approximation and integration concepts.
NEXT STEPS
  • Research "MATLAB function handles" to improve code modularity.
  • Learn about "error analysis in numerical methods" to enhance accuracy in computations.
  • Explore "adaptive quadrature methods" for more efficient integration techniques.
  • Investigate "MATLAB's built-in numerical integration functions" for comparison with custom implementations.
USEFUL FOR

Mathematicians, engineers, and students involved in numerical analysis or computational mathematics who are looking to implement and optimize numerical integration techniques in MATLAB.

chronicals
Messages
35
Reaction score
0
I want to compute x within 0.1% relative error with Simpson method, these are my m-files. Which command i should add for this?

Matlab:
function simps(a, b, n)
%simps(a, b, n) approximates the integral of a function f(x) in the
%interval [a;b] by the composite simpson rule
%n is the number of subintervals

h = (b-a)/n;

sum_even = 0;

for i = 1:n/2-1
x(i) = a + 2*i*h;
sum_even = sum_even + f(x(i));
end

sum_odd = 0;

for i = 1:n/2
x(i) = a + (2*i-1)*h;
sum_odd = sum_odd + f(x(i));
end

integral = h*(f(a)+ 2*sum_even + 4*sum_odd +f(b))/3function y = f(x)
y=1/x;
 
Last edited by a moderator:
Physics news on Phys.org
The best way to get an error estimate is to do the integration with two different values of the step (say h and h/2) and use the relative difference between the two results.
 

Similar threads

  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 4 ·
Replies
4
Views
4K
  • · Replies 1 ·
Replies
1
Views
10K
  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 1 ·
Replies
1
Views
3K
Replies
6
Views
2K