Simpson's Method for Computing Relative Error of x

In summary, the conversation is about using the Simpson method to compute x within 0.1% relative error. The person is asking which command to add for this in their m-files. The suggested approach is to use two different values of the step and calculate the relative difference between the results to get an error estimate.
  • #1
chronicals
36
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
  • #2
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.
 

What is Simpson's Method for Computing Relative Error of x?

Simpson's Method for Computing Relative Error of x is a mathematical formula used to calculate the difference between the actual value of x and the estimated value of x, expressed as a percentage of the actual value.

How is Simpson's Method for Computing Relative Error of x used in scientific research?

Simpson's Method for Computing Relative Error of x is commonly used in scientific research to determine the accuracy and precision of experimental data. It allows researchers to compare their results to the true value of a measurement and assess the reliability of their methods.

What are the advantages of using Simpson's Method for Computing Relative Error of x?

One of the main advantages of Simpson's Method for Computing Relative Error of x is that it takes into account both the magnitude and direction of the error, providing a more comprehensive measure of accuracy than other error calculation methods. It also allows for easy comparison between different data sets.

What are the limitations of Simpson's Method for Computing Relative Error of x?

Simpson's Method for Computing Relative Error of x assumes that the estimated value of x is close to the actual value, and therefore may not be suitable for large errors. It also only considers one variable at a time and does not account for errors caused by multiple factors.

Are there any alternative methods for calculating relative error?

Yes, there are other methods for calculating relative error such as the Mean Absolute Percentage Error (MAPE) and the Root Mean Square Error (RMSE). Each method may be more suitable for different types of data and research purposes. It is important for scientists to carefully consider the best method to use for their specific study.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
3
Views
805
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
216
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
3K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
930
Replies
6
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
13
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
992
  • Calculus
Replies
13
Views
1K
Back
Top