BASIC Programming/Normative BASIC/Minimal BASIC

From testwiki
Revision as of 02:37, 28 October 2024 by imported>SHB2000 (Protected "BASIC Programming/Normative BASIC/Minimal BASIC": Counter-productive edit warring ([Edit=Allow only autoconfirmed users] (expires 01:37, 11 November 2024 (UTC)) [Move=Allow only autoconfirmed users] (expires 01:37, 11 November 2024 (UTC))))
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Sample Programs

Sample programs for Minimal BASIC will appear here.

Numerical Integration

Introduction

There exists two cases, when the computation of the value of a definite integral by numerical methods is needed. One of them is the calculation of the area below the curve defined by a set of experimental data, and another is the calculation of the definite integral of a mathematical function, for which no known integral is known. The former is often the case of response functions in the experimental labors of science and engineering, while the latter is normally the case in the practical investigations of physics, mathematics, and engineering.

Independently of it, the development of numerical methods for integration purposes, a field that belongs to the department of applied mathematics, is based on the simple idea from which it stems, i.e., if y(x)=f(x) is a real-valued (the complex-valued case can be treated analogously, by separating it into its real and imaginary parts) continuous function of x defined in an interval (a,b), its definite integral,

abf(x)dx=x=ax=blimδx0f(x)δx=limδx0x=ax=bf(x)δxx=ax=bf(x)Δx,

can be calculated approximately as the finite sum of the product f(x)Δx evaluated at some given points in the interval (a,b).

In the case of experimental data, the set of points at which the value of the function is measured is usually not regularly distributed (i.e., the points are not equispaced), so the value of the definite integral must be calculated in the form:

abf(x)dx=x0=ax1f(x)dx+x1x2f(x)dx+...+xn2xn1f(x)dx+xn1xn=bf(x)dx,

which can be approximated either as:

abf(x)dxf(x0=a)(x1x0)+f(x1)(x2x1)+...+f(xn2)(xn1xn2)+f(xn1)(xnxn1),

or as:

abf(x)dxf(x1)(x1x0)+f(x2)(x2x1)+...+f(xn1)(xn1xn2)+f(xn=b)(xnxn1).

In the first case, the value of the integral is underestimated (overestimated) in the case of monotonically ascending (descending) functions, since the value of f(x) taken in each evaluation is always the lowest (highest) in every subinterval, and hence constituting an absolute lower (upper) bound to the value of the integral, while in the second case, the value of the integral is overestimated (underestimated) in the case of monotonically descending (ascending) functions, since the value of f(x) taken in each evaluation is always the highest (lowest) in every subinterval, and hence constituting an absolute upper (lower) bound to the value of the integral.

According to the Mean-Value Theorem of Calculus, the value of a definite integral can also be calculated as:

abf(x)dx=f(γ)(ba),

for some value γ in (a,b) for which f(γ) represents the mean value of f(x) in (a,b), so it is then a better approximation to calculate the definite integral of a set of experimental data as:

abf(x)dx=x0=ax1f(x)dx+x1x2f(x)dx+...+xn2xn1f(x)dx+xn1xn=bf(x)dx,

abf(x)dx=f(γ(0,1))(x1x0)+f(γ(1,2))(x2x1)+...+f(γ(n2,n1))(xn1xn2)+f(γ(n1,n))(xnxn1),

abf(x)dxf(x0)+f(x1)2(x1x0)+f(x1)+f(x2)2(x2x1)+...+f(xn2)+f(xn1)2(xn1xn2)+f(xn1)+f(xn)2(xnxn1).

For reasons that we shall see later, this is equal to assume a piecewise linear interpolating function between the different points, and the value of the integral so calculated is exact for linear functions (i.e., functions for which its slope changes at constant rate), although it is underestimated for functions for which its slope grows at non-constant rate (i.e., its second derivative is strictly positive in the considered interval), and it is overestimated for functions for which its slope decreases at non-constant rate (i.e., its second derivative is strictly negative in the considered interval). The value so calculated constitutes a better approximation than the lower and upper bounds presented before, and in the case that the second derivative of the function (which can be calculated from the experimental data with the help of second or central differences) changes signs between subintervals, the value is expected to be close to the actual value due to the cancellation of the errors in the approximation of the mean values.

In the case of mathematical functions, there is more information about the function, since it is possible not only to calculate the value of the function at any given point, but also to compute first, second, and higher-order derivatives with any degree of accuracy.

Let us elaborate some mathematical results, going from simple to more elaborate methods:

The main theme in the development of numerical methods, together with the study of the stability (i.e., if a method converges), is the rate of convergence of the method, which studies how many evaluations are needed and the error in the approximation, for non-iterative methods, or how many iterations are needed and how the error is minimized in each iteration, for iterative methods.

In the case of the study of the stability, and as we have seen before, the value of the definite integral of a function f(x) defined in an interval (a,b),

abf(x)dx=x=ax=blimδx0f(x)δx=limδx0x=ax=bf(x)δxx=ax=bf(xk)Δxk,

can be calculated approximately as the finite sum of the product f(x)Δx evaluated at some given points in the interval (a,b).

In the limit Δxδx0, the finite sum tends to the infinite integral, and so convergence is assured.

