SONNYX

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

function f

f = input('Typing f(x):','s');

a=input('Typing Less a: ');

x=a

f_a=eval(f)

b=input('Typing Up b: ');

x=b

f_b=eval(f)

n=input('Typing Number n ');

h=(b-a)/n

starting=a+h

adding=0

Now,

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 i=1:n-1

x=starting;

xi=eval(f)

adding=adding+x_i;

next_X=starting+h;

starting=next_X

end

adding

ending=(h/2)*(f_a+adding+f_b)

x=linspace(a,b);

z=eval(f);

plot(x,z)

For the error is very simple.

fprintf ('Here is the ERROR')

f = input('Typing f(x) again:','s');

div = diff(f,2)

integral_method=int(f,a,b)

new_f=int((div)/(b-a),a,b)

error=((-new_f)/12)*(b-a)^3

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