# 7.6E: Exercises for Numerical Integration - Mathematics

In exercises 1 - 5, approximate the following integrals using either the midpoint rule, trapezoidal rule, or Simpson’s rule as indicated. (Round answers to three decimal places.)

1) ( displaystyle ∫^2_1frac{dx}{x};) trapezoidal rule; ( n=5)

( 0.696)

2) ( displaystyle ∫^3_0sqrt{4+x^3};dx;) trapezoidal rule; ( n=6)

3) ( displaystyle ∫^3_0sqrt{4+x^3};dx;) Simpson’s rule; ( n=6)

( 9.279)

4) ( displaystyle ∫^{12}_0x^2;dx;) midpoint rule; ( n=6)

5) ( displaystyle ∫^1_0sin^2(pi x);dx;) midpoint rule; ( n=3)

( 0.500)

6) Use the midpoint rule with eight subdivisions to estimate ( displaystyle ∫^4_2x^2;dx.)

7) Use the trapezoidal rule with four subdivisions to estimate ( displaystyle ∫^4_2x^2;dx.)

( T_4=18.75)

8) Find the exact value of ( displaystyle ∫^4_2x^2;dx.) Find the error of approximation between the exact value and the value calculated using the trapezoidal rule with four subdivisions. Draw a graph to illustrate.

Approximate the integral to four decimal places using the indicated rule.

9) ( displaystyle ∫^1_0sin^2(pi x);dx;) trapezoidal rule; ( n=6)

( 0.5000)

10) ( displaystyle ∫^3_0frac{1}{1+x^3};dx;) trapezoidal rule; ( n=6)

11) ( displaystyle ∫^3_0frac{1}{1+x^3};dx;) Simpson’s rule; ( n=6)

( 1.1614)

12) ( displaystyle ∫^{0.8}_0e^{−x^2};dx;) trapezoidal rule; ( n=4)

13) ( displaystyle ∫^{0.8}_0e^{−x^2};dx;) Simpson’s rule; ( n=4)

(0.6577)

14) (displaystyle ∫^{0.4}_0sin(x^2);dx;) trapezoidal rule; ( n=4)

15) (displaystyle ∫^{0.4}_0sin(x^2);dx;) Simpson’s rule; ( n=4)

(0.0213)

16) ( displaystyle ∫^{0.5}_{0.1}frac{cos x}{x};dx;) trapezoidal rule; (n=4)

17) ( displaystyle ∫^{0.5}_{0.1}frac{cos x}{x};dx;) Simpson’s rule; (n=4)

(1.5629)

18) Evaluate ( displaystyle ∫^1_0frac{dx}{1+x^2}) exactly and show that the result is ( π/4). Then, find the approximate value of the integral using the trapezoidal rule with ( n=4) subdivisions. Use the result to approximate the value of ( π).

19) Approximate ( displaystyle ∫^4_2frac{1}{ln x};dx) using the midpoint rule with four subdivisions to four decimal places.

( 1.9133)

20) Approximate ( displaystyle ∫^4_2frac{1}{ln x};dx) using the trapezoidal rule with eight subdivisions to four decimal places.

21) Use the trapezoidal rule with four subdivisions to estimate ( displaystyle ∫^{0.8}_0x^3;dx) to four decimal places.

( T(4)=0.1088)

22) Use the trapezoidal rule with four subdivisions to estimate ( displaystyle ∫^{0.8}_0x^3;dx.) Compare this value with the exact value and find the error estimate.

23) Using Simpson’s rule with four subdivisions, find ( displaystyle ∫^{π/2}_0cos(x);dx.)

24) Show that the exact value of ( displaystyle ∫^1_0xe^{−x};dx=1−frac{2}{e}). Find the absolute error if you approximate the integral using the midpoint rule with 16 subdivisions.

25) Given ( displaystyle ∫^1_0xe^{−x};dx=1−frac{2}{e},) use the trapezoidal rule with 16 subdivisions to approximate the integral and find the absolute error.

Approximate error is ( 0.000325.)

26) Find an upper bound for the error in estimating ( displaystyle ∫^3_0(5x+4);dx) using the trapezoidal rule with six steps.

27) Find an upper bound for the error in estimating ( displaystyle ∫^5_4frac{1}{(x−1)^2};dx) using the trapezoidal rule with seven subdivisions.

( frac{1}{7938})

28) Find an upper bound for the error in estimating ( displaystyle ∫^3_0(6x^2−1);dx) using Simpson’s rule with ( n=10) steps.