In the case of the study of the rate of convergence, one is interested in increasing the accuracy of the approximation, while retaining the number of subintervals, with a minor increase in computational complexity.

The approach used consists normally in using a polynomial approximation for the evaluation of the function f(x) in each subinterval, using the information provided by the value of the function at several points in the subinterval.

Let us consider the case of equally-spaced points (although this restriction can be easily lifted):

According to the definition,

abf(x)dx=x=ax=blimδx0f(x)δx=limδx0x=ax=bf(x)δxx=ax=bf(xk)Δxk=x=ax=bf(xk)(xj+1xj),

with k being indicative of the subinterval, xk being some arbitrary number in every subinterval (xj,xj+1), with j=0,1,2,...,n1, and x0=a,xn=b, and Δxk=(xj+1xj), with k=1,2,...,n, and j=k1.

The Mean-Value Theorem of Calculus tells us, that if

abf(x)dx

is the definite integral of f(x) in (a,b), there exists a value γ in (a,b), such that

abf(x)dx=f(γ)(ba).

Additionally, by definition, if

abf(x)dx

is the definite integral of f(x) in (a,b), this one can also be understood as being composed of the individual contributions

abf(x)dx=x0=ax1f(x)dx+x1x2f(x)dx+...+xn2xn1f(x)dx+xn1xn=bf(x)dx

for arbitrary values x0=a,x1,x2,...,xn2,xn1,xn=b.

Now, applying the Mean-Value Theorem to each individual contribution yields the result:

abf(x)dx=f(γ(x0,x1))(x1x0)+f(γ(x1,x2))(x2x1)+...+f(γ(xn2,xn1))(xn1xn2)+f(γ(xn1,xn))(xnxn1),

which is exact.

In the particular case that every subinterval is of equal size, i.e., (x1x0)=(x2x1)=...=(xn1xn2)=(xnxn1)=Δx, then the expression reduces to

abf(x)dx=(f(γ(x0,x1))+f(γ(x1,x2))+...+f(γ(xn2,xn1))+f(γ(xn1,xn)))Δx.

In this way, the calculation of the initial definite integral reduces to the calculation of the mean values

f(γ(x0,x1)),f(γ(x1,x2)),...,f(γ(xn2,xn1)),f(γ(xn1,xn)).

In a first approximation, with only one point,

f(γ(x0,x1))f(xi(x0,x1)),f(γ(x1,x2))f(xi(x1,x2)),...,f(γ(xn2,xn1))f(xi(xn2,xn1)),f(γ(xn1,xn))f(xi(xn1,xn)),

with xi being the value of x in the middle of each subinterval, which leads to

abf(x)dx(f(xi(x0,x1))+f(xi(x1,x2))+...+f(xi(xn2,xn1))+f(xi(xn1,xn)))Δx.

In a second approximation, with only two points,

f(γ(x0,x1))f(x0)+f(x1)2,f(γ(x1,x2))f(x1)+f(x2)2,...,f(γ(xn2,xn1))f(xn2)+f(xn1)2,f(γ(xn1,xn))f(xn1)+f(xn)2,

with xn1,xn being the value of x at the beginning and at the end of each subinterval, which leads to

abf(x)dx(f(x0)+2f(x1)+...+2f(xn1)+f(xn))Δx/2.

In a third approximation, with only three points,

f(γ(x0,x1))f(x0)+f(xi(x0,x1))+f(x1)3,f(γ(x1,x2))f(x1)+f(xi(x1,x2))+f(x2)3,...,f(γ(xn2,xn1))f(xn2)+f(xi(xn2,xn1))+f(xn1)3,f(γ(xn1,xn))f(xn1)+f(xi(xn1,xn))+f(xn)3,

with xn1,xi,xn being the value of x at the beginning, in the middle, and at the end of each subinterval, which leads to

abf(x)dx(f(x0)+f(xi(x0,x1))+2f(x1)+f(xi(x1,x2))+2f(x2)+...+2f(xn2)+f(xi(xn2,xn1))+2f(xn1)+f(xi(xn1,xn))+f(xn))Δx/3.

In a fourth approximation, while still making use of the evaluation of the function f(x) at the beginning, in the middle, and at the end of each subinterval, one can use the result that if f(γ) and f(γ+) are estimates for f(γ), then its arithmetic mean (f(γ)+f(γ+))/2 is also another estimate with at least the same accuracy, if not better.

So, adding the results for the first and second approximation, and dividing by two,

f(γ(xn1,xn))f(xi(xn1,xn))+f(xn1)+f(xn)22=f(xn1)+2f(xi(xn1,xn))+f(xn)4,

which leads to the result

abf(x)dx(f(x0)+2f(xi(x0,x1))+2f(x1)+2f(xi(x1,x2))+2f(x2)+...+2f(xn2)+2f(xi(xn2,xn1))+2f(xn1)+2f(xi(xn1,xn))+f(xn))Δx/4.

Adding the results for the first and third approximation, and dividing by two,

f(γ(xn1,xn))f(xi(xn1,xn))+f(xn1)+f(xi(xn1,xn))+f(xn)32=f(xn1)+4f(xi(xn1,xn))+f(xn)6,

which leads to the result

