Trapezoidal rule is a numerical tool for the solving of definite integral. This rule based on computing the area of trapezium. Trapezoidal rule is applicable for all number of interval whether n is even or odd. The large number of interval give the best result compare than small number of interval. At here, we write the code of Trapezoidal Rule in MATLAB step by step. MATLAB is easy way to solve complicated problems that are not solve by hand or impossible to solve at page. MATLAB is develop for mathematics, therefore MATLAB is the abbreviation of MATrix LABoratory.
In this program, we evaluate the integral
[katex display=true]\int_{a}^{b}\frac{1}{1+x^2}dx[/katex]
The formula of composite trapezoidal rule is
[katex display=true]\int_{a}^{b}f(x)dx=\frac{h}{2}(f(a)+2\sum_{i=1}^{n-1}f(x_i)+f(b))[/katex]
% Numerical Analysis Trapezoidal Rule using MATLAB
clear all;
close all;
clc;
f=inline('1/(1+x^2)');
a=input('Enter lower limit of integral=');
b=input('Enter upper limit of integral=');
n=input('Enter number of intervals=');
h=(b-a)/n;
sum=0.0;
for i=1:n-1
x=a+i*h;
sum=sum+f(x);
end
trap=h*(f(a)+2*sum+f(b))/2.0;
fprintf('Evaluated Integral =%f',trap);
Other Numerical Methods with MATLAB Coding
- Bisection Method with MATLAB
- Newton Raphson Method with MATLAB
- Secant Method with MATLAB
- Regula Falsi Method with MATLAB
- Fixed Point Iteration with MATLAB
- Trapezoidal Rule with MATLAB
- Simpson 1/3 Rule with MATLAB
- Simpson 3/8 Rule with MATLAB
- Bool’s Rule with MATLAB
- Weddle’s Rule with MATLAB
- Euler Method with MATLAB
- Modified Euler Method with MATLAB
- Midpoint Method with MATLAB
- Runge-Kutta Method with MATLAB
- Millen’s Method with MATLAB
- Adams Bashforth Moulton Method with MATLAB
- Newton Forward Difference Interpolation with MATLAB
- Newton Backward Difference Interpolation with MATLAB
- Lagrange Interpolation with MATLAB
- Newton Divided Difference Interpolation with MATLAB
- Hermite Interpolation with MATLAB
- Natural Cubic Spline Interpolation with MATLAB
- Gauss Jacobi Method with MATLAB
- Gauss Seidal Method with MATLAB
- Power Method with MATLAB