29) Find an upper bound for the error in estimating ( displaystyle ∫^5_2frac{1}{x−1};dx) using Simpson’s rule with ( n=10) steps.

( frac{81}{25,000})

30) Find an upper bound for the error in estimating ( displaystyle ∫^π_02xcos(x);dx) using Simpson’s rule with four steps.

31) Estimate the minimum number of subintervals needed to approximate the integral ( displaystyle ∫^4_1(5x^2+8);dx) with an error magnitude of less than 0.0001 using the trapezoidal rule.

( 475)

32) Determine a value of n such that the trapezoidal rule will approximate ( displaystyle ∫^1_0sqrt{1+x^2};dx) with an error of no more than 0.01.

33) Estimate the minimum number of subintervals needed to approximate the integral ( displaystyle ∫^3_2(2x^3+4x);dx) with an error of magnitude less than 0.0001 using the trapezoidal rule.

( 174)

34) Estimate the minimum number of subintervals needed to approximate the integral ( displaystyle ∫^4_3frac{1}{(x−1)^2};dx) with an error magnitude of less than 0.0001 using the trapezoidal rule.

35) Use Simpson’s rule with four subdivisions to approximate the area under the probability density function ( y=frac{1}{sqrt{2π}}e^{−x^2/2}) from ( x=0) to ( x=0.4).

( 0.1544)

36) Use Simpson’s rule with ( n=14) to approximate (to three decimal places) the area of the region bounded by the graphs of ( y=0, x=0,) and ( x=π/2.)

37) The length of one arch of the curve ( y=3sin(2x)) is given by ( L=∫^{π/2}_0sqrt{1+36cos^2(2x)};dx.) Estimate L using the trapezoidal rule with ( n=6).

( 6.2807)

38) The length of the ellipse ( x=acos(t),y=bsin(t),0≤t≤2π) is given by ( L=4a∫^{π/2}_0sqrt{1−e^2cos^2(t)}dt), where e is the eccentricity of the ellipse. Use Simpson’s rule with ( n=6) subdivisions to estimate the length of the ellipse when ( a=2) and ( e=1/3.)

39) Estimate the area of the surface generated by revolving the curve ( y=cos(2x),0≤x≤frac{π}{4}) about the x-axis. Use the trapezoidal rule with six subdivisions.

( 4.606)

40) Estimate the area of the surface generated by revolving the curve ( y=2x^2, 0≤x≤3) about the x-axis. Use Simpson’s rule with ( n=6.)

41) The growth rate of a certain tree (in feet) is given by ( y=dfrac{2}{t+1}+e^{−t^2/2},) where t is time in years. Estimate the growth of the tree through the end of the second year by using Simpson’s rule, using two subintervals. (Round the answer to the nearest hundredth.)

( 3.41) ft

42) [T] Use a calculator to approximate ( displaystyle ∫^1_0sin(πx);dx) using the midpoint rule with 25 subdivisions. Compute the relative error of approximation.

43) [T] Given ( displaystyle ∫^5_1(3x^2−2x);dx=100,) approximate the value of this integral using the midpoint rule with 16 subdivisions and determine the absolute error.

( T_{16}=100.125;) absolute error = ( 0.125)

44) Given that we know the Fundamental Theorem of Calculus, why would we want to develop numerical methods for definite integrals?

45) The table represents the coordinates ( (x,​y)) that give the boundary of a lot. The units of measurement are meters. Use the trapezoidal rule to estimate the number of square meters of land that is in this lot.

 ( x) ( y) ( x) ( y) 0 125 600 95 100 125 700 88 200 120 800 75 300 112 900 35 400 90 1000 0 500 90

46) Choose the correct answer. When Simpson’s rule is used to approximate the definite integral, it is necessary that the number of partitions be____

a. an even number

b. odd number

c. either an even or an odd number

d. a multiple of 4

47) The “Simpson” sum is based on the area under a ____.

parabola

48) The error formula for Simpson’s rule depends on___.

a. ( f(x))

b. ( f′(x))

c. ( f^{(4)}(x))

d. the number of steps

## 7.6E: Exercises for Numerical Integration - Mathematics