abf(x)dx(f(x0)+4f(xi(x0,x1))+2f(x1)+4f(xi(x1,x2))+2f(x2)+...+2f(xn2)+4f(xi(xn2,xn1))+2f(xn1)+4f(xi(xn1,xn))+f(xn))Δx/6.

In practice, one can do no better with only three evaluations in an interval, but the results obtained are simple and accurate enough, even in the case of one single interval.

Let us illustrate the case by means of an example:

Let us suppose, that we wish to calculate the definite integral of the function f(x)=exp(x) in the interval (0,1), for which we know its exact value, F(x)|01=01exp(x)dx=exp(x)|01=exp(1)exp(0)=2.718281.00000=1.71828.

Let us also keep the problem simple and do the calculations with a single interval, i.e., x0=a=0.0, xn=b=1.0, and xi=0.5.

So, we have:

First approximation:

abf(x)dxf(xi)(ba)=exp(0.5)(1.00.0)=1.64872

This is equal to a relative error of

error=1.648721.718281.71828×100=4.04823%.

Second approximation:

abf(x)dxf(xa)+f(xb)2(ba)=exp(0.0)+exp(1.0)2(1.00.0)=1.85914

This is equal to a relative error of

error=1.859141.718281.71828×100=+8.19774%.

Third approximation:

abf(x)dxf(xa)+f(xi)+f(xb)3(ba)=exp(0.0)+exp(0.5)+exp(1.0)3(1.00.0)=1.78900

This is equal to a relative error of

error=1.859141.718281.71828×100=+4.11575%.

Fourth approximation, first and second terms (linear expansion):

abf(x)dxf(xa)+2f(xi)+f(xb)4(ba)=exp(0.0)+2×exp(0.5)+exp(1.0)4(1.00.0)=1.75393

This is equal to a relative error of

error=1.753931.718281.71828×100=+2.07475%.

Fourth approximation, first and third terms (quadratic expansion):

abf(x)dxf(xa)+4f(xi)+f(xb)6(ba)=exp(0.0)+4×exp(0.5)+exp(1.0)6(1.00.0)=1.71886

This is equal to a relative error of

error=1.718861.718281.71828×100=+0.0337589%.

In case more accuracy is needed, one can analogously introduce higher-order terms in the expansion of f(x) around xi, or half the integration step in one of the methods considered before.

Let us consider the case, when higher-order terms are considered in the expansion, i.e.,

f(γ(xn1,xn))f(xi(xn1,xn))+f(xn1)+f(xi1/4)+f(xi(xn1,xn))+f(xi3/4)+f(xn)52=f(xn1)+f(xi1/4)+6f(xi(xn1,xn))+f(xi3/4)+f(xn)10,

which leads to the result

abf(x)dx(f(x0)+f(x1/4(x0,x1))+6f(xi(x1,x2))+f(x3/4(x0,x1))+2f(x1)+...+2f(xn1)+f(x1/4(xn1,xn))+6f(xi(xn1,xn))+f(x1/4(xn1,xn))+f(xn))Δx/10.

Let us illustrate the case by means of an example:

Let us suppose, that we wish to calculate the definite integral of the function f(x)=exp(x) in the interval (0,1), for which we know its exact value, F(x)|01=01exp(x)dx=exp(x)|01=exp(1)exp(0)=2.718281.00000=1.71828.

Let us also keep the problem simple and do the calculations with two intervals, i.e., x0=a=0.0, xn=b=1.0, x1=0.5, xi(x0,x1)=0.25 and xi(x1,x2)=0.25.

Applying second order expansion

abf(x)dx(f(x0)+4f(xi(x0,x1))+2f(x1)+4f(xi(x1,x2))+f(x2))Δx/6,

which yields

abf(x)dx(exp(0.0)+4exp(0.25)+2exp(0.5)+4exp(0.75)+exp(1.0))×0.5/6=1.71832,

which is equal to a relative error of

error=1.718321.718281.71828×100=+0.00216456%.

Applying fourth order expansion

abf(x)dx(f(0.0)+f(0.25)+6f(0.50)+f(0.75)+f(1.0))1.0/10,

which yields

abf(x)dx(exp(0.0)+7exp(0.25)+2exp(0.5)+7exp(0.75)+exp(1.0))×1.0/10.

We know from the Calculus of Differences, that any function can be expressed as the polynomial expansion

f(x)=f(x0)+f(x1)f(x0)x1x0(xx0)+f(x1)2f(xi)+f(x0)(x1x0)2(xx0)2+...

in the case of forward differences, or

f(x)=f(x1)+f(x1)f(x0)x1x0(xx1)+f(x1)2f(xi)+f(x0)(x1x0)2(xx1)2+...

in the case of backward differences, or

f(x)=f(xi)+f(x1)f(x0)x1x0(xxi)+f(x1)2f(xi)+f(x0)(x1x0)2(xxi)2+...

in the case of central differences.

In a first approximation,

abf(x)dx=ab(f(x0)+h(x0)(xx0))dxabf(x0)dx=f(x0)(ba)=f(x0)(x1x0)=f(x0)Δx

abh(x0)(xx0)dx=h(x0)(xx0)22|ab=h(x0)(bx0)2(ax0)22=h(x0)(x1x0)2(x0x0)22=h(x0)(x1x0)22=h(x0)Δx22f(x0)Δx22

in the case of forward differences,

