First we have to know what does the program need to do.
Let's see guys.
The integral of function y = f(x) on the interval from a to b is a square of the area limited by this function, X-axis and two vertical lines
x = a and x = b.
Computer can evaluate integrals approximately. One of the most frequently used methods is the trapeze method. The interval [a; b] is separated into N equal subintervals.
That's why we should use Mat Lab.
At the begining
f = input('Typing f(x):','s');
a=input('Typing Less a: ');
b=input('Typing Up b: ');
n=input('Typing Number n ');
You can evaluate integrals of any functions using Tavrida Calculator. You simply enter a function (for example, x^2 - x + 1) in one of the cells, select the Integrate cell option, enter the limits of integration (for example, a = -10, b = 10), the number of intervals (for example, N = 10) and get the result (S = 700 in this case).
For the error is very simple.
fprintf ('Here is the ERROR')
f = input('Typing f(x) again:','s');
div = diff(f,2)
This is not a method that we typically use in practice. Its usefulness is to introduce the subject and provide a general framework for this area of numerical methods.
Using the Euler-Maclaurin formula, the integral of f(x) dx on the interval a to be can be expressed as (note that the concept of expansions is a common technique in mathematics)
where B2n are Bernoulli numbers.
We observe that, if the interval of integration is small enough, the series in the second term above would yield a contribution that is negligible compared to the first term. This is a standard technique in deriving relationships in numerical methods.
As a result the integral of f(x)dx on the interval a to b is approximately equal to the following if b - a is sufficiently small
Note that the above expression is the area of a trapezoid where b - a is the base and f(a) and f(b) are the lengths of the two vertical parallel sides.
Next, recall the additive formula between integrals