Does the series $dssum_^infty$ converge? It is possible, but a bit unpleasant, to approach this with the integral test or the comparison test, but there is an easier way. Consider what happens as we move from one term to the next in this series: $cdots++<(n+1)^5over 5^>+cdots$ The denominator goes up by a factor of 5, $ds 5^=5cdot5^n$, but the numerator goes up by much less: $ds (n+1)^5=n^5+5n^4+10n^3+10n^2+5n+1$, which is much less than $ds 5n^5$ when $n$ is large, because $ds 5n^4$ is much less than $ds n^5$. So we might guess that in the long run it begins to look as if each term is $1/5$ of the previous term. We have seen series that behave like this: $sum_^infty <1over 5^n>= <5over4>,$ a geometric series. So we might try comparing the given series to some variation of this geometric series. This is possible, but a bit messy. We can in effect do the same thing, but bypass most of the unpleasant work.

The key is to notice that $lim_ <>over a_n>= lim_ <(n+1)^5over 5^><5^nover n^5>= lim_ <(n+1)^5over n^5><1over 5>=1cdot <1over5>=<1over 5>.$ This is really just what we noticed above, done a bit more officially: in the long run, each term is one fifth of the previous term. Now pick some number between $1/5$ and $1$, say $1/2$. Because $lim_ <>over a_n>=<1over5>,$ then when $n$ is big enough, say $nge N$ for some $N$, $<>over a_n> Theorem 11.7.1 (The Ratio Test) Suppose that$dslim_ |a_/a_n|=L$. If$L 1$the series diverges, and if$L=1$this test gives no information. Proof. The example above essentially proves the first part of this, if we simply replace$1/5$by$L$and$1/2$by$r$. Suppose that$L>1$, and pick$r$so that$1 r quad hboxquad |a_| > r|a_n|.$This implies that$ds |a_|>r^k|a_N|$, but since$r>1$this means that$dslim_|a_| ot=0$, which means also that$dslim_a_n ot=0$. By the divergence test, the series diverges. To see that we get no information when$L=1$, we need to exhibit two series with$L=1$, one that converges and one that diverges. It is easy to see that$sum 1/n^2$and$sum 1/n$do the job. Example 11.7.2 The ratio test is particularly useful for series involving the factorial function. Consider$dssum_^infty 5^n/n!$.$ lim_ <5^over (n+1)!>= lim_ <5^over 5^n>= lim_ <5><1over (n+1)>=0. $Since Theorem 11.7.3 (The Root Test) Suppose that$dslim_ |a_n|^<1/n>=L$. If$L 1$the series diverges, and if$L=1$this test gives no information. The proof of the root test is actually easier than that of the ratio test, and is a good exercise. Example 11.7.4 Analyze$dssum_^infty <5^nover n^n>$. The ratio test turns out to be a bit difficult on this series (try it). Using the root test:$ lim_ left(<5^nover n^n> ight)^<1/n>= lim_ <(5^n)^<1/n>over (n^n)^<1/n>>= lim_ <5over n>=0. $Since < 1$, the series converges.

The root test is frequently useful when $n$ appears as an exponent in the general term of the series.

## Error Formulas

Natural questions arise: how good are the approximations given by the forward, backwards and central difference formulas? We derive the error formulas from Taylor's Theorem.

Theorem. The degree $n$ Taylor polynomial of $f(x)$ at $x=a$ with remainder term is

for some value $c$ between $x$ and $a$.

Theorem. The forward difference formula error is

where $left| , f''(x) , ight| leq K_2$ for all $x in [a,a+h]$. The same error fomula holds for the backward difference formula.

Proof. Look at the degree 1 Taylor formula:

Let $x = a+h$ and manipulate the formula

Let $K_2$ such that $left| , f''(x) , ight| leq K_2$ for all $x in [a,a+h]$ and we see the result.

Theorem. The central difference formula error is:

where $|f'''(x)| leq K_3$ for all $x in [a-h,a+h]$.

Proof. Look at the Taylor polynomial of degree 2:

Let $x = a + h$ and also $x = a - h$ and write:

Notice that $f'''(x)$ is continuous (by assumption) and $(f'''(c_1) + f'''(c_2))/2$ is between $f'''(c_1)$ and $f'''(c_2)$ and so there exists some $c$ between $c_1$ and $c_2$ such that