abf(x)dx=ab(f(x1)+h(x1)(xx1))dxabf(x1)dx=f(x1)(ba)=f(x1)(x1x0)=f(x1)Δx

abh(x1)(xx1)dx=h(x1)(xx1)22|ab=h(x1)(bx1)2(ax1)22=h(x1)(x1x1)2(x0x1)22=h(x1)(x0x1)22=h(x1)Δx22f(x1)Δx22

in the case of backward differences,

abf(x)dx=ab(f(xi)+h(xi)(xxi))dxabf(xi)dx=f(xi)(ba)=f(xi)(x1x0)=f(xi)Δx

abh(xi)(xxi)dx=h(xi)(xxi)22|ab=h(xi)(bxi)2(axi)22=h(xi)(x1xi)2(x0xi)22=h(xi)(Δx/2)2(Δx/2)22=h(xi)Δx2Δx24=0

in the case of central differences.

So, in the case of evaluating the integral with one single point, the value of it is always underestimated (overestimated) with forward (backward) differences if the value of the slope of the function at the evaluation point is positive, and underestimated (overestimated) with forward (backward) differences if the value of the slope of the function at the evaluation point is negative, being the error in the estimation directly proportional to the slope of the function at the evaluation point, and to one half of the square of the integration step. In the case of evaluating the integral with central differences, the value is exact for linear functions.

In a second approximation,

abf(x)dx=ab(f(x0)+f(x1)f(x0)x1x0(xx0)+h(x0)(xx0)2)dx

abf(x)dxab(f(x0)+f(x1)f(x0)x1x0(xx0))dx=f(x0)(x1x0)+f(x1)f(x0)x1x0(x1x0)2(x0x0)22

abf(x)dxf(x0)(x1x0)+f(x1)f(x0)x1x0(x1x0)22=f(x0)(x1x0)+f(x1)f(x0)2(x1x0)=f(x1)+f(x0)2(x1x0)=f(x1)+f(x0)2Δx

abh(x0)(xx0)2dx=h(x0)(xx0)33|ab=h(x0)(x1x0)3(x0x0)33=h(x0)(x1x0)33=h(x0)Δx33f(x0)Δx33

in the case of forward differences,

abf(x)dx=ab(f(x1)+f(x1)f(x0)x1x0(xx1)+h(x1)(xx1)2)dx

abf(x)dxab(f(x1)+f(x1)f(x0)x1x0(xx1))dx=f(x1)(x1x0)+f(x1)f(x0)x1x0(x1x1)2(x0x1)22

abf(x)dxf(x1)(x1x0)f(x1)f(x0)x1x0(x1x0)22=f(x1)(x1x0)f(x1)f(x0)2(x1x0)=f(x1)+f(x0)2(x1x0)=f(x1)+f(x0)2Δx

abh(x1)(xx1)2dx=h(x1)(xx1)33|ab=h(x1)(x1x1)3(x0x1)33=h(x1)(x1x0)33=h(x1)Δx33f(x1)Δx33

in the case of backward differences,

abf(x)dx=ab(f(xi)+f(x1)f(x0)x1x0(xxi)+h(xi)(xxi)2)dx

abf(x)dxab(f(xi)+f(x1)f(x0)x1x0(xxi))dx=f(xi)(x1x0)+f(x1)f(x0)x1x0(x1xi)2(x0xi)22

abf(x)dxf(xi)(x1x0)+f(x1)f(x0)x1x0(x1xi)2(xix0)22=f(xi)(x1x0)+f(x1)f(x0)x1x0(x1x0)2(x1x0)28=f(xi)(x1x0)=f(xi)Δx

abh(xi)(xxi)2dx=h(xi)(xxi)33|ab=h(xi)(x1xi)3(x0xi)33=h(xi)(x1xi)3+(xix0)33=h(xi)(x1x0)312=h(xi)Δx312f(xi)Δx312

in the case of central differences.

So, in the case of evaluating the integral with a linear function, there is no difference between forward and backward differences, and the value of the integral is equal to the product of the mean of the values of the function at the beginning and at the end of the interval times the integration step, being the value so calculated underestimated (overestimated) for monotonically increasing (decreasing) functions with a positive (negative) second derivative, the error in the approximation being directly proportional to the second derivative of the function and to the cube of the integration step (i.e., as one increases the number of subintervals, one reduces the deviation proportional to the cube of the number of subintervals). In the case of central differences, the value of the integral is equal to the product of the value of the function in the middle of the interval times the integration step, as in the previous case, the error in the approximation being reduced by a factor of four with relation to the case of forward and backward differences.

In a third approximation,

abf(x)dx=ab(f(x0)+f(x1)f(x0)x1x0(xx0)+f(x1)2f(xi)+f(x0)(x1x0)2(xx0)2+h(x0)(xx0)3)dx

abf(x)dxab(f(x0)+f(x1)f(x0)x1x0(xx0)+f(x1)2f(xi)+f(x0)(x1x0)2(xx0)2)dx

abf(x)dxf(x1)+f(x0)2(x1x0)+f(x1)2f(xi)+f(x0)(x1x0)2(x1x0)3(x0x0)33

abf(x)dxf(x1)+f(x0)2(x1x0)+f(x1)2f(xi)+f(x0)(x1x0)2(x1x0)33

