This document performs numerical integration using the composite trapezoidal rule. It takes in user input for the x-points, equation to integrate, and step size h. It then calculates the length of x-points, initializes a sum variable, and uses a for loop to calculate the value of the function at each x-point. If the index is even, it adds the function value to the running sum. It finally multiplies the sum by 2*h to give the final numerical integration value and prints the result.
This document performs numerical integration using the composite trapezoidal rule. It takes in user input for the x-points, equation to integrate, and step size h. It then calculates the length of x-points, initializes a sum variable, and uses a for loop to calculate the value of the function at each x-point. If the index is even, it adds the function value to the running sum. It finally multiplies the sum by 2*h to give the final numerical integration value and prints the result.
This document performs numerical integration using the composite trapezoidal rule. It takes in user input for the x-points, equation to integrate, and step size h. It then calculates the length of x-points, initializes a sum variable, and uses a for loop to calculate the value of the function at each x-point. If the index is even, it adds the function value to the running sum. It finally multiplies the sum by 2*h to give the final numerical integration value and prints the result.
%equation = x/(1+x) %h = 0.5 clc x = input('Enter points of X :'); a = input('Enter equation :','s'); eq=inline(a); h = input ('Enter the step size(h): ');
N = length (x); sum=0; for j=1:N if mod(j,2)==0 sum=sum+eq(x(j)); end end sum = sum*(2*h); fprintf("the sum =%.3f",sum);