by the Intermediate Value Theorem. Let $K_3$ such that $left| , f'''(x) , ight| leq K_3$ for all $x in [a-h,a+h]$ and we see the result.

## Numerical Integration

You will probably encounter many situations in which analytical integration of a function or a differential equation is difficult or impossible. In this section we show how Scientific Python can help through its high level mathematical algorithms. You will learn how to develop you own numerical integration method and how to get a specified accuracy. The package scipy.integrate can do integration in quadrature and can solve differential equations

### 1. The Basic Trapezium Rule

Scipy uses three methods to integrate a one-dimensional function: trapezoidal (integrate.trapz), Simpson (integrate.simps) and Romberg (integrate.romb). The trapezium (trapezoidal) method is the most straightforward of the three. The simple trapezium formula calculates the integral of a function f(x) as the area under the curve representing f(x) by approximating it with the sum of trapeziums:

The area of each trapezium is calculated as width times the average height.
Example: Evaluate the integral:

using the basic trapezium rule.
We shall write a small program to evaluate the integral. Of course we have to estimate the number of trapeziums to use the accuracy of our method depends on this number.

Our basic integration program has the inconvenience of depending on the number of trapeziums that we have to change manually. As a basic rule, if we double the number of trapeziums and get the same answer within 1 in 1000000, the answer is probably correct.

Run the program. How many trapeziums are needed to get a relative error of less than 1 part in 1,000,000?
We can do this as follows:

After running this code you should end up with a printed out value of 6.

You have to modify the previous program because of the infinite range of integration. Check the integrand to see where it becomes negligible. The modified code should look something like this.

And the printed result when the program is run should be something close to 1.77245385091.

### 2. Integrating a function with scipy.integrate

Our simple integration program will divide the interval 0 to 2 in equally spaced slices and spend the same time calculating the integrand in each of these slices. If we have a closer look at the integrand and plot it, we would notice that at low x-values the function hardly varies, so our program will waste time in that region. In contrast, the integrate.quad() routine from Scipy is arbitrary callable (adaptive), in the sense that it can adjust the function evaluations to concentrate on the more important regions (quad is short for quadrature, an older name for integration). Let’s see how Scipy could simplify our work:

The output will be (8.153364119811167, 9.0520525739669813e-014). As you notice, we get both the integral value and the error estimate in only three lines of code, without bothering about the number of trapeziums or the accuracy. The integrate.quad() routine takes the function and the integration limits as input arguments.An overview of scipy.integrate modules can be accessed by typing in the shell window:

The period of a pendulum of length l oscillating at a large angle α is given by

is the period of the same pendulum at small amplitudes. In Exercises 2 and 3 you will analyze both experimental data and the Pylab plot of the large-angle pendulum. Any numerical evaluation of the integral as is would fail (explain why). If we change the variable by writing:

which is a well-behaved integral. Write a program to use the above integral to calculate the ratio T/T0 for integral amplitudes 0° ≤ α ≤ 90°. Output these values as a table showing the amplitude in degrees and radians as well as T/T0. Explain the result when α = 0. Think about this for a moment before you read the solution below.

Some sample output can be found here. NumIntA3output.txt

On the same graph, compare the plot of the sin function with the plot of the integral of the cos function in the range [-π, π].
This can be done as follows:

### 3. Integrating ordinary differential equations with odeint

Many physical phenomena are modeled by differential equations: oscillations of simple systems (spring-mass, pendulum, etc.), fluid mechanics (Navier-Stokes, Laplace's, etc.), quantum mechanics (Schrödinger’s) and many others. Here we’ll show you how to numerically solve these equations. The example we shall use in this tutorial is the dynamics of a spring-mass system in the presence of a drag force.

Writing Newton’s second law for the system, we have to combine the elastic force

with the drag force whose model for a slowly moving object is

where L is the length of the unstretched/uncompressed spring.

To find an approximate solution to the equation of motion above, we’ll have to use a finite difference approximation for the derivative, which will generate an algorithm for solving the equation. Most such algorithms are based on first order differential equations, so it will probably not be a bad idea to start by putting our second-order equation in the form of a system of two first-order differential equations:

To write the numerical integration program, we shall use odeint, which is part of scipy.integrate. A function call to odeint looks something like this:

As you may see in the simplified syntax above, it takes a number of input arguments: function func defining the system of first order equations, initial values of variables y0 (put in an array), time t (an array of time values), and arguments args() which can be our parameters (mass, elastic constant, drag coefficient and initial length of the spring). The unknowns in a system of differential equations are functions odeint will return to us the values of these functions at the values t provided, as an array.

## Exercises 10.5

In the following problems, compute the trapezoid and Simpson approximations using 4 subintervals, and compute the error estimate for each. (Finding the maximum values of the second and fourth derivatives can be challenging for some of these you may use a graphing calculator or computer software to estimate the maximum values.) If you have access to Sage or similar software, approximate each integral to two decimal places. You can use this Sage worksheet to get started.

## 7.6E: Exercises for Numerical Integration - Mathematics

Over the next few sections we examine some techniques that are frequently successful when seeking antiderivatives of functions. Sometimes this is a simple problem, since it will be apparent that the function you wish to integrate is a derivative in some straightforward way. For example, faced with $int x^<10>,dx$ we realize immediately that the derivative of $ds x^<11>$ will supply an $ds x^<10>$: $ds (x^<11>)'=11x^<10>$. We don't want the "11'', but constants are easy to alter, because differentiation "ignores'' them in certain circumstances, so $<1over 11>>=<1over 11>11>=x^<10>.$

From our knowledge of derivatives, we can immediately write down a number of antiderivatives. Here is a list of those most often used:

$displaylines< int x^n,dx=<>over n+1>+C, quadhboxcr int x^<-1>,dx = ln |x|+Ccr int e^x,dx = e^x+Ccr int sin x,dx = -cos x+Ccr int cos x,dx = sin x+Ccr int sec^2 x,dx = an x+Ccr int sec x an x,dx = sec x+Ccr int <1over1+x^2>,dx = arctan x+Ccr int <1over sqrt<1-x^2>>,dx = arcsin x+Ccr >$

## 7.6E: Exercises for Numerical Integration - Mathematics

discrete mathematics and its applications 7e solution [pdf]

Discrete Mathematics & Its Applications (7E) Student’s Solutions Guide by Kenneth H. Rosen, Jerrold W. Grossman

MathSchoolinternational contain 5000+ of Mathematics Free PDF Books and Physics Free PDF Books . Which cover almost all topics for students of Mathematics, Physics and Engineering. Here is extisive list of Basic Mathematics ebooks . We hope students and teachers like these textbooks , notes and solution manuals.

Discrete Mathematics & Its Applications (7E) Student’s Solutions Guide written by Kenneth H. Rosen, Jerrold W. Grossman
This text is designed for a one- or two-term introductory discrete mathematics course taken by students in a wide variety of majors, including mathematics, computer science, and engineering.
College algebra is the only explicit prerequisite, although a certain degree of mathematical maturity is needed to study discrete mathematics in a meaningful way. This book has been designed to meet the needs of almost all types of introductory discrete mathematics courses. It is highly flexible and extremely comprehensive. The book is designed not only to be a successful textbook, but also to serve as valuable resource students can consult throughout their studies and professional life.

Book Detail :-
Title: Discrete Mathematics & Its Applications Student’s Solutions Guide
Edition: 7th
Author(s): Kenneth H. Rosen, Jerrold W. Grossman
Publisher: McGraw-Hill Science/Engineering/Math
Series:
Year: 2011
Pages: 534
Type: PDF
Language: English
ISBN: 0077353501,9780077353506
Country: US

Author Kenneth H. Rosen is an author and mathematician. His interests include discrete mathematics and number theory. He is the author of several books including Discrete Mathematics and Its Applications, McGraw-Hill. He holds degrees in mathematics from the University of Michigan Ann Arbor and Massachusetts Institute of Technology. He has published several articles in the areas of number theory and mathematical modeling. He is currently a member of the technical staff at AT&T Labs in Middletown, New Jersey and chief editor of the Handbook of Discrete and Combinatorial Mathematics, published by CRC Press. At AT&T Labs, some of his contributions are in the areas of multimedia, including video communications, speech recognition, and image networking.Rosen received a B.S. in Mathematics from the University of Michigan, Ann Arbor (1972), and his Ph.D. in Mathematics from M.I.T. (1976)
The contents of this page are sourced from Wikipedia article. The contents are available under the CC BY-SA 4.0 license.

Join WhatsApp Group
Join Telegram Group

Book Contents :-
Discrete Mathematics & Its Applications (7E) Student’s Solutions Guide written by Kenneth H. Rosen, Jerrold W. Grossman cover the following topics.
1. The Foundations: Logic and Proofs
2. Basic Structures: Sets, Functions, Sequences, Sums, and Matrices
3. Algorithms
4. Number Theory and Cryptography
5. Induction and Recursion
6. Counting
7. Discrete Probability
9. Relations
10. Graphs
11. Trees
12. Boolean Algebra
13. Modeling Computation
Appendixes 1 Axioms for the Real Numbers and the Positive Integers
Appendixes 2 Exponential and Logarithmic Functions
Appendixes 3 Pseudocode.
Photo Credits
Index of Biographies
Index

We are not the owner of this book/notes. We provide it which is already avialable on the internet. For any further querries please contact us. We never SUPPORT PIRACY. This copy was provided for students who are financially troubled but want studeing to learn. If You Think This Materials Is Useful, Please get it legally from the PUBLISHERS. Thank you.

## Exercises 15.7

Ex 15.7.1 Complete example 15.7.1 by converting to polar coordinates and evaluating the integral. (answer)

Ex 15.7.2 Evaluate $dsdint<> xy,dx,dy$ over the square with corners $(0,0)$, $(1,1)$, $(2,0)$, and $(1,-1)$ in two ways: directly, and using $x=(u+v)/2$, $y=(u-v)/2$. (answer)

Ex 15.7.3 Evaluate $dsdint<> x^2+y^2,dx,dy$ over the square with corners $(-1,0)$, $(0,1)$, $(1,0)$, and $(0,-1)$ in two ways: directly, and using $x=(u+v)/2$, $y=(u-v)/2$. (answer)

Ex 15.7.4 Evaluate $dsdint<> (x+y)e^,dx,dy$ over the triangle with corners $(0,0)$, $(-1,1)$, and $(1,1)$ in two ways: directly, and using $x=(u+v)/2$, $y=(u-v)/2$. (answer)

Ex 15.7.5 Evaluate $dsdint<> y(x-y),dx,dy$ over the parallelogram with corners $(0,0)$, $(3,3)$, $(7,3)$, and $(4,0)$ in two ways: directly, and using $x=u+v$, $y=u$. (answer)

Ex 15.7.6 Evaluate $dsdint<> sqrt,dx,dy$ over the triangle with corners $(0,0)$, $(4,4)$, and $(4,0)$ using $x=u$, $y=uv$. (answer)

Ex 15.7.7 Evaluate $dsdint<> ysin(xy),dx,dy$ over the region bounded by $xy=1$, $xy=4$, $y=1$, and $y=4$ using $x=u/v$, $y=v$. (answer)

Ex 15.7.8 Evaluate $dsdint<> sin(9x^2 + 4y^2),dA,$ over the region in the first quadrant bounded by the ellipse $9x^2+4y^2 = 1$. (answer)

Ex 15.7.9 Compute the Jacobian for the substitutions $x= hosinphicos heta$, $y= hosinphisin heta$, $z= hocosphi$.

Ex 15.7.10 Evaluate $ds intdV$ where $E$ is the solid enclosed by the ellipsoid $+ + = 1,$ using the transformation $x=au$, $y=bv$, and $z=cw$. (answer)

## Euler integration method for solving differential equations

In mathematics there are several types of ordinary differential equations (ODE), like linear, separable, or exact differential equations, which are solved analytically, giving an exact solution. This means that there is a specific method to be applied in order to extract a general exact solution.

is a first order separable differential equation, which has the exact solution:

In practice, most of the differential equation do not have a standard form and can not be solved with analytic methods, which means we can not find a general solution y(x). This is the case for most of the differential equations derived from physical models (mechanical, electrical, thermal, etc.).

In this case, we need to use numerical methods to be able to determine the solution of the differential equation. Bear in mind that with numerical methods:

• we get an approximation of the solution, not the exact solution
• the solution is calculated incrementally, step by step

One of the simplest integration method is the Euler integration method, named after the mathematician Leonhard Euler. The Euler method is a first-order method, which means that the local error (error per step) is proportional to the square of the step size, and the global error (error at a given time) is proportional to the step size.

The Euler integration method is also an explicit integration method, which means that the state of a system at a later time (next step) is calculated from the state of the system at the current time (current step).

The Euler integration method is also called the polygonal integration method, because it approximates the solution of a differential equation with a series of connected lines (polygon).

### Line equation

In order to have a better understanding of the Euler integration method, we need to recall the equation of a line:

m – is the slope of the line
n – is the offset
(x,y) – coordinates

Image: Example of line equations

If we apply a differentiation to the line equation (4), we get:

which means that the slope m of the line is equal with the differential of y(x).

### Euler method

The Euler method gives an approximation for the solution of the differential equation:

with the initial condition:

where t is continuous in the interval [a, b].

The Euler algorithm for differential equations integration is the following:

Step 1. Define the integration start parameters: N, a, b, h, t0 and y0.

N is the number of integration steps, it is defined by the user (e.g 10, 100, etc.). For a fixed integration interval, the higher the number of integration steps, the better the approximation of the exact solution. Very high steps implies high computing power. Usually there must be a compromise between the accuracy and the time taken to solve the integration.

a and b are the start and end of the integration interval. If, for example we want to approximate the solution of a differential equation between 0 and 1, then a = 0 and b = 1.

The size of the interval and the number of integration steps define the integration step size h. The smaller the step size, the better the approximation, the smaller the integration error. It is possible to directly define the step size, which will further determine the number of integration steps. The step size h is calculated as:

The initial conditions t0, y0 represent the solution (y0) of the differential equation at a given time (t0). Usually t0 is equal with the start value of the integration interval a.

Step 2. Initialise the calculation loop index i = 1.

Step 3. (Loop) Calculate the function argument ti and the function approximation wi as:

Note that the initial function approximation w0 is equal with the initial solution y0.

Step 4. If i < N, increment i = i + 1 and repeat Step 3.

Step 5. If i = N, the algorithm is complete and wi will be the approximation of the solution y(t), for i = 1, 2, … N.

In each step of the iteration, the Euler approximation calculate the end point of a line. The starting point A0 is known, it has the coordinates (t0, y0). The point A1 is calculated based on the point A0 and the slope f(t,y). The next points An are calculated based on the previous points An-1 and the slope. As we seen in the line equation, the slope is equal with the differential of y(t).

Image: Graphical representation of Euler integration method

The is a direct link between the Euler approximation used in Step 3 and the line equation. In the picture below is depicted where every parameter of the line equation is found in the Euler approximation. This image summarises quite well how the Euler approximation (integration method) works.

Image: Euler approximation and line equation

### Euler integration method example

Let’s apply the Euler integration and solve the following ordinary differential equation:

The Euler approximation must be performed in 10 and 30 steps. The exact solution of the equation is:

We will use the exact solution to compare against the Euler approximation. For a better understanding, we are going to apply the method step-by-step (manual) and also using a Scilab and a C script.

#### Step-by-step (manual) method

Second, we’ll write the expression of the slope f(t,w):

The iteration loop is going to be done in the table below:

 Step Time Slope Euler approximation Exact solution Absolute error i ti = t0 + h·i f(ti-1, wi-1) wi = wi-1 + h·f(ti-1, wi-1) yi = -1/ti |yi – wi| 1 1.1 1.0000000 -0.9000000 -0.9090909 0.0090909 2 1.2 0.8346281 -0.8165372 -0.8333333 0.0167961 3 1.3 0.7081591 -0.7457213 -0.7692308 0.0235095 4 1.4 0.6092475 -0.6847965 -0.7142857 0.0294892 5 1.5 0.5303982 -0.6317567 -0.6666667 0.0349100 6 1.6 0.4664990 -0.5851068 -0.6250000 0.0398932 7 1.7 0.4139668 -0.5437101 -0.5882353 0.0445252 8 1.8 0.3702295 -0.5066872 -0.5555556 0.0488684 9 1.9 0.3334030 -0.4733469 -0.5263158 0.0529689 10 2.0 0.3020810 -0.4431388 -0.5000000 0.0568612

As expected, there is a difference between the Euler approximation and the exact solution. The absolute error increases in each iteration step because at every step, the current approximation (i) is based on a previous approximation (i-1), which also has an error.

#### C script

The Euler method can be defined in any programming language. Below you can see the implementation in a C code.

Running the executable will output the following results:

#### Scilab script

Using Scilab is a very easy and flexible way to experiment different integration step sizes and also give the possibility to plot the results. For an easier understanding we are going to define several Scilab function ( *.sci ), for:

The Scilab function for the slope function is going to be defined in a file f.sci , with the following content:

The Scilab function for the Euler approximation is going to be defined in a file eulerODE1.sci , with the following content:

The exact solution is going to be defined in a file y.sci , with the following content:

In a Scilab script, in our case named runEuler.sce , we are going to define the initial parameters of the Euler integration, call the *.sci functions and plot the results.

After running the script, the following plot is being generated:

Image: Euler integration method – example 1 (10 steps)

It’s clearly visible that there is a significand difference between the exact solution of the differential equation and its Euler approximation. In order to improve the results, we are going to increase the number the integration steps N = 30 and run the Scilab script again.

Image: Euler integration method – example 1 (30 steps)

As expected, the error between the exact solution and the Euler approximation is reduced. This is achieved by having 3 times more integration steps, which means more calculation power.

## Input Arguments

### Fun — Integrand function handle

Integrand, specified as a function handle, which defines the function to be integrated from xmin to xmax .

For scalar-valued problems, the function y = fun(x) must accept a vector argument, x , and return a vector result, y . This generally means that fun must use array operators instead of matrix operators. For example, use .* ( times ) rather than * ( mtimes ). If you set the 'ArrayValued' option to true , then fun must accept a scalar and return an array of fixed size.

### Xmin — Lower limit of x real number | complex number

Lower limit of x, specified as a real (finite or infinite) scalar value or a complex (finite) scalar value. If either xmin or xmax are complex, then integral approximates the path integral from xmin to xmax over a straight line path.

Data Types: double | single
Complex Number Support: Yes

### Xmax — Upper limit of x real number | complex number

Upper limit of x, specified as a real number (finite or infinite) or a complex number (finite). If either xmin or xmax are complex, integral approximates the path integral from xmin to xmax over a straight line path.

Data Types: double | single
Complex Number Support: Yes

### Name-Value Pair Arguments

Specify optional comma-separated pairs of Name,Value arguments. Name is the argument name and Value is the corresponding value. Name must appear inside quotes. You can specify several name and value pair arguments in any order as Name1,Value1. NameN,ValueN .

Example: integral(fun,a,b,'AbsTol',1e-12) sets the absolute error tolerance to approximately 12 decimal places of accuracy.

### 'AbsTol' — Absolute error tolerance 1e-10 (default) | nonnegative real number

Absolute error tolerance, specified as the comma-separated pair consisting of 'AbsTol' and a nonnegative real number. integral uses the absolute error tolerance to limit an estimate of the absolute error, |qQ|, where q is the computed value of the integral and Q is the (unknown) exact value. integral might provide more decimal places of precision if you decrease the absolute error tolerance.

AbsTol and RelTol work together. integral might satisfy the absolute error tolerance or the relative error tolerance, but not necessarily both. For more information on using these tolerances, see the Tips section.

Example: integral(fun,a,b,'AbsTol',1e-12) sets the absolute error tolerance to approximately 12 decimal places of accuracy.

Data Types: single | double

### 'RelTol' — Relative error tolerance 1e-6 (default) | nonnegative real number

Relative error tolerance, specified as the comma-separated pair consisting of 'RelTol' and a nonnegative real number. integral uses the relative error tolerance to limit an estimate of the relative error, |qQ|/|Q|, where q is the computed value of the integral and Q is the (unknown) exact value. integral might provide more significant digits of precision if you decrease the relative error tolerance.

RelTol and AbsTol work together. integral might satisfy the relative error tolerance or the absolute error tolerance, but not necessarily both. For more information on using these tolerances, see the Tips section.

Example: integral(fun,a,b,'RelTol',1e-9) sets the relative error tolerance to approximately 9 significant digits.

Data Types: single | double

### 'ArrayValued' — Array-valued function flag false or 0 (default) | true or 1

Array-valued function flag, specified as the comma-separated pair consisting of 'ArrayValued' and a numeric or logical 1 ( true ) or 0 ( false ). Set this flag to true or 1 to indicate that fun is a function that accepts a scalar input and returns a vector, matrix, or N-D array output.

The default value of false indicates that fun is a function that accepts a vector input and returns a vector output.

Example: integral(fun,a,b,'ArrayValued',true) indicates that the integrand is an array-valued function.

### 'Waypoints' — Integration waypoints vector

Integration waypoints, specified as the comma-separated pair consisting of 'Waypoints' and a vector of real or complex numbers. Use waypoints to indicate points in the integration interval that you would like the integrator to use in the initial mesh:

Add more evaluation points near interesting features of the function, such as a local extrema.

Integrate efficiently across discontinuities of the integrand by specifying the locations of the discontinuities.

Perform complex contour integrations by specifying complex numbers as waypoints. If xmin , xmax , or any entry of the waypoints vector is complex, then the integration is performed over a sequence of straight line paths in the complex plane. In this case, all of the integration limits and waypoints must be finite.

Do not use waypoints to specify singularities. Instead, split the interval and add the results of separate integrations with the singularities at the endpoints.

Example: integral(fun,a,b,'Waypoints',[1+1i,1-1i]) specifies two complex waypoints along the interval of integration.

Data Types: single | double
Complex Number Support: Yes