abf(x)dxf(x1)+f(x0)2(x1x0)+f(x1)2f(xi)+f(x0)3(x1x0)

abf(x)dx3f(x1)+3f(x0)+2f(x1)4f(xi)+2f(x0)6(x1x0)

abf(x)dx5f(x0)4f(xi)+5f(x1)6(x1x0)

abh(x0)(xx0)3dx=h(x0)(xx0)44|ab=h(x0)(x1x0)4(x0x0)44=h(x0)(x1x0)44=h(x0)Δx44f(x0)Δx44

in the case of forward differences,

abf(x)dx=ab(f(x1)+f(x1)f(x0)x1x0(xx1)+f(x1)2f(xi)+f(x0)(x1x0)2(xx1)2+h(x1)(xx1)3)dx

abf(x)dxab(f(x1)+f(x1)f(x0)x1x0(xx1)+f(x1)2f(xi)+f(x0)(x1x0)2(xx1)2)dx

abf(x)dxf(x1)+f(x0)2(x1x0)+f(x1)2f(xi)+f(x0)(x1x0)2(x1x1)3(x0x1)33

abf(x)dxf(x1)+f(x0)2(x1x0)f(x1)2f(xi)+f(x0)(x1x0)2(x1x0)33

abf(x)dxf(x1)+f(x0)2(x1x0)f(x1)2f(xi)+f(x0)3(x1x0)

abf(x)dx3f(x1)+3f(x0)2f(x1)+4f(xi)2f(x0)6(x1x0)

abf(x)dxf(x0)+4f(xi)+f(x1)6(x1x0)

abh(x1)(xx1)3dx=h(x1)(xx1)44|ab=h(x1)(x1x1)4(x0x1)44=h(x1)(x1x0)44=h(x1)Δx44f(x1)Δx44

in the case of backward differences,

abf(x)dx=ab(f(xi)+f(x1)f(x0)x1x0(xxi)+f(x1)2f(xi)+f(x0)(x1x0)2(xxi)2+h(xi)(xxi)3)dx

abf(x)dxab(f(xi)+f(x1)f(x0)x1x0(xxi)+f(x1)2f(xi)+f(x0)(x1x0)2(xxi)2)dx

abf(x)dxf(xi)(x1x0)+f(x1)2f(xi)+f(x0)(x1x0)2(x1xi)3(x0xi)33

abf(x)dxf(xi)(x1x0)+f(x1)2f(xi)+f(x0)(x1x0)2(x1x0)312

abf(x)dxf(xi)(x1x0)+f(x1)2f(xi)+f(x0)12(x1x0)

abf(x)dx12f(xi)+f(x1)2f(xi)+f(x0)12(x1x0)

abf(x)dxf(x1)+10f(xi)+f(x0)12(x1x0)

abh(xi)(xxi)3dx=h(xi)(xxi)44|ab=h(xi)(x1xi)4(x0xi)44=h(xi)(x1x0)4(x1x0)464=0

in the case of central differences.

In a fourth approximation,

abf(x)dx=ab(f(x0)+f(x1)f(x0)x1x0(xx0)+f(x1)2f(xi)+f(x0)(x1x0)2(xx0)2+f(x1)f(xi)x1xif(xi)f(x0)xix0(x1x0)2(xx0)3+h(x0)(xx0)3)dx

abf(x)dxab(f(x0)+f(x1)f(x0)x1x0(xx0)+f(x1)2f(xi)+f(x0)(x1x0)2(xx0)2)dx

abf(x)dxf(x1)+f(x0)2(x1x0)+f(x1)2f(xi)+f(x0)(x1x0)2(x1x0)3(x0x0)33

abf(x)dxf(x1)+f(x0)2(x1x0)+f(x1)2f(xi)+f(x0)(x1x0)2(x1x0)33

abf(x)dxf(x1)+f(x0)2(x1x0)+f(x1)2f(xi)+f(x0)3(x1x0)

abf(x)dx3f(x1)+3f(x0)+2f(x1)4f(xi)+2f(x0)6(x1x0)

abf(x)dx5f(x0)4f(xi)+5f(x1)6(x1x0)

abh(x0)(xx0)3dx=h(x0)(xx0)44|ab=h(x0)(x1x0)4(x0x0)44=h(x0)(x1x0)44=h(x0)Δx44f(x0)Δx44

in the case of forward differences,

abf(x)dx=ab(f(x1)+f(x1)f(x0)x1x0(xx1)+f(x1)2f(xi)+f(x0)(x1x0)2(xx1)2+h(x1)(xx1)3)dx

abf(x)dxab(f(x1)+f(x1)f(x0)x1x0(xx1)+f(x1)2f(xi)+f(x0)(x1x0)2(xx1)2)dx

abf(x)dxf(x1)+f(x0)2(x1x0)+f(x1)2f(xi)+f(x0)(x1x0)2(x1x1)3(x0x1)33

abf(x)dxf(x1)+f(x0)2(x1x0)f(x1)2f(xi)+f(x0)(x1x0)2(x1x0)33

abf(x)dxf(x1)+f(x0)2(x1x0)f(x1)2f(xi)+f(x0)3(x1x0)

abf(x)dx3f(x1)+3f(x0)2f(x1)+4f(xi)2f(x0)6(x1x0)

