Simpson's Rule in MATLAB Last Updated : 08 Aug, 2024 Summarize Comments Improve Suggest changes Share Like Article Like Report Simpson’s 1/3 rule is a numerical method used for the evaluation of definite integrals. MATLAB does not provide an in-built function to find numerical integration using Simpson's rule. However, we can find that using the below formula.The formula for numerical integration using Simpson's rule is:where, h = (b-a)/nIn Simpson's 1/3 rule, we evaluate the definite integral using integration by successive segments of the curve. It helps us to make the approximations more precise as compared to trapezoidal rule where straight lines segments were used instead of parabolic arcs.Note: For Simpson's 1/3 Rule, n must be even.Example: Evaluate ∫logx dx within limit 4 to 5.2 Matlab % MATLAB code for syms function that creates a variable % dynamically and automatically assigns % to a MATLAB variable with the same name syms x % Lower Limit a = 4; % Upper Limit b = 5.2; % Number of Segments n = 6; % Declare the function f1 = log(x); % inline creates a function of string containing in f1 f = inline(f1); % h is the segment size h = (b - a)/n; % X stores the summation of first and last segment X = f(a)+f(b); % variables Odd and Even to store % summation of odd and even % terms respectively Odd = 0; Even = 0; for i = 1:2:n-1 xi=a+(i*h); Odd=Odd+f(xi); end for i = 2:2:n-2 xi=a+(i*h); Even=Even+f(xi); end % Formula to calculate numerical integration % using Simpsons 1/3 Rule I = (h/3)*(X+4*Odd+2*Even); disp('The approximation of above integral is: '); disp(I); Output: Comment More infoAdvertise with us Next Article Simulink in MATLAB J jatan_18 Follow Improve Article Tags : Software Engineering MATLAB MATLAB-Maths Similar Reads Simpson's Rule Formula A way of finding the area of any figure is by integrating the function of that curve within the required limits which gives the area under that curve. However, there is a problem with this approach as in some cases the integral of the function can not be calculated or is difficult to find. It should 7 min read Simulink in MATLAB MATLAB which is also known as "Matrix Laboratory" allows its user to manipulate matrixes, plotting of functions and data, creation of algorithms, and user interfaces written in different programming languages by providing a computing environment. MATLAB is software designed and powered by mathworks. 4 min read How to reverse a string in MATLAB? In this article, we are going to discuss the "Reversing of a string" in MATLAB which can be done in multiple approaches that are illustrated below: Method 1: Using Built-in Functions By using MATLAB built-in functions like reverse(), flip() and fliplr(). Built-in functions can be defined as - " The 3 min read Real Life Applications of Simpsons Rules Simpson's Rule is like a helpful tool in math that helps solve real-life problems. In this article, we'll talk about how Simpson's Rule is used in the real world. From figuring out stuff in engineering and finance to understanding things in environmental science. Simpson's Rule helps us do accurate 6 min read polyfit() in MATLAB Polyfit is a function in MATLAB that fits a polynomial to a set of data points. It takes in three arguments: x: a vector of x-coordinates of the data pointsy: a vector of y-coordinates of the data pointsn: the degree of the polynomial polyfit returns a vector of coefficients representing the fitted 2 min read polyval() in MATLAB polyval is a built-in function in MATLAB that allows you to evaluate a polynomial at a specific point. It evaluates the polynomial let's p at the points in x and it returns the corresponding function values in y . The syntax for polyval is as follows: Syntax: y = polyval(p,x) %returns the value of a 2 min read Like