abf(x)dxf(x0)+4f(xi)+f(x1)6(x1x0)

abh(x1)(xx1)3dx=h(x1)(xx1)44|ab=h(x1)(x1x1)4(x0x1)44=h(x1)(x1x0)44=h(x1)Δx44f(x1)Δx44

in the case of backward differences,

abf(x)dx=ab(f(xi)+f(x1)f(x0)x1x0(xxi)+f(x1)2f(xi)+f(x0)(x1x0)2(xxi)2+h(xi)(xxi)3)dx

abf(x)dxab(f(xi)+f(x1)f(x0)x1x0(xxi)+f(x1)2f(xi)+f(x0)(x1x0)2(xxi)2)dx

abf(x)dxf(xi)(x1x0)+f(x1)2f(xi)+f(x0)(x1x0)2(x1xi)3(x0xi)33

abf(x)dxf(xi)(x1x0)+f(x1)2f(xi)+f(x0)(x1x0)2(x1x0)312

abf(x)dxf(xi)(x1x0)+f(x1)2f(xi)+f(x0)12(x1x0)

abf(x)dx12f(xi)+f(x1)2f(xi)+f(x0)12(x1x0)

abf(x)dxf(x1)+10f(xi)+f(x0)12(x1x0)

abh(xi)(xxi)3dx=h(xi)(xxi)44|ab=h(xi)(x1xi)4(x0xi)44=h(xi)(x1x0)4(x1x0)464=0

in the case of central differences.

The divided differences are:

df(x)dxf(x1)f(x0)x1x0

d2f(x)dx2f(x1)f(xi)x1xif(xi)f(x0)xix0x1x0=2(f(x1)2f(xi)+f(x0))(x1x0)2

d3f(x)dx3f(x1)f((x1+xi)/2)x1x04f((x1+xi)/2)f(xi)x1x04x1x02f(xi)f((xi+x0)/2)x1x04f((xi+x0)/2)f(x0)x1x04x1x02x1x0=8(f(x1)2f((x1+xi)/2)+2f((xi+x0)/2)f(x0))(x1x0)3

d4f(x)dx4f(x1)f((x1+xi)/4)x1x08f(x1)f((x1+xi)/4)x1x08x1x04f((x1+xi)/2)f(xi)x1x04x1x02f(xi)f((xi+x0)/2)x1x04f((xi+x0)/2)f(x0)x1x04x1x02x1x0=8(f(x1)2f((x1+xi)/2)+2f((xi+x0)/2)f(x0))(x1x0)3

Lagrange interpolation

One point:

L1(x0,x1)=f(x0+x12)=f(xi)

Two points:

L2(x0,x1)=f(x0)(x0x1)(xx1)+f(x1)(x1x0)(xx0)

Three points:

L3(x0,x1)=f(x0)(x0xi)(x0x1)(xxi)(xx1)+f(xi)(xix0)(xix1)(xx0)(xx1)+f(x1)(x1x0)(x1xi)(xx0)(xxi)

Four points:

L4(x0,x1)=f(x0)(x0xi)(x0x1)(xxi)(xx1)+f(xi)(xix0)(xix1)(xx0)(xx1)+f(x1)(x1xi)(x1x0)(xxi)(xx0)

Five points:

L5(x0,x1)=f(x0)(x0xi)(x0x1)(xxi)(xx1)+f(xi)(xix0)(xix1)(xx0)(xx1)+f(x1)(x1xi)(x1x0)(xxi)(xx0)

Six points:

L6(x0,x1)=f(x0)(x0xi)(x0x1)(xxi)(xx1)+f(xi)(xix0)(xix1)(xx0)(xx1)+f(x1)(x1xi)(x1x0)(xxi)(xx0)

Seven points:

L7(x0,x1)=f(x0)(x0xi)(x0x1)(xxi)(xx1)+f(xi)(xix0)(xix1)(xx0)(xx1)+f(x1)(x1xi)(x1x0)(xxi)(xx0)

One point:

abf(x)dx=ab(L1(x)+h1(x))dx=ab(f(xi)+1h1(xxi))dx

abf(x)dx=f(xi)(x1x0)+h1(x1xi)2(x0xi)22

abf(x)dx=f(xi)(x1x0)

abf(x)dx=f(xi)Δx

Two points:

abf(x)dx=ab(L2(x)+h2(x))dx=ab(f(x0)(x0x1)(xx1)+f(x1)(x1x0)(xx0)+2h2(xxi)2)dx

abf(x)dx=f(x0)(x0x1)(x1x1)2(x0x1)22+f(x1)(x1x0)(x1x0)2(x0x0)22+2h2(x1xi)3(x0xi)33

abf(x)dx=f(x0)(x0x1)(x0x1)22+f(x1)(x1x0)(x1x0)22+2h2(x1x0)3(x0x1)324

abf(x)dx=f(x0)2(x0x1)+f(x1)2(x1x0)+2h2(x1x0)3+(x1x0)324

abf(x)dx=f(x0)2(x1x0)+f(x1)2(x1x0)+4h2(x1x0)324

abf(x)dx=f(x0)+f(x1)2(x1x0)+h2(x1x0)36

abf(x)dx=f(x0)+f(x1)2Δx+h2Δx36

abf(x)dx=(f(x0)+f(x1))Δx2+h2Δx36


Three points:

abf(x)dx=ab(L3(x)+h3(x))dx=ab(L3,1(x)+L3,2(x)+L3,3(x)+h3(x))dx

abf(x)dx=ab(f(x0)(x0xi)(x0x1)(xxi)(xx1))dx+ab(f(xi)(xix0)(xix1)(xx0)(xx1))dx+ab(f(x1)(x1x0)(x1xi)(xx0)(xxi))dx+abh3(x)(xxi)3dx

abf(x)dx=ab(f(x0)(x0xi)(x0x1)(x2xxixx1+xix1))dx+ab(f(xi)(xix0)(xix1)(x2xx0xx1+x0x1))dx+ab(f(x1)(x1x0)(x1xi)(x2xx0xxi+x0xi))dx+abh3(x)(xxi)3dx

abf(x)dx=ab(f(x0)(x0xi)(x0x1)(x2(xi+x1)x+xix1))dx+ab(f(xi)(xix0)(xix1)(x2(x0+x1)x+x0x1))dx+ab(f(x1)(x1x0)(x1xi)(x2(x0+xi)x+x0xi))dx+abh3(x)(xxi)3dx

abf(x)dx=f(x0)(x0xi)(x0x1)(x13x033(xi+x1)x12x022+xix1(x1x0))+f(xi)(xix0)(xix1)(x13x033(x0+x1)x12x022+x0x1(x1x0))+f(x1)(x1x0)(x1xi)(x13x033(x0+xi)x12x022+x0xi(x1x0))+h3(x1xi)4(x0xi)44

abf(x)dx=2f(x0)(x0x1)(x0x1)(x13x033(x0+x12+x1)x12x022+x0+x12x1(x1x0))+4f(xi)(x1x0)(x0x1)(x13x033(x0+x1)x12x022+x0x1(x1x0))+2f(x1)(x1x0)(x1x0)(x13x033(x0+x0+x12)x12x022+x0x0+x12(x1x0))+h3(x1xi)4(x0xi)44

abf(x)dx=2f(x0)(x0x1)(x0x1)(x13x033x0+3x12x12x022+x12x022x1)+4f(xi)(x1x0)(x0x1)(x13x033x0x12x03+x13x1x022+x0x12x1x02)+2f(x1)(x1x0)(x1x0)(x13x0333x0+x12x12x022+x12x022x0)+h3(x1xi)4(x0xi)44

abf(x)dx=2f(x0)(x0x1)(x0x1)(x13x033(x0+3x12x1)x12x022)+4f(xi)(x1x0)(x0x1)(x13x033x0x12x03+x13x1x022x0x12+2x1x022)+2f(x1)(x1x0)(x1x0)(x13x033(3x0+x12x0)x12x022)+h3(x1xi)4(x0xi)44

abf(x)dx=2f(x0)(x0x1)(x0x1)(x13x033x0+x12x12x022)+4f(xi)(x1x0)(x0x1)2x132x033x0x12+3x033x13+3x1x02+6x0x126x1x026+2f(x1)(x1x0)(x1x0)(x13x033x0+x12x12x022)+h3(x1xi)4(x0xi)44

abf(x)dx=2f(x0)(x0x1)(x0x1)(x13x033x0x12x03+x13x1x024)+4f(xi)(x1x0)(x0x1)x13+x03+3x0x123x1x026+2f(x1)(x1x0)(x1x0)(x13x033x0x12+x13x03x1x024)+h3(x1xi)4(x0xi)44

abf(x)dx=2f(x0)(x0x1)(x0x1)4x134x033x0x12+3x033x13+3x1x0212+4f(xi)(x1x0)(x0x1)x13+3x0x123x1x02+x036+2f(x1)(x1x0)(x1x0)(4x134x033x0x123x13+3x03+3x1x0212)+h3(x1xi)4(x0xi)44

abf(x)dx=2f(x0)(x0x1)(x0x1)x13x033x0x12+3x1x0212+4f(xi)(x1x0)(x1x0)x133x0x12+3x1x02x036+2f(x1)(x1x0)(x1x0)(x13x033x0x12+3x1x0212)+h3(x1xi)4(x0xi)44

abf(x)dx=2f(x0)(x0x1)(x0x1)x133x0x12+3x1x02x0312+4f(xi)(x1x0)(x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(x13x033(x0+x12+x1)x12x022+x0+x12x1(x1x0))+4f(xi)(x1x0)(x0x1)(x13x033(x0+x1)x12x022+x0x1(x1x0))+2f(x1)(x1x0)(x1x0)(x13x033(x0+x0+x12)x12x022+x0x0+x12(x1x0))+3h3(xxi)3

abf(x)dx=2f(x0)(x0x1)(x0x1)(x13x033x0+3x12x12x022+x12x022x1)+4f(xi)(x1x0)(x0x1)(x13x033x0x12x03+x13x1x022+x0x12x1x02)+2f(x1)(x1x0)(x1x0)(x13x0333x0+x12x12x022+x12x022x0)+3h3(xxi)3

abf(x)dx=2f(x0)(x0x1)(x0x1)(x13x033(x0+3x12x1)x12x022)+4f(xi)(x1x0)(x0x1)(x13x033x0x12x03+x13x1x022x0x12+2x1x022)+2f(x1)(x1x0)(x1x0)(x13x033(3x0+x12x0)x12x022)+3h3(xxi)3

abf(x)dx=2f(x0)(x0x1)(x0x1)(x13x033x0+x12x12x022)+4f(xi)(x1x0)(x0x1)2x132x033x0x12+3x033x13+3x1x02+6x0x126x1x026+2f(x1)(x1x0)(x1x0)(x13x033x0+x12x12x022)+3h3(xxi)3

abf(x)dx=2f(x0)(x0x1)(x0x1)(x13x033x0x12x03+x13x1x024)+4f(xi)(x1x0)(x0x1)x13+x03+3x0x123x1x026+2f(x1)(x1x0)(x1x0)(x13x033x0x12+x13x03x1x024)+3h3(xxi)3

abf(x)dx=2f(x0)(x0x1)(x0x1)4x134x033x0x12+3x033x13+3x1x0212+4f(xi)(x1x0)(x0x1)x13+3x0x123x1x02+x036+2f(x1)(x1x0)(x1x0)(4x134x033x0x123x13+3x03+3x1x0212)+3h3(xxi)3

abf(x)dx=2f(x0)(x0x1)(x0x1)x13x033x0x12+3x1x0212+4f(xi)(x1x0)(x1x0)x133x0x12+3x1x02x036+2f(x1)(x1x0)(x1x0)(x13x033x0x12+3x1x0212)+3h3(xxi)3

abf(x)dx=2f(x0)(x0x1)(x0x1)x133x0x12+3x1x02x0312+4f(xi)(x1x0)(x1x0)(x1x0)36+2f(x1)(x1x0)(x1x0)(x133x0x12+3x1x02x0312)+3h3(xxi)3

abf(x)dx=2f(x0)(x0x1)(x0x1)(x1x0)312+4f(xi)6(x1x0)+2f(x1)(x1x0)(x1x0)(x1x0)312+3h3(xxi)3

abf(x)dx=f(x0)6(x1x0)+4f(xi)6(x1x0)+f(x1)6(x1x0)+3h3(xxi)3

abf(x)dx=f(x0)+4f(xi)+f(x1)6(x1x0)+3h3(xxi)3

abf(x)dx=f(x0)+4f(xi)+f(x1)6Δx+3h3(xxi)3

abf(x)dx=(f(x0)+4f(xi)+f(x1))Δx6+3h3(xxi)3


abf(x)dx=f(x0)(x0x1)(x0x1)22+f(x1)(x1x0)(x1x0)22+2h2(x1x0)3(x0x1)324

abf(x)dx=f(x0)2(x0x1)+f(x1)2(x1x0)+2h2(x1x0)3+(x1x0)324

abf(x)dx=f(x0)2(x1x0)+f(x1)2(x1x0)+4h2(x1x0)324

abf(x)dx=f(x0)+f(x1)2(x1x0)+h2(x1x0)36

abf(x)dx=f(x0)+f(x1)2Δx+h2Δx36


abf(x)dx=f(xi)(x1x0)

abf(x)dx=f(xi)Δx


abf(x)dxabf(xi)dx


S-Sum S1(x0,x1)=xi1/2/1

S2(x0,x1)=xi1/3+xi2/3/2

S1(x0,x1)=xi1/4+xi2/4+xi3/4/3

Let us consider the integrals

(xc1)dx=x22c1x+c0=1x22c1x+2c01×2

(xc1)(xc2)dx=(x2(c1+c2)x+c1c2)dx=x33(c1+c2)x22+c1c2x+c0=2x33(c1+c2)x+6c1c2x+6c01×2×3

(xc1)(xc2)(xc3)dx=(x3(c1+c2+c3)x2+(c1c2+c1c3+c2c3)x+c1c2c3)dx=x44(c1+c2+c3)x33+(c1c2+c1c3+c2c3)x22+c1c2c3x+c0=2x33(c1+c2)x+6c1c2x+6c01×2×3



An analytical method of calculation of the relative weights of the evaluations of the function f(x) at the points x0,xi(x0,x1),x1,..., consists in evaluating the integral of the function f(x) as the integral of a polynomial approximation.

If one chooses the value of xk as xk=xj, i.e., at the beginning of every subinterval, then the sum of products is equal to:

abf(x)dxf(x0=a)(x1x0)+f(x1)(x2x1)+...+f(xn2)(xn1xn2)+f(xn1)(xnxn1),

If one chooses the value of xk as xk=xi, i.e., at the beginning of every subinterval, then the sum of products is equal to:

abf(x)dxf(x0=a)(x1x0)+f(x1)(x2x1)+...+f(xn2)(xn1xn2)+f(xn1)(xnxn1),

Let us consider the case of equally-spaced points (although this restriction can be easily lifted), according to the definition,

In the case of a semi-continuous function, i.e., a function which is continuous except for a finite numerable set of points in an interval (a,d), the calculation of the definite integral can be defined as the sum of the definite integrals between the points of discontinuity, i.e.,

adf(x)dx=abf(x)dx+b+cf(x)dx+c+df(x)dxx=ax=bf(x)Δx+x=b+x=cf(x)Δx+x=c+x=df(x)Δx.


Template:Bookcat