0% found this document useful (0 votes)
591 views

Integral Calculus and Differential Equations Using Mathematica

The document provides an introduction to using Mathematica for symbolic and numeric calculations involving calculus and differential equations. It discusses how Mathematica can be used to perform numeric calculations with arbitrary precision, symbolic manipulations of expressions, indefinite and definite integrals, solutions to differential equations, and numeric solutions to problems using approximation methods. The document also outlines various functions and operations in Mathematica for working with numbers, variables, functions, and complex expressions.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
591 views

Integral Calculus and Differential Equations Using Mathematica

The document provides an introduction to using Mathematica for symbolic and numeric calculations involving calculus and differential equations. It discusses how Mathematica can be used to perform numeric calculations with arbitrary precision, symbolic manipulations of expressions, indefinite and definite integrals, solutions to differential equations, and numeric solutions to problems using approximation methods. The document also outlines various functions and operations in Mathematica for working with numbers, variables, functions, and complex expressions.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 223

Integral Calculus and Differential

Equations using

MATHEMATICA

CÉSAR PÉREZ LÓPEZ


INDEX
PRACTICAL INTRODUCTION TO MATHEMATICA
1.1 CALCULATION NUMERIC WITH MATHEMATICA
1.2 SYMBOLIC CALCULATION WITH MATHEMATICA
1.3 GRAPHICS WITH MATHEMATICA
1.4 MATHEMATICA AND THE PROGRAMMING
INTEGRATION AND APPLICATIONS
2.1 INDEFINITE INTEGRALS
2.1.1 Inmediate integrals
2.2 INTEGRATION BY SUBSTITUTION (OR CHANGE OF VARIABLES)
2.2.1 Exponential, logarithmic, hyperbolic and inverse circular functions
2.2.2 Irrational functions, binomial integrals
2.3 INTEGRATION BY PARTS
2.4 INTEGRATION BY REDUCTION AND CYCLIC INTEGRATION
DEFINITE INTEGRALS. CURVE ARC LENGTH, AREAS, VOLUMES AND SURFACES OF REVOLUTION.
IMPROPER INTEGRALS
3.1 DEFINITE INTEGRALS
3.2 CURVE ARC LENGTH
3.3 THE AREA ENCLOSED BETWEEN CURVES
3.4 SURFACES OF REVOLUTION
3.5 VOLUMES OF REVOLUTION
3.6 CURVILINEAR INTEGRALS
3.7 IMPROPER INTEGRALS
3.8 PARAMETER DEPENDENT INTEGRALS
3.9 THE RIEMANN INTEGRAL
INTEGRATION IN SEVERAL VARIABLES AND APPLICATIONS. AREAS AND VOLUMES. DIVERGENCE, STOKES
AND GREEN’S THEOREMS
4.1 AREAS AND DOUBLE INTEGRALS
4.2 SURFACE AREA BY DOUBLE INTEGRATION
4.3 VOLUME CALCULATION BY DOUBLE INTEGRALS
4.4 VOLUME CALCULATION AND TRIPLE INTEGRALS
4.5 GREEN’S THEOREM
4.6 THE DIVERGENCE THEOREM
4.7 STOKES’ THEOREM
FIRST ORDER DIFFERENTIAL EQUATIONS. SEPARATES VARIABLES, EXACT EQUATIONS, LINEAR AND
HOMOGENEOUS EQUATIONS. NUMERIACAL METHODS
5.1 SEPARATION OF VARIABLES
5.2 HOMOGENEOUS DIFFERENTIAL EQUATIONS
5.3 EXACT DIFFERENTIAL EQUATIONS
5.4 LINEAR DIFFERENTIAL EQUATIONS
5.5 NUMERICAL SOLUTIONS TO DIFFERENTIAL EQUATIONS OF THE FIRST ORDER
HIGH-ORDER DIFFERENTIAL EQUATIONS AND SYSTEMS OF DIFFERENTIAL EQUATIONS
6.1 ORDINARY HIGH-ORDER EQUATIONS
6.2 HIGHER-ORDER LINEAR HOMOGENEOUS EQUATIONS WITH CONSTANT COEFFICIENTS
6.3 NON-HOMOGENEOUS EQUATIONS WITH CONSTANT COEFFICIENTS. VARIATION OF PARAMETERS
6.4 NON-HOMOGENEOUS LINEAR EQUATIONS WITH VARIABLE COEFFICIENTS. CAUCHY-EULER EQUATIONS
6.5 THE LAPLACE TRANSFORM
6.6 SYSTEMS OF LINEAR HOMOGENEOUS EQUATIONS WITH CONSTANT COEFFICIENTS
6.7 SYSTEMS OF LINEAR NON-HOMOGENEOUS EQUATIONS WITH CONSTANT COEFFICIENTS
HIGHER ORDEN DIFFERENTIAL EQUATIONS AND SYSTEMS USING APPROXIMATION METHODS.
DIFFERENTIAL EQUATIONS IN PARTIAL DERIVATIVES
7.1 HIGHER ORDER EQUATIONS AND APPROXIMATION METHODS
7.2 THE EULER METHOD
7.3 THE RUNGE–KUTTA METHOD
7.4 DIFFERENTIAL EQUATIONS SYSTEMS BY APPROXIMATE METHODS
7.5 DIFFERENTIAL EQUATIONS IN PARTIAL DERIVATIVES
7.6 ORTHOGONAL POLYNOMIALS
7.7 AIRY AND BESSEL FUNCTIONS
APPENDIX I. NUMBERS, OPERATIONS AND MOST COMMON FUNCTIONS
8.1 ARITHMETIC OPERATIONS IN MATHEMATICA
8.2 PREDEFINED FUNCTIONS OF INTEGER ARGUMENT
8.3 NUMBERING SYSTEMS
8.4 RATIONAL NUMBERS
8.5 IRRATIONAL NUMBERS
8.6 COMPLEX NUMBERS. MORE COMMON FUNCTIONS
8.7 ROUNDING AND APPROACH FUNCTIONS
8.8 COMMON CONSTANT USED IN MATHEMATICA
8.9 RANDOM NUMBERS
8.10 NUMBER THEORY PACKAGE
APPENDIX II. VARIABLES AND FUNCTIONS
9.1 VARIABLES
9.2 FUNCTIONS DEFINITION
9.3 RECURSIVE FUNCTIONS
9.4 PIECEWISE FUNCTIONS
9.5 OPERATIONS WITH FUNCTIONS
9.6 DATA TYPES USED IN THE DEFINITION OF THE FUNCTIONS
Chapter 1.

PRACTICAL INTRODUCTION TO
MATHEMATICA
1.1 CALCULATION NUMERIC WITH MATHEMATICA

We can use Mathematica as a powerful numerical computer. Most calculators handle


numbers only with a degree of precision preset, however Mathematica makes exact
calculations with precision which is necessary. In addition, unlike calculators, we can
perform operations not only with individual numbers, but also with objects such as arrays.

Most of the themes of the classical numerical calculus, are treated in this software. It
supports matrix calculus, statistics, interpolation, fit by least squares, numerical integration,
minimization of functions, linear programming, numerical algebraic and differential
equations resolution and a long list of processes of numerical analysis that we’ll see as the
successive issues of this book.

Here are some examples of numerical calculus with Mathematica. (As we all know, to
get the results necessary type mayusculas+enter once written corresponding expressions)

(1) We can simply calculate 4 + 3 and get as a result 7, to do this, just type 4 + 3 (and
then shift + Enter).

In [1]: = 4 + 3
Out [1] = 7

(2) Also we can get the exact value of 3 high at 100, without having previously set
precision, just for this purpose press 3 ^ 100.

In [2]: = 3 ^ 100
Out [2] = 515377520732011331036461129765621272702107522001

(3) Also we can use the N function to pass the result of the operation immediately prior
to scientific notation. To do this, type N [%] (symbol % we use to refer to the immediately
preceding calculation).

In [3]: = N [%]
47
Out [3] = 5.153775207320114 10
(4) Also we can perform operations with a fixed degree of precision. If we find the
square root of 5 with 25 digits, simply enter the expression N [Sqrt [5], 25].

In [4]: = N [Sqrt [5], 25]


Out [4] = 2.2360679774997896964091737

(5) Also we can work with complex numbers. We will get the result of the operation (2 +
3i) raised to 10, by typing the expression (2 + 3I) ^ 10.

In [5]: = (2 + 3 * I) ^ 10
Out [5] = 341525 145668 I

(6) Also we can calculate the value of the Bessel function in section 13.5. This type
BesselJ [0,13.5].

In [6]: = BesselJ [0, 13.5]


Out [6] = 0.2149891658804008

(7) Also can calculate the value of Rieman function Z at the point (1/2 + 13i) with 15
digits. Just press N [Zeta [1/2 + 13I], 15].

I In[7] := N[Zeta[1/2 + 13*I], 15]


Out [7] = 0.4430047825053677 0.6554830983211705

(8) Also we can perform numeric integrals. To calculate the integral between 0 and p of
(SIN(x)) sine function type expression NIntegrate [Sin [no [x]], {x, 0, Pi}].

In [8]: = NIntegrate [Sin [no [x]], {x, 0, Pi}]


Out [8] = 1.78648748195006.

These themes will be treated more thoroughly in successive chapters throughout the
book.
1.2 SYMBOLIC CALCULATION WITH MATHEMATICA
Mathematica perfectly handled the symbolic mathematical computation, manipulating
formulae and algebraic expressions easily and quickly and can perform the majority of
algebraic operations. You can expand, factor and simplify polynomials and rational and
trigonometric expressions, you can find algebraic solutions of polynomial equations and
systems of equations, can evaluate derivatives and integrals symbolically and find functions
solution of differential equations, you can manipulate powers, limits and many other facets
of algebraic mathematics series.

Here are some examples of symbolic computation with Mathematica.

1) We can raise the bucket the following algebraic expression: (x + 1) (x+2) (x+2) ^ 2.
This is done by typing the following expression: Expand [((x + 1) (x+2) (x+2) ^ 2) ^ 3]. The
result will be another algebraic expression:

In [1]: = Expand [((x + 1) *(x + 2) (x + 2) ^ 2) ^ 3]

23
Out [1] = 8- 12 x- 6 x- x

2) We can factor the result of the calculation on the previous example by typing Factor
[%]

In [2]: = Factor [%]

3
Out [2] = (2 + x)

3) We can resolve the indefinite integral of the function (x ^ 2) Sin(x) ^ 2 by typing


Integrate [x ^ 2 Sin [x] ^ 2 x]

In[3] := Integrate[x^2*Sin[x]^2, x]
Out[3]=
3 2
x x Cos [2 x] (1- 2 x) Sin [2 x]
‑‑ ‑ ‑‑‑‑‑‑‑‑‑‑– + ‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑–—
6 4 8

4) We can find the derivative of the result of the integral above by typing D [% x]

In[4] := D[%, x]

Out[4] =

2 2
x Cos[2 x] (1 ‑ 2 x ) Cos[2 x]
‑‑ ‑ ‑‑‑‑‑‑‑‑‑‑– +–-‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑
2 4 4

5) We can simplify the result of the derivative before typing Simplify [%]

In[5] := Simplify[%]

2 2
Out[5] = x Sin[x]

6) We can develop in power of order 14 series the result from the previous example by
typing Series [% {x, 0.14}]

In[6] := Series[%, {x, 0, 14}]


Out[6] =

6 8 10 12 14
4 x 2x x 2x 2x 15
x ‑ ‑‑ + ‑‑‑‑ ‑ ‑‑‑— +–-‑‑‑‑ ‑ —‑‑‑‑‑‑— + O[x]
3 45 315 14175 467775
7) We can solve the equation 3ax - 7 x ^ 2 + x ^ 3 = 0 (a, is a parameter) by typing Solve
[3ax 7 x ^ 2 + x ^ 3 = 0]

In[7] := Solve[3*ax ‑ 7*x^2 + x^3 == 0, x]

Out[7] =

1/3
7 49 2
{{x ‑>-‑ + ‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑––––––— +
3 2 1/3
3 (686 ‑ 81 ax + 9 Sqrt[‑1372 ax + 81 ax ] )

2 1/3
(686 ‑ 81 ax + 9 Sqrt[‑1372 ax + 81 ax ] )
+ ‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑––––––-},
1/3
32
1/3
7 I ‑49 2
{x ‑> ‑ + ‑ Sqrt[3] (‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑–––––––– +
3 2 2 1/3
3(686‑81ax+9Sqrt[‑1372ax+81ax ] )

2 1/3
(686 ‑ 81 ax + 9 Sqrt[‑1372 ax + 81 ax ] )
+ ‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑–––––––) ‑
1/3
32
1/3
49 2
- (‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑–––––––— +
2 1/3
3 (686 ‑ 81 ax + 9 Sqrt[‑1372 ax + 81 ax ] )

2 1/3
(686 ‑ 81 ax + 9 Sqrt[‑1372 ax + 81 ax ] )
+ ‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑–––––––-) / 2},
1/3
32
1/3
7 I ‑49 2
{x ‑> ‑ ‑ ‑ Sqrt[3] (‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑––––––- +
3 2 2 1/3
3 (686‑81ax+9 Sqrt[‑1372ax+81ax ] )

2 1/3
(686 ‑ 81 ax + 9 Sqrt[‑1372 ax + 81 ax ] )
+ ‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑–––––––-) ‑
1/3
32

1/3
49 2
‑ (‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑––––––––- +
2 1/3
3 (686 ‑ 81 ax + 9 Sqrt[‑1372 ax + 81 ax ] )

2 1/3
(686 81 ax + Sqrt 9 [1372 ax + 81 ax])
+ ‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑–––––––) / 2}}
1/3
32
8) We can find five complex solutions of the equation x ^ 5 + 2 x + 1 = 0 by typing NSolve
[x ^ 5 + 2 x + 1 = 0, x]

In[8] := NSolve[x^5 + 2*x + 1 == 0, x]

Out[8] = {{x ‑> ‑0.7018735688558619 ‑ 0.879697197929824 I},


{x ‑> ‑0.7018735688558619 + 0.879697197929824 I},
{x ‑> ‑0.486389035934543},
{x ‑> 0.945068086823133 ‑ 0.854517514439046 I},
{{x > 0.945068086823133 + 0.854517514439046 I}}

9) We can generate a matrix 3 x 3 whose (i, j) element is 1 / (i+j+1) by typing m = Table


[1 / (i + j + 1), {i, 3}, {j, 3}]

In[9] := m = Table[1/(i + j + 1), {i, 3}, {j, 3}]


Out [9] = {{1/3, 1/4, 1/5}, {1/4, 1/5, 1/6}, {1/5, 1/6, 1/7}}

10) We can invert the matrix above, typing Inverse [m]

In [10]: = Inverse [m]


Out [10] = {{300, 900, 630}, {900, 2880, 2100}, {630, 2100, 1575}}

11) We can find the determinant of the matrix m xIdentidad (3.3)


tecleando Det[ m ‑ x IdentityMatrix[3] ]

In[11] := Det[m ‑ x*IdentityMatrix[3]]

2 3
Out [11] = (1 4755 x + 255600 x - 378000 x ) / 378000

12) We can find all the permutations of the three elements {e, f, g}
tecleando Permutations[{e, f, g}]

In[12] := Permutations[{e, f, g}]


Out[12] = {{e, f, g}, {e, g, f}, {f, e, g}, {f, g, e}, {g, e, f}, {g, f, e}}

13) We can define the function f (x) = x ^ 2, variable x, the explicit form:

In [13]: = f [x_] = x ^ 2;

14) We can create pure functions that do not have explicit typing for example, definitions
Map [Function [x, 1 + x ^ 2], {a, b, c, d}]

In[14] := Map[Function[x,1+x^2], {a,b,c,d}]


Out [14] =

2 2 2 2
{1 + a, 1 + b, 1 + c, 1 + d }

All of these concepts will be expanded in the corresponding chapters.


1.3 GRAPHICS WITH MATHEMATICA
Mathematica produces two and three-dimensional graphics, as well as outlines and
graphics of density, you can represent the graphics and list data, allows to control colors,
shading and other graphics features, also supports animated graphics. Produced by
Mathematica graphics are portable to other programs.

Here are some examples of graphics with Mathematica

We can represent the function Seno (1/x) for x ranging between 0 and pi typing Plot
[Sin[1/x], {x, 0, Pi}]. See Figure 1.1

Figure 1.1

We can give options of framework and grid to the graph above, by typing Show [%,
Frame > True, FrameLabel > {“time”, “Signal”}, GridLines > Automatic]. See Figure 1.2.

Figure 1.2

We can generate a graphic of contour for the sine function Sin(x+Sin(y)), by typing
ContourPlot [Sin[x + Sin[y]], {x, 2, 2}, {y, 2, 2}]. See Figure 1.3.
Figure 1.3

We can generate a three-dimensional graph, typing Plot3D [Cos [x + Cos [y]], {x, 3, 3},
{y, 3, 3}]. See Figure 1.4.

These 3D graphics allow perfection to get an idea of the figures in space, and are very
helpful in visually identifying intersections between different bodies, generation of
developments of all kinds and volumes of revolution.

Figure 1.4

We can represent a surface given by the parametric coordinates x = uCos(t). y = u sine


(t), z = t/2 by typing the expression: ParametricPlot3D [{uCos[t], uSin[t], t/2}, {t, 0, 15},
{u, 1, 1}, tick > None]. See Figure 1.5.
Figure 1.5

We can combine in the same graph the two previous charts by typing Show [% %].

In the corresponding chapter of graphics we will extend these concepts.


1.4 MATHEMATICA AND THE PROGRAMMING
Properly combined all the objects defined in Mathematica, appropriate to the work rules
defined in the program, you can build very useful programming in mathematical research.

Programs usually consist of a series of instructions in which values are calculated, is


assigned a name and are reused in further calculations.

As in programming languages like C or Fortran, in Mathematica you can write programs


with loops, control flow and conditionals.

In Mathematica can write procedural programs, i.e., define a sequence of steps standard
to run. As in C or Pascal, a Do, For, or While using repetitive calculation can be performed.
The language of Mathematica also includes structures such as If and Which Swiych.

Mathematica also supports different logic, such as And, Or, Not and Xor functions.
Mathematica supports procedural programming (with entry iterative, recursive, loops…),
functional programming (pure functions…), and the object-oriented programming.

Here are two simple examples of programs. The first calculates the sign of a number, and
the second calculates the median of a set of numbers.

In[1]:= sign[x_] :=
Which[
x < 0., -1,
x == 0., 0,
x > 0, 1
]

In[2]:= sign[3]
Out[2] =1
In[3]:= mediana[lista_List] :=
Block[{
lo,
long
},
long =Length[lista];
lo = Sort[lista];
If[
OddQ[long],
the [[(long + 1) / 2]],
(the [[long/2]] + the [[long/2 + 1]] / 2).
]
]

In [4]: = median [{76, 56, 23, 78, 34}]


Out [4] = 56
Chapter 2.

INTEGRATION AND APPLICATIONS


Mathematica works with integral calculus in a clear and simple way. The number of
functions that enables you to work in this area is not very high, but they are very efficient
in solving integration problems. You can calculate the indefinite integral of most
integrable functions whose structure is not very complicated; for example, functions that
involve simple logarithms, exponentials, rational, trigonometric functions, inverse
trigonometric functions, etc. Definite and improper integrals do not present problems for
Mathematica. Double integrals, triple integrals and n-fold integrals are also easily found.

The most commonly used Mathematica commands for integral calculus are:

Integrate[f[x],x] Computes the indefinite integral

Integrate[f[x,y],{x,y}] Computes the double integral


Integrate[f[x,y, …, z],{x,y, …,z}]

Computes

Integrate[f[x],{x,a,b}] Computes the definite integral


NIntegrate[f[x],{x,a,b}]

Computes, using approximate methods, the definite integral

Integrate[f[x,y],{x,a,b},{y,c,d}}]

Computes the definite double integral

NIntegrate[f[x,y],{x,a,b},{y,c,d}}]
Computes, using approximate methods, the definite double integral

Integrate[f[x,y,…, z],{x,a,b},{y,c,d},…,{z,e,f}]

Computes

NIntegrate[f[x,y,…, z],{x,a,b},{y,c,d},…,{z,e,f}]

Computes, using approximate methods, the definite integral

Here are some examples:

In[1]:= Integrate[1/(x^2-1), x]

Log[1 - x] Log[1 + x]
–––- - –––-
2 2

In[2]:= D[% + c, x]//Simplify

1
––-
2
-1 + x

In the two previous examples we have shown that differentiation and integration are
inverse functions.

In[3]:= Integrate[a Log[1+b x], x]//Simplify


a (1 + b x) (-1 + Log[1 + b x])
––––––––––-
b

In[4]:= Integrate[x^n,x]

1+n
x
––
1+n

We have seen how Mathematica lets you enter parameters on the whole, they are
treated as generic constant.

In[5]:= Integrate[(x^2)(f’[x]^3),f[x]]

2 3
x f[x] f’[x]

In[6]:=Integrate[f’[x],x]

f[x]

In the preceding examples it is observed that is possible to use as integration


variable a function.

In[7]:= Integrate[x^3,{x,a,b}]

4 4
-a b
–+—
4 4

In[8]:= Integrate[x^3+y^3,{x,0,a},{y,0,b}]

4 4
a b ab
–- + –-
4 4

In[9]:= Integrate[x^3+y^3,{x,0,a},{y,0,x}]

5
a

4

In these last examples definite integrals have been solved, one of which has a variable
limit of integration, which is perfectly valid with Mathematica.
2.1 INDEFINITE INTEGRALS
2.1.1 Inmediate integrals

In the examples that follow, we demonstrate the ease with which Mathematica can
find integrals that are not so obvious using classical techniques. Mathematica is able to find
indefinite integrals involving simple, rational, exponential, logarithmic, trigonometric and
inverse trigonometric functions.

Exercise 2-1. Find the following integrals:

In[1]:= Integrate[3x^5+7x+2,x]

2 6
7x x
2 x + –- + —
2 2

In[2]:= Integrate[1/(Sqrt[x^2+1]),x]
ArcSinh[x]
In[3]:= Integrate[x^3 Sqrt[1+x^4],x]

4
1 x 4
(- + —) Sqrt[1 + x ]
6 6

In[4]:=Integrate[1/((2+x)Sqrt[1+x]),x]

2 ArcTan[Sqrt[1 + x]]

In[5]:= Integrate[1/((1-x^2)Sqrt[1-x^2]),x]

2
x Sqrt[1 - x ]
-(––––—)
2
-1 + x

Exercise 2-2. Find the following integrals:


In[1]:= Integrate[Cos[x^3]/Sqrt[Sin[x]],x]

3
Cos[x ]
Integrate[––––, x]
Sqrt[Sin[x]]

We have here an example of an integral that does not solve directly Mathematica.

In[2]:= Integrate[x Cos[x],x]


Cos[x] + x Sin[x]

In[3]:= Integrate[arc Cos[2x],x]

arc Sin[2 x]
––––
2

In[4]:= Integrate[Sin[Log[x]],x]

-(x Cos[Log[x]]) + x Sin[Log[x]]


––––––––––—
2

In[5]:= Integrate[Log[x]/Sqrt[x],x]
-4 Sqrt[x] + 2 Sqrt[x] Log[x]

Exercise 2-3. Find the following integrals:


In[1]:= Integrate[Tan[x]^2,x]
Sec[x] (-(x Cos[x]) + Sin[x])

In[2]:= Integrate[(x^3)(E^(2x)),x]
2 3
2x 3 3x 3x x
E (-(-) + – - –- + —)
8 4 4 2

In[3]:= Integrate[Cos[x]^11/Sin[x]^2,x]

((-87318 + 48510 Cos[2 x] + 5544 Cos[4 x] +


891 Cos[6 x] + 110 Cos[8 x] + 7 Cos[10 x]) Csc[x]) / 32256
In[4]:= Integrate[Sec[x],x]
x x x x
-Log[Cos[-] - Sin[-]] + Log[Cos[-] + Sin[-]]
2 2 2 2

Exercise 2-4. Find the following integrals:


In[1]:= Integrate[(3x+5)/(x^3-x^2-x+1),x]

-4 Log[1 - x] Log[1 + x]
–– - –––- + –––-
-1 + x 2 2

In[2]:= Integrate[x^2/(a^4-x^4),x]
x
-ArcTan[-]
a Log[-a + x] Log[a + x]
–––- - –––— + –––-
2a 4a 4a

In[3]:= Integrate[(x-1)/((x^3))(x^2+1),x]

1 1
–- - - + x - Log[x]
2 x
2x

In[4]:= Integrate[x^2/Sqrt[(a+b x^2)^5],x]//Simplify

3 25
x Sqrt[(a + b x ) ]
––––––—
24
3 a (a + b x )

In[5]:= Integrate[Sqrt[-x^2-2x+1],x]

1 x 2 -1 - x
(- + -) Sqrt[1 - 2 x - x ] - ArcSin[––-]
2 2 Sqrt[2]
2.2 INTEGRATION BY SUBSTITUTION (OR CHANGE
OF VARIABLES)

Integration by substitution is used to solve integrals ò f(x) dx where a direct solution is


not immediate and where other techniques fail.

The method is to find a function x = g (t) which replaces x under the integral sign,
converting the integral into another simpler integral in the variable t. The new integrand will
in the majority of cases be immediately integrable or will be a rational function.

The substitution must meet the following conditions:

· is differentiable:

· must be invertible, supporting an inverse function .

Once the transformed integral has been calculated as a function of , we must substitute
to give the final solution as a function of .

The substitution method is one of the most wide ranging of integral calculus, because of
the great variety of substitutions that can be used, depending on the type of function that
appears under the integral sign. However, it can easily go wrong in the sense that the
transformed integral may be more difficult than the original integral, so some care is needed
to choose an appropriate substitution.
2.2.1 Exponential, logarithmic, hyperbolic and inverse
circular functions

The following chart summarizes the substitutions to be made depending on the


function to integrate, where R is a rational function of its corresponding argument.

Function to integrate Substitution Inverse function


––––––––––––––––––––––––––––––––––-

R(ax) ax = t x = (1/lna)lnt

R(x,ax) a = tx x = (1/lna)lnt

R(ex) ex = t x = lnt

R(x,ex) ex = t x = lnt

R(x,lnx) lnx = t x = et

R(x,asenx) asenx = t x = senx

R(x,acosx) acosx = t x = cost

R(x,atanx) atanx = t x= tant

R(x,senhx) ex = t x = lnt

R(x,coshx) ex = t x = lnt

R(x,tanhx) ex = t x = lnt
R(sinhx,coshx) ex = t x = lnt

R(función hiperb.) ex = t x = lnt

Exercise 2-5. Find the following integrals:

For the first integral we make the change E =t (x=Log[t])

In[1]:= f[x_]=(1/(1+E^x))Dt[x]

Dt[x]
––
x
1+E

In[2]:= f[Log[t]]

Dt[t]
–––
t (1 + t)
In[3]:= Integrate[%/Dt[t],t]

Log[t] - Log[1 + t]

In[4]:= % /. t->E^x//Simplify

x x
Log[E ] - Log[1 + E ]

For the second integral we make the same change

In[1]:= f[x_]=(x/(Cosh[x]+Sinh[x]))Dt[x]

x Dt[x]
–––––—
Cosh[x] + Sinh[x]

In[2]:= f[Log[t]]

Dt[t] Log[t]
––––––—
2 2
-1 + t 1 + t
t (––- + ––)
2t 2t

In[3]:= Integrate[%/Dt[t],t]

1 Log[t]
-(-) - ––
t t

In[4]:= % /. t->E^x//Simplify

x
1 + Log[E ]
-(–––—)
x
E

For the third integral is making the change ArcSin[x]=t (x=Sin[t])

In[1]:= f[x_]=(ArcSin[x]/(1-x^2)^(3/2))Dt[x]

ArcSin[x] Dt[x]
–––––
2 3/2
(1 - x )

In[2]:= f[Sin[t]]

ArcSin[Sin[t]] Cos[t] Dt[t]


–––––––––
2 3/2
(1 - Sin[t] )

In[3]:= Integrate[%/Dt[t],t]
2
Log[1 - Sin[t] ] ArcSin[Sin[t]] Sin[t]
–––––- + –––––––
2 2
Sqrt[1 - Sin[t] ]

In[4]:= % /. t->ArcSin[x]//Simplify

2
x ArcSin[x] Log[1 - x ]
–––– + –––—
2 2
Sqrt[1 - x ]

Exercise 2-6. Find the following integrals:

t
For the first integral we make the change Log [x]=t (x=E )

In[1]:= f[x_]=(Log[2x]/(x Log[4x]))Dt[x]

Dt[x] Log[2 x]
––––—
x Log[4 x]

In[2]:= f[E^t]
t
Dt[t] Log[2 E ]
–––––
t
Log[4 E ]

In[3]:= Integrate[%/Dt[t],t]

t t t
t + (Log[2 E ] - Log[4 E ]) Log[Log[4 E ]]

In[4]:= % /. t->Log[x]//Simplify

Log[x] + (Log[2 x] - Log[4 x]) Log[Log[4 x]]

For the second integral we make the same change

In[1]:= f[x_]=(1/(x(4-Log[x^2])))Dt[x]

Dt[x]
–––––
2
x (4 - Log[x ])

In[2]:= f[E^t]

Dt[t]
––––-
2t
4 - Log[E ]

In[3]:= Integrate[%/Dt[t],t]
2t
-Log[4 - Log[E ]]
––––––-
2

In[4]:= % /. t->Log[x]//Simplify

2
-Log[4 - Log[x ]]
–––––—
2
2.2.2 Irrational functions, binomial integrals
The following chart summarizes the substitutions to be made, depending on the function
to integrate, where R is a rational function of its corresponding argument.
Function a integrate Substitution Inverse function

m/n p/q ax+b M M


┌ ax+b ┐ ┌ ax+b ┐ ──── = t dt ‑ b
R (x, │───── │,…,│───── │ ) cx+d x = ────────
└ cx+d ┘ └ cx+d ┘ M
M = mcm(n,..,q) a ‑ ct

M M
m/n p/q ax+b = t t‑b
R (x, (x, (ax+b),…,(ax+b) ) x = ──────
M = mcm(n,…,q) a

M
m/n p/q r/s x=t
R (x, x , x , ….,x )
M = mcm(n,q,..,s)

1 1 1
───────────────────── ───── = t x=a+─
p 2 1/2 x‑a t
(x‑a) (ax +bx +c)
2
2 1/2 2 1/2 t‑c
R (x, (ax +bx + c) a>0 (ax +bx+c) = xÖa +t x= ────────
b ‑ 2tÖa

2 1/2 2 1/2 2tÖc ‑ b


R (x, (ax +bx + c) c>0 (ax +bx+c) = Öc +xt x = ────────
2
a‑t
2
2 1/2 2 1/2 ab‑at
R (x, (ax +bx + c) (ax +bx+c) = (x‑a)t x = ────────
a,b are roots of 2
2 a‑t
ax + bx + c = 0

2 1/2 Öc
R (x, (‑ax +c) ) x = ── SIN(t)
Öa

2 1/2 Öc
R (x, (ax ‑c) ) x = ── SEC(t)
Öa

2 1/2 Öc
R (x, (ax +c) ) x = ── TAN(t)
Öa

BINOMIAS:

m np 1/n
x (a+bx ) with p integer x=t

s 1/n
m np m+1 n s (t ‑a)
x (a+bx ) with ─── integer a+bx = t x = ─────────
n s=denominator of p 1/n
b

s
m np m+1 -n s (t ‑b)
x (a+bx ) with ─── +p integer ax+b = t x = ─────────
n s=denominator of p -1/n
a
Exercise 2-7. Find the following integrals:

2 ½2

ò 1/[(x -x+1) x ]

ò x/(x+1)

2 ½2

ò 1/[(x +4) x ]

The first integral is an binomial integral with (8 + 1) / 3 = 3, which is an integer. After the
change to be made will be:

3 4 4 3 1/4
3+5x=t (x=(t - 3)/5 y t=(3 + 5 x ) )

In[1]:= f[x_]=(x^8/(3+5x^3)^(1/4))Dt[x]

8
x Dt[x]
––––-
3 1/4
(3 + 5 x )

In[2]:= f[((t^4-3)/5)^(1/3)]//Simplify

3 42
4 t (-3 + t ) Dt[t]
–––––––
4 1/4
375 (t )

In[3]:= Integrate[%/Dt[t],t]//PowerExpand

4 8
3 4 8t 4t
t (– - –- + –-)
125 875 4125

In[4]:= % /. t->(3+5x^3)^(1/4)//Simplify

3 3/4 3 6
4 (3 + 5 x ) (96 - 120 x + 175 x )
––––––––––––—
28875

The second integral is irrational, and should change:

1/x = t (x = 1/t)

In[1]:= f[x_]=(1/(x^2(x^2-x+1)^(1/2)))Dt[x]

Dt[x]
––––––-
2 2
x Sqrt[1 - x + x ]

In[2]:= f[1/t]//Simplify
Dt[t]
-(–––––—)
-2 1
Sqrt[1 + t - -]
t

In[3]:= Integrate[%/Dt[t],t]//PowerExpand
2
2 Log[-1 + 2 t + 2 Sqrt[1 - t + t ]]
-Sqrt[1 - t + t ] - –––––––––––-
2

In[4]:= % /. t->(1/x)
-2 1 2
Log[-1 + 2 Sqrt[1 + x - -] + -]
-2 1 x x
-Sqrt[1 + x - -] - –––––––––––
x 2

To calculate the third integral, the change to be made is:

2 2 2
x/(x+1) = t ( x = t / (1 - t ) )

In[1]:= f[x_]=(x/(x+1)^(1/2))Dt[x]

x Dt[x]
–––—
Sqrt[1 + x]
In[2]:= f[t^2/(1-t^2)]//Simplify

3 1
2 t Sqrt[––] Dt[t]
2
1-t
–––––––—
22
(-1 + t )

In[3]:= Integrate[%/Dt[t],t]//Simplify
1 2
Sqrt[––] (-2 + ––—)
2 2
1-t 3-3t

In[4]:= % /. t->(x/(x+1))^(1/2)//Simplify

2 (-2 + x) Sqrt[1 + x]
–––––––-
3

The fourth is an irrational comprehensive integrated where necessary change:

x = 2 Tan[t] , o sea, t = ArcTan(x/2)

In[1]:= f[x_]=(1/(x^2(x^2+4)^(1/2)))Dt[x]

Dt[x]
–––––
2 2
x Sqrt[4 + x ]

In[2]:= f[2 Tan[t]]//Simplify


2
Csc[t] Dt[t]
–––––
2
4 Sqrt[Sec[t] ]

In[3]:= Integrate[%/Dt[t],t]//Simplify
2
-(Cot[t] Sqrt[Sec[t] ])
–––––––—
4
In[4]:= % /. t->ArcTan[x/2]//Simplify

2
-Sqrt[4 + x ]
––––-
4x
2.3 INTEGRATION BY PARTS

Let and be two differentiable functions of . The formula for the


derivative of a product of functions is: d (u.v) = u.dv + v.du, which we rearrange as: u.dv =
d (u.v) - v.du. Integrating both sides of this equation gives us: ò u.dv = ò d (u.v) - ò v.du,
so we have:

ò u.dv = u.v - ò v.du

We have u = f (x)Þdu= f’(x) dx, and v = g (x)Þdv= g’(x) dx, so the final expression of the
integral will be:

ò f (x). g’(x) dx = f (x) .g (x) - ò g(x). f’(x) dx

This gives us a method of finding the integral of a product of two functions which can
potentially reduce the integral to a simpler integral.

Mathematica does not provide a function to do integrals parties directly, but, as in the
substitution method, it is easy to develop a procedure to perform this task. This procedure is
saved as permanent file and then be charged each time you want to make integral
substitution. It really is as if there was a package that solves the problem. Unlike the
substitution method, this is the option that will be adopted here.

Another alternative is to do with Mathematica the same steps used in normal practice
when a whole is solved piecemeal. This is the option which was adopted in the case of the
integral substitution.
Using a simple program we define a procedure that has as inputs the function to integrate
(function), the integration variable (x), the variable u and the value that takes u as a function
of x (u (x)=sustitution).

Ln[1]:=partes[function_, x_, u_, sustitution_]:=


{newfunction=Integrate[function/sustitution,x]*D[sustitution,x],
u->sustitution, v->Integrate[function/sustitution,x]}
Now we save this procedure permanently in a file with the Mathematica Save command.

In[2]:= Save[“intparts”, partes]


The first thing you have to do to solve an integral by parts with this procedure will load it
into memory, load as any other package.

Mathematica incorporates the command ‘partes’ which allows you to find an integral
directly by parts.

In[3]:= <<intparts
Once the procedure is loaded, enter its arguments (function f (x) to integrate, the
integration variable x, the variable u, and the value that takes u as a function of x (u (x)) and
execute it.

The final value of the integral is proposing to get Mathematica expression:

In[4]:= u(x) v(x) - Integrate[newfunction,x]//Simplify


Let’s illustrate this procedure with an example, which is calculated òxCos(x)d(x).

In[1]:= <<intparts

In[2]:= partes[x Cos[x],x,u,x]


{Sin[x], u -> x, v -> Sin[x]}

In[3]:= x Sin[x]-Integrate[nuevointegrando,x]
Cos[x] + x Sin[x]

Exercise 2-8. Solve the following integrals:


For the first integral we put u =3x^2+2x-7 y dv =Cos(x) dx

In[1]:= partes[(3x^2+2x-7) Cos[x],x,u,3x^2+2x-7]

2
{(2 + 6 x) Sin[x], u -> -7 + 2 x + 3 x , v -> Sin[x]}

In[2]:= (3x^2+2x-7) Sin[x] -Integrate[nuevointegrando,x]//Simplify

2 Cos[x] + 6 x Cos[x] - 13 Sin[x] + 2 x Sin[x] +

2
3 x Sin[x]

For the second integral we put u = Sen[Ln(x)]

In[1]:= partes[Sin[Log[x]] x^2,x,u,Sin[Log[x]]]

2 3
x Cos[Log[x]] x
{––––—, u -> Sin[Log[x]], v -> —}
3 3

In[2]:= Sin[Log[x]](x/3)-Integrate[nuevointegrando,x]//Simplify
3
x Sin[Log[x]] x (3 Cos[Log[x]] + Sin[Log[x]])
––––- - ––––––––––—
3 30
x
For the third integral we put u=E

In[1]:= partes [E^x Cos[x],x,u,E^x]


x x
{E Sin[x], u -> E , v -> Sin[x]}

In[2]:= E^x Sin[x] -Integrate[nuevointegrando,x]//Simplify

x
E (Cos[x] + Sin[x])
––––––—
2
2.4 INTEGRATION BY REDUCTION AND CYCLIC
INTEGRATION

Integration by reduction (reduction formulas) is used to integrate functions involving


large integer exponents. It reduces the integral to a similar integral where the value of the
exponent has been reduced. Repeating this procedure we obtain the value of the original
integral.

The usual procedure is to perform integration by parts. This will lead to the sum of an
integrated part and an integral of a similar form to the original, but with a reduced exponent.

Cyclic integration is similar except we end up with the same integral that we had at the
beginning, except for constants. The resulting equation can be rearranged to give the
original integral.

In both cases the problem lies in the proper choice of the function u(x) in the integration
by parts.

Mathematica directly calculates the value of this type of integral in the majority of cases.
In the worst case, the final value of the integral can be found after one to three applications of
integration by parts.

Exercise 2-9. Solve the following integrals:

12
For the first integral we do u = Sen (x)
In[1]:= partes [Sin[x]^13 Cos[x]^15,x,u,Sin[x]^12]

17 11 16
-3 Cos[x] Sin[x] 12 -Cos[x]
{––––––—, u -> Sin[x] , v -> –––}
4 16
In[2]:= -Sin[x]^12(Cos[x]^16)/16-Integrate[nuevointegrando,x]//Simplify

(-1486485 - 20612592 Cos[2 x] - 1288287 Cos[4 x] +

5153148 Cos[6 x] + 858858 Cos[8 x] -

1717716 Cos[10 x] - 429429 Cos[12 x] +

490776 Cos[14 x] + 156156 Cos[16 x] -

104104 Cos[18 x] - 39039 Cos[20 x] +

14196 Cos[22 x] + 6006 Cos[24 x] - 924 Cos[26 x] -

429 Cos[28 x]) / 1612223348736

7
For the second integral we do u = x

In[1]:= partes [(x^7)(a+b x)^(1/2),x,u,x^7]

2a 2x 6 7
{7 (– + –) x Sqrt[a + b x], u -> x ,
3b 3
2a 2x
v -> (– + –) Sqrt[a + b x]}
3b 3

In[2]:=(x^7)(2a/3b+2x/3)Sqrt[a+bx]-Integrate[nuevointegrando,x]
//Simplify

7
2 x (a b + x) Sqrt[a + b x]
–––––––––- -
3

5/2 6 5
(4 (a + b x) (1024 a - 2560 a b x +

4 2 2 3 3 3 2 4 4
4480 a b x - 6720 a b x + 9240 a b x -

5 5 6 6 8
12012 a b x + 15015 b x )) / (109395 b )

9
For the third integral we do u= Sen (x)

In[1]:= partes [Sin[x]^10,x,u,Sin[x]^9]

2 8 9
{-9 Cos[x] Sin[x] , u -> Sin[x] , v -> -Cos[x]}

In[2]:= (Sin[x]^9)(-Cos[x])-Integrate[nuevointegrando,x]//Simplify

(2520 x - 2100 Sin[2 x] + 600 Sin[4 x] -


150 Sin[6 x] + 25 Sin[8 x] - 2 Sin[10 x]) / 10240

6
For the fourth integral we do u = ArcSen (x)

In[1]:= partes [ArcSin[x]^6,x,u,ArcSin[x]^6]

5
6 x ArcSin[x] 6
{––––—, u -> ArcSin[x] , v -> x}
2
Sqrt[1 - x ]

In[2]:= (ArcSin[x]6)x-Integrate[nuevointegrando,x]//Simplify

6 (-120 x + x ArcSin[x] +

2 2
120 Sqrt[1 - x ] ArcSin[x] + 60 x ArcSin[x] -

2 3 4
20 Sqrt[1 - x ] ArcSin[x] - 5 x ArcSin[x] +

2 5
Sqrt[1 - x ] ArcSin[x] )
12
For the fifth integral we do u = x

In[1]:= partes [x^12 Cos[x],x,u,x^12]


11 12
{12 x Sin[x], u -> x , v -> Sin[x]}

In[2]:= (x^12)(Sin[x])-Integrate[nuevointegrando,x]//Simplify

12
x Sin[x] - 12 (39916800 x Cos[x] -

3 5
6652800 x Cos[x] + 332640 x Cos[x] -
7 9 11
7920 x Cos[x] + 110 x Cos[x] - x Cos[x] -

2
39916800 Sin[x] + 19958400 x Sin[x] -

4 6
1663200 x Sin[x] + 55440 x Sin[x] -
8 10
990 x Sin[x] + 11 x Sin[x])
Chapter 3.

DEFINITE INTEGRALS. CURVE ARC LENGTH,


AREAS, VOLUMES AND SURFACES OF
REVOLUTION. IMPROPER INTEGRALS
3.1 DEFINITE INTEGRALS

The definite integral acquires its strength when it comes to applying the techniques of
integration to practical problems. Here we present some of the most common applications.
3.2 CURVE ARC LENGTH

One of the most common applications of integral calculus is to find lengths of arcs of a
curve.

For a planar curve with equation , the arc length of the curve between points
with coordinates and is given by the expression:

For a planar curve with parametric coordinates and , the arc length
of the curve between the points corresponding to the values and of the
parameter is given by the expression:

For a curve in polar coordinates with equation , the arc length of the curve
between the points corresponding to the parameter values and is given by the
expression:

For a space curve with parametric coordinates , , , the arc


length of the curve between the points corresponding to the parameter values and
is given by the expression:

For a space curve in cylindrical coordinates with equations ,


, , the arc length of the curve between the points corresponding to the
parameter values and is given by the expression:
For a spacecurve in spherical coordinates with equations given by
, , , the arc length of the curve
between the points corresponding to the values and is given by the
expression:

Exercise 3-1. An electrical cable hangs between two towers which are 80 meters apart.
The cable adopts the shape of a catenary whose equation is:

Calculate the arc length of the cable between the two towers.

Given the symmetry of the curve with respect to the y-axis, the limits of integration will
be - 40 and 40:

In[1]:= f[x_]=100 Cosh[x/100];

In[2]:= Integrate[(1+f’[x]^2)^(1/2),{x,-40,40}]

4 2
100 Sqrt[2] Sqrt[1 + Cosh[-]] Tanh[-]
5 5

In[3]:= N[%]
82.1505

Result: 82.1505 m.

A graphical representation of the problem (Figure 3-1) is made.


Figure 3-1

Exercise 3-2. Calculate the arc length of the space curve represented by the parametric
equations:

between t=0 and t=2.

In[1]:= {x[t_],y[t_],z[t_]}={t,(4/3)t^(3/2),(1/2)t^2}

3/2 2
4t t
{t, ––, —}
3 2

In[2]:= Integrate[(x’[t]^2+y’[t]^2+z’[t]^2)^(1/2),{t,0,2}]

3 Log[3] 3 Log[4 + Sqrt[13]]


-1 + 2 Sqrt[13] + ––— - ––––––-
2 2
In[3]:= N[%]
4.8157

Result: 4.8157.
Exercise 3-3. Find the arc length for values from a = 0 to a = 2pi of the cardioid given in
polar coordinates by r = 3-3cos (a).

In[1]:= r=f[a_]=3-3Cos[a]
3 - 3 Cos[a]

In[2]:= Integrate[(r^2+f’[a]^2)^(1/2),{a,0,2Pi}]
24

Result: 24

Making a graphic representation will have the graph of Figure 3-1.

In[3]:= <<Graphics`Graphics`

In[3]:= PolarPlot[f[a],{a,0,2Pi}]

Figure 3-1
3.3 THE AREA ENCLOSED BETWEEN CURVES

The area enclosed between a curve with equation and the x-axis is given, in
general, by the integral:

where and are the abscissas of the end points of the curve.

If the curve is given in parametric coordinates and , the area is given


by the integral:

where values of the parameter and correspond to the end points of the curve.

If the curve is given in polar coordinates , the area is given by the integral:

for the parameter values and corresponding to the end points of the curve.

To calculate the area between two curves with equations and , we


use the integral:

where and are the abscissas of the end points of the two curves.

When calculating these areas it is very important to take into account the sign of the
functions involved since the integral of a negative portion of a curve will be negative. One
must divide the region of integration so that positive and negative values are not computed
simultaneously. For the negative parts one takes the modulus.
Exercise 3-4. Find the area of the region bounded by the curves defined below:

and

We will have to find the abscissas of the points where the curves meet. Consider the
equation:

In[1]:= Solve[2-x^2==x,x]
{{x -> -2}, {x -> 1}}

Now, we can already find the area that we have to calculate:

In[2]:= Integrate[2-x^2-x,{x,-2,1}]

9
-
2

Result: 4.5 square units:

The graph in Figure 3-2 illustrates the area that we had to calculate:

Plot[{f[x]=2-x^2,g[x]=x},{x,-2,1}]
Figure 3-2

Exercise 3-5. Calculate the area under the normal curve between the limits 1.96 and
1.96.

We need to calculate the integral .

In[1]:= Integrate[E^(-x^2 /2)/(2 Pi)^(1/2),{x,-1.96,1.96}]


0.950004
Graphed the requested area in Figure 3-3

In[2]:= Plot[E^(-x^2 /2)/(2 Pi)^(1/2),{x,-1.96,1.96}]

Figure 3-3

Exercise 3-6. Calculate the area of the ellipse with major and minor axes of length a and
b.
As is known, the equation of this ellipse is:

Rearranging this equation for y and assuming the positive root, we obtain
.

By the symmetry of the ellipse, the area will be four times the integral of this expression

between 0 and a. Therefore we calculate: .

In[1]:=Integrate[(4b(a^2-x^2)^(1/2))/a,{x,0,a}]
a b Pi

The requested result is therefore pab.

Exercise 3-7. Calculate the length of the perimeter and the area enclosed by the curves:

First, in order to get an idea of what the problem is, we graphically represent the curve
(see Figure 3-5):

In[1]:= ParametricPlot[{Cos[t](2-Cos[2t])/4,Sin[t](2+Cos[2t])/4},{t,0,2Pi}]
Figure 3-5

We see that as the parameter ranges between 0 and 2p the curve described is closed. We
can then calculate its length and the area that it encloses.

In[1]:= {x[t_],y[t_]}={Cos[t](2-Cos[2t])/4,Sin[t](2+Cos[2t])/4};

In[2]:= L=Integrate[(x’[t]^2+y’[t]^2)^(1/2),{t,0,2Pi}]
3

The length of the curve is 3 units. To calculate the area, we divide it into four equal
pieces (to prevent positive and negative cancellation), where t varies between 0 and 2p.
The area of each piece will be the absolute value of the integral between 0 and 2p of the
product y(t) * x’(t):

In[3]:= S=4*Integrate[y[t]*x’[t],{t,0,Pi/2}]

(-10 Sqrt[3 Pi] + 9 Sqrt[3 Pi] FresnelS[1] -

Sqrt[Pi] FresnelS[Sqrt[3]]) / (3 Sqrt[6])

In[5]:= Abs[N[%]]

2.65466

Thus, the area enclosed by the curve is 2,65466 square units.


Exercise 3-8. Calculate the length and the area enclosed by each of the following curves
given in polar coordinates:

and

We begin by representing both curves on the same graph (Figures 3-6 and 3-7).

In[1]:= <<Graphics`Graphics`

In[2]:= PolarPlot[ Sqrt[Cos[2 a]], {a,0,2 Pi}]

Figura 3-6

In[3]:= PolarPlot[ Sin[2 a], {a,0,2 Pi}]

Figura 3-7

Now, we calculate the arc lengths and the areas enclosed by both curves. The first curve
repeats the structure for a between 0 and p/4 four times, and the second for a between 0 and
p/2:

In[1]:= r=f[a_]=Sqrt[Cos[2 a]]


Sqrt[Cos[2 a]]

In[2]:= L=4 NIntegrate[Sqrt[f[a]^2+f’[a]^2],{a,0,Pi/4}]


5.24412

In[3]:= S=4(1/2)Integrate[f[a]^2,{a,0,Pi/4}]
1

In[4]:= r=f[a_]=Sin[2 a]
Sin[2 a]

In[5]:= L=4 NIntegrate[Sqrt[f[a]^2+f’[a]^2],{a,0,Pi/2}]


9.68845

In[6]:= S=4(1/2)Integrate[f[a]^2,{a,0,Pi/2}]
Pi

2

Exercise 3-9. Calculate the area enclosed by the curve y = sin(x) and y = cos (x) for x
varying between 0 and 2p.

Figure 3-8 shows the graph of both curves on the same axis, so we can see the points of
intersection and the region between the curves.

In[1]:=Plot[{Sin[x],Cos[x]},{x,0,2 Pi},
PlotStyle->{GrayLevel[0],Dashing[{.01}]}]
Figure 3-8

We need to know the coordinates of the points of intersection of the two curves. To do
this, we solve the system formed by their two defining equations. The command solve does
not solve the problem. Therefore, since the graph indicates that there are solutions in the
intervals (0,1) and (1,2p). We will to find these solutions:

In[2]:= FindRoot[Sin[x]==Cos[x],{x,0.5}]
{x -> 0.785398}

In[3]:= FindRoot[Sin[x]==Cos[x],{x,4}]
{x -> 3.92699}

In[4]:= Abs[Integrate[Cos[x]-Sin[x],{x,0,0.785398}]]+
Abs[Integrate[Cos[x]-Sin[x],{x,0.785398,3.92699}]]+
Abs[Integrate[Cos[x]-Sin[x],{x,3.92699,2 Pi}]]

5.65685

We have I = S1 + abs (S2) + S3 = 5.6569 square units.


3.4 SURFACES OF REVOLUTION

The area of the surface generated by rotating the curve with equation
around the x-axis is given by the integral:

where and are the x-coordinates of the end points of the revolving curve. If the
curve is given in parametric coordinates and and the end points of the
curve correspond to and then the rotational surface area is given by the
integral:

The area of the surface generated by rotating the curve with equation around
the y axis is given by the integral:

Where and are the y-coordinates of the end points of the rotating curve.

Exercise 3-10. Calculate the area of the surface generated by rotating the cubic
around the OX axis, for x between 0 and 5/2.

We represent the surface (Figure 3-9) and calculate area requested.

In[1]:= <<Graphics`SurfaceOfRevolution`

In[2]:= SurfaceOfRevolution[2x^3-9x^2+12x,{x,0,2.5}]
Figure 3-9
In[3]:= f[x_]=2x^3-9x^2+12x;

In[4]:= Abs[2Pi*NIntegrate[f[x]*Sqrt[1+f’[x]^2],{x,0,5/2}]]
1.73127 Pi

Thus the surface of revolution has area 2p(0.8656) = 1.7312 p square units.

Exercise 3-11. Calculate the area of the surface of revolution given by rotating the
parametric curve defined by x (t) = t - sin (t) and y (t) = 1-cos (t) around the OX axis, for
t between 0 and 2p .

We represent the surface (Figure 3-10) and calculate area requested.

In[1]:= {x[t_],y[t_]}={t-Sin[t],1-Cos[t]};

In[2]:= SurfaceOfRevolution[{t-Sin[t],1-Cos[t]},{t,0,2Pi}]
Figure 3-10

In[3]:= 2Pi NIntegrate[y[t]*Sqrt[x’[t]^2+y’[t]^2],{t,0,2Pi}]

21.3333 Pi

The area will be 21.3334p square units.


3.5 VOLUMES OF REVOLUTION

The volume generated by rotating the curve with equation around the x-axis is
given by the integral:

where and are the x-coordinates of the end points of the rotating curve.

The volume generated by rotating the curve with equation around the y-axis is
given by the integral:

where and are the y-coordinates of the end points of the rotating curve.

If one cuts a volume by planes parallel to one of the three coordinate planes (for
example, the plane z=0) and if the equation S(z) of the curve given by the cross section is
given in terms of the distance of the plane from the origin (in this case, z) then the volume is
given by:

Exercise 3-12. Calculate the volume generated by rotating the ellipse


around the OX axis and around the OY axis.

We depict half of each of the generated surfaces of revolution next to each other in
Figure 3-11. The final volume will therefore be twice that of the represented figure.

In[1]:= SurfaceOfRevolution[Sqrt[9(1-x^2 /4)],{x,0,2}]


Figure 3-11

In[2]:= V1=2 Integrate[Pi 9(1-x^2 /4),{x,0,2}]


24 Pi

In[3]:= V2=2 Integrate[Pi 4(1-y^2 /9),{y,0,3}]


16 Pi

Exercise 3-13. Calculate the volume generated by rotating the curve given in polar
coordinates by r = 1 + cos (a) about the OX axis.

The curve is given in polar coordinates, but there is no problem in calculating the values
of and needed to implement the volume formula in cartesian coordinates. We
have:

x (a) = r (a) cos (a) = (1 + cos (a)) cos (a)

y (a) = r (a) sin (a) = (1 + cos (a)) sin (a)

We represent the surface (Figure 3-12) and calculate volume requested.

In[1]:=SurfaceOfRevolution[{(1+Cos[a])Cos[a],(1+Cos[a])Sin[a]},{a,0,Pi}]
Figure 3-12

In[1]:= {x[a_],y[a_]}={(1+Cos[a])Cos[a],(1+Cos[a])Sin[a]};

In[2]:= V=Abs[Pi*Integrate[y[a]^2 D[x[a],a],{a,0,Pi}]]

8 Pi
–-
3

The required volume is p (abs (I)) = 8p/3 cubic units.


3.6 CURVILINEAR INTEGRALS

Let be a continuous vector field in R3 and c: [a, b] ® R3 be a continuous

differentiable curve in R3. We define , and call it the integral of along the curve
c, as follows:

Exercise 3-14. Consider the curve with , and the


vector field . Calculate

In[1]:= F[x_,y_,z_]=x i+y j+z k;

In[2]:= F[Sin[t],Cos[t],t]

k t + j Cos[t] + i Sin[t]

In[3]:={Sin[t],Cos[t],t}.D[{Sin[t],Cos[t],t},t]

In[4]:= Integrate[t,{t,0,2Pi}]

2
2 Pi

Exercise 3-15. Consider the curve c defined by the parametric equations:


Calculate .

In[1]:= {x[a_],y[a_],z[a_]}={Cos[a]^3,Sin[a]^3,a}

3 3
{Cos[a] , Sin[a] , a}

In[2]:= D[%,a]

2 2
{-3 Cos[a] Sin[a], 3 Cos[a] Sin[a] , 1}

In[3]:= Integrate[ % . {Sin[a],Cos[a],-Cos[a] Sin[a]},{a,0,7Pi/2}]

1
-(-)
2

Exercise 3-16. Let the curve c be the circle of radius a: x2 + y2 =a2. Calculate the value of

First, the circle can be parameterized (x = a cos (t), y = a sin (t)) and we can then
calculate the integral as follows:

In[1]:= {x[t_],y[t_]}={a Cos[t], a Sin[t]}

{a Cos[t], a Sin[t]}

In[2]=Integrate[(a Cos[t])^3 D[a Sin[t],t]-(a Sin[t])^3 D[a Cos[t],t],{t,0,2Pi}]


4
3 a Pi
––-
2
3.7 IMPROPER INTEGRALS

Mathematica works with improper integrals in the same way as it works with any other
type of definite integral. We will not discuss theoretical issues concerning the convergence
of improper integrals here, but within the class of improper integrals we will distinguish two
types:

1) Integrals with infinite limits: the domain of definition of the integrand is a half-line
[(a,¥) or (-¥, a)] or the entire line (-¥,¥).

2) Integrals of discontinuous functions: the given function is continuous in an interval


[a, b] except at finitely many so-called isolated singularities.

Complicated combinations of these two cases may also occur. One can also generalize
this to the more general setting of Stieltjes integrals, but to discuss this would require a
course in mathematical analysis.

Exercise 3-17. Calculte the following integrals:

Mathematica calculate, if possible, improper integrals directly. In this exercise, we will


check the convergence of the integrals and certify that its value matches the calculated
directly by Mathematica.

In[1]:= Limit[Integrate[1/x^2,{x,a,b}],b->Infinity]
1
-
a

In[2]:= Integrate[1/x^2,{x,a,Infinity}]
1
-
a

In[3]:= Limit[Integrate[1/(x^4 +1),{x,0,b}],b->Infinity]


Pi
–––
2 Sqrt[2]

In[4]:= Integrate[1/(x^4 +1),{x,0,Infinity}]


Pi
–––
2 Sqrt[2]

In[5]:= Limit[Integrate[1/(x^2 +1)^2,{x,0,b}],b->Infinity]


Pi

4
Integrate[1/(x^2 +1)^2,{x,0,Infinity}]
Pi

4

Exercise 3-18. Calculte the following integrals:


In[1]:= Integrate[(1-E^(-x^2))/x^2,{x,0,Infinity}]
Sqrt[Pi]

In[2]:= Integrate[E^(-x) Sin[x]/x,{x,0,Infinity}]

Pi

4
It is therefore two convergent improper integrals

Exercise 3-19. Calculte the following integrals:

b p/2 8 1/3 2 2
ò 1/Öx dx ò Tan(x)dx ò 1/ x dx ò 2x/(x - 1) dx
0 0 -1 -2

The first comprehensive presents a unique singular point at x = 0, then it is zero in an


environment where there may be problems.

In[1]:= Limit[Integrate[1/Sqrt[x],{x,a,b}],a->0]
2 Sqrt[b]
In[2]:= Integrate[1/Sqrt[x],{x,0,b}]
2 Sqrt[b]
The first integral is convergent and its value is 2Öb.

The second of the integrals have one singular point at x=p/2

In[3]:= Limit[Integrate[Tan[x],{x,0,Pi/2-b}],b->0]
Infinity

The integral is divergent. If we try to find its value directly with Mathematica gives us
undetermined.

In[4]:= Integrate[Tan[x],{x,0,Pi/2}]
Indeterminate

The third integral presents a unique singular point at x = 0, which is within the range
(-1.8).

In[5]:= Limit[Integrate[1/(x)^(1/3),{x,-1,-b}],b->0]+
Limit[Integrate[1/(x)^(1/3),{x,c,8}],c->0]

2/3
3 (-1)
6 - –––
2
The above value is 9.2, which is integral convergent.

In[6]:= Integrate[1/(x)^(1/3),{x,-1,8}]

2/3
3 (-1)
6 - –––
2
The last integral has two singular points x = -1 and x = 1 that are internal to the interval
(-2.2)

In[7]:= Limit[Integrate[2x/(x^2-1),{x,-2,-1-b}],b->0]+
Limit[Limit[Integrate[2x/(x^2-1),{x,-1+c,1-d}],c->0],d->0]+
Limit[Integrate[2x/(x^2-1),{x,1+e,2}],e->0]

Indeterminate

In[8]:= Integrate[2x/(x^2-1),{x,-2,2}]

Indeterminate

The integral is divergent.


3.8 PARAMETER DEPENDENT INTEGRALS

Consider the function of the variable : defined in the interval


, where the function is continuous in the rectangle with
continuous partial derivative with respect to y in the rectangle, then for all y such that
we have:

This result is very important, because it allows us to differentiate an integral by


differentiating under the integral sign.

Integrals dependent on a parameter can also be improper, and in addition the limits of
integration may also depend on a parameter.

If the limits of integration depend on a parameter, we have the following:

provided and are defined on the interval and have continuous derivatives
and , and the curves and are contained in the rectangle .

Also, if the function is defined on the interval and is


continuous in the rectangle , then the following holds:

i.e. integration under the integral sign is valid, and the order in which the integrals are
evaluated can be reversed without affecting the result.
Exercise 3-20. Solve the following integrals using a parameter :

For the first integral, we will start by integrating the derivative of the integrand with
respect to the parameter , which will be easier to integrate. Once this integral is found we
integrate with respect to to find the original integral.

In[1]:= Integrate[D[ArcTan[a x]/(x(1+x^2)),a],{x,0,Infinity}]//PowerExpand


2
(-a + a ) Pi
––––-
2
2 a (-1 + a )

Now we integrate this function with respect to the variable a, to find the original integral:

In[2]:= Integrate[%,a]

Pi Log[1 + a]
––––-
2

To solve the second integral, we consider the following, using as a parameter:

As in the first integral, we differentiate the integrand with respect to the parameter , find
the integral, and then integrate with respect to . The desired integral is then given by setting
.
In[1]:= Integrate[D[(1-E^(-a x^2))/x^2,a],{x,0,Infinity}]

Sqrt[Pi]
–––
2 Sqrt[a]

In[2]:= s[a_]=Integrate[%,a]
Sqrt[a] Sqrt[Pi]

In[3]:= s[1]
Sqrt[Pi]
3.9 THE RIEMANN INTEGRAL
The definite integral of a function gives the total area between the graph of the
function and the x-axis contained between the two limits of integration, where areas under
the x-axis are regarded as negative.

Riemann defined this integral as a certain limit. Given a partition of the domain of the
function into intervals one can define two associated values, the upper sum and the lower
sum. The upper sum is the sum of the areas of the rectangles with bases the intervals of the
partition and heights given by the maximum of the function in the interval. The lower sum
is similarly defined except the height of the rectangle is determined by the minimum of the
function in the interval. Thus there are infinitely many upper sums and infinitely many
lower sums. One can define the upper integral to be the infimum of the upper sums and the
lower integral to be the supremum of the lower sums. If these two values are equal, then the
function is Riemann integrable and the common value is its integral.

By dividing the domain into a large number of intervals with small widths one can
approximate the integral. This method can be used when the integrand cannot be integrated
algebraically.

If the function y = f (x) we have to integrate is positive and continuous on the interval [a,
b] of integration, the upper and lower sums can be calculated with the following
Mathematica expressions:

suminf[f_,{a_,b_},n_]:= (b-a)/n Sum[f[a + k(b-a)/n],{k,0,n-1}]//N

sumsup[f_,{a_,b_},n_]:= (b-a)/n Sum[f[a + k(b-a)/n],{k,1,n}]//N

If the function we have to integrate is negative in certain subsets of its domain, we take the
modulus of the function for the purpose of computing the integral and finding areas. One can
apply this directly to the function without having to determine the subintervals on which it is
negative.

Exercise 3-21. Approximate the value of the following integral:


To approximate the integrals, we partition the range of integration into n intervals, find
the middlesum, and then find the limit of these sums as n tends to infinity:

First we made a plot to get an idea of the problem (Figure 3-13).

In[1]:= Plot[1/Log[x],{x,1.1,5}]

Figura 3-13

We approximate the integral value using 100 rectangles and considering the upper and
lower amounts.

In[2]:= <<Algebra`SymbolicSum`

In[3]:= f[x_]=1/Log[x]

1
––
Log[x]

In[4]:= (5-2)/100 Sum[f[2+(5-2)k/100],{k,1,100}]//N


2.57718

In[5]:= (5-2)/100 Sum[f[2+(5-2)k/100],{k,0,99}]//N


2.60182

The value of the integral is a number between 2.57718 and 2.60182.

Exercise 3-22. Approximate the value of the following integral:

First we made a plot to get an idea of the problem (Figure 3-14).

In[1]:= Plot[Sin[x^2],{x,0,4}]

Figure 3-14

Since there are areas above and below the x axis must be considered in the function
module to subtract areas not to try to add them. We estimate 1,000 rectangles and the upper
and lower Riemann sums. The actual value of the integral will be a number between these
two sums. Keep in mind that the function has positive and negative areas, so it is necessary
to consider its module.
In[2]:= <<Algebra`SymbolicSum`

In[3]:= f[x_]=Sin[x^2];

In[4]:= (4-0)/1000 Sum[Abs[f[0+(4-0)k/1000]],{k,1,1000}]//N

1.75381
In[5]:= (4-0)/1000 Sum[Abs[f[0+(4-0)k/1000]],{k,0,999}]//N

1.75152

Then the exact value of the integral problem will be a number between 1.75381 and
1.75152.

The exact value can be calculated considering n intervals and finding the limit when n
has infinite sums upper and lower amounts. Should match this limit, the integral value is to
limit calculated precisely.

Exercise 3-23. Calculate the value of the integral:

5 2
ò (1 + 12 x - x )

In[1]:= f[x_]=1+12x-x^2;

In[2]:= Limit[(5-2)/n Sum[f[2+(5-2)k/n],{k,1,n}], n->Infinity]


90

In[3]:= Limit[(5-2)/n Sum[f[2+(5-2)k/n],{k,0,n-1}], n->Infinity]


90

We have now calculated the exact value of the integral, as the limit of the upper and
lower amounts of Rieman agree limit value.
Chapter 4.

INTEGRATION IN SEVERAL VARIABLES AND


APPLICATIONS. AREAS AND VOLUMES.
DIVERGENCE, STOKES AND GREEN’S
THEOREMS
In this chapter we will describe how to solve multivariate integrals with Mathematica,
and give applications of double and triple integrals to calculate areas and volumes. We
also give some other typical applications of multivariate integral calculus.
The relevant Mathematica functions have already been introduced in the previous
chapter. They are the following:

Integrate[f[x],x] Computes the indefinite integral

Integrate[f[x,y],{x,y}] Computes the double integral


Integrate[f[x,y, …, z],{x,y, …,z}]

Computes

Integrate[f[x],{x,a,b}] Computes the definite integral


NIntegrate[f[x],{x,a,b}]

Computes, using approximate methods, the definite integral

Integrate[f[x,y],{x,a,b},{y,c,d}}]

Computes the definite double integral

NIntegrate[f[x,y],{x,a,b},{y,c,d}}]
Computes, using approximate methods, the definite double integral

Integrate[f[x,y,…, z],{x,a,b},{y,c,d},…,{z,e,f}]

Computes

NIntegrate[f[x,y,…, z],{x,a,b},{y,c,d},…,{z,e,f}]

Computes, using approximate methods, the definite integral


4.1 AREAS AND DOUBLE INTEGRALS

If we consider an enclosure S, we can find its area through the use of double integrals.
If the area S is determined by boundary curves whose equations are given in cartesian
coordinates, its area A is given by the formula:

If, for example, S is determined by and , the area will be:

If S is determined by and , the area will be:

If the region S is determined by curves whose equations are given in polar coordinates
with radius vector and angle , its area is given by the formula:

If, for example, S is determined by and then

Exercise 4-1. Calculate the area of the region above the OX axis bounded by the OX
axis, the parabola y2 = 4 x and the line x + y = 3.

First, we create a graphical representation of the problem, which is presented in Figure


4-1:

In[1]:= Plot[{y=0,y=Sqrt[4x],y=3-x},{x,-1,4}]
Figure 4-1

We see that in the enclosed region y is limited between 0 and 2 (0 < y < 2) and x is
limited between the curves x =( y ^ 2)/4 and x = 3 - y. We calculate the requested area as
follows:

Abs[Integrate[1 Integrate[1,{x,y^2/4,3-y}],{y,0,2}]]

10

3

Exercise 4-2. Calculate the area in the first quadrant bounded between the semicubical
parabola y2 = x3 and the bisector of the first quadrant.

First, we graphically represent the problem (see Figure 4-2):

In[1]:= Plot[{y=Sqrt[x^3],y=x},{x,-1/4,5/4}]

Figure 4-2
Inspecting the graph we see that the enclosed area is defined for x ranging between 0
and 1 (0 <x< 1) and y ranging between the curves y = x and y = x ^(3/2). Therefore the
area of the requested region can be calculated as:

In[2]:= Abs[Integrate[1 Integrate[1,{y,x^(3/2),x}],{x,0,1}]]

1

10

Exercise 4-3. Calculate the area outside the circle with polar equation r = 2, and inside
the cardioid with polar equation r = 2 (1 + cos (a)).

First, we graphically represent the problem (see Figure 4-3):

In[1]:= <<Graphics`Graphics`

In[2]:= PolarPlot[{2,2(1+Cos[a])},{a,0,2Pi}]

Figure 4-3

Inspecting the graph, we see that, by symmetry, we can calculate half of the required
area by varying a between 0 and Pi/2 (0 <a<Pi/2) and r between the curves r = 2 and r =
2 (1 + cos (a)):

In[1]:= 2Integrate[1 Integrate[r,{r,2,2(1+Cos[a])}],{a,0,Pi/2}]


8 + Pi

The required area is therefore p + 8 square units.


4.2 SURFACE AREA BY DOUBLE INTEGRATION

The surface area of a surface defined by , where ranges over a


region in the OXY plane, is given by:

The surface area of a surface defined by , where ranges over a


region in the OYZ plane, is given by:

The surface area of a surface defined by , where ranges over a


region in the OXZ plane, is given by:

Exercise 4-4. Calculate the area of the surface of the cone x2 + y2 = z2, limited above
the OXY plane and cut by the cylinder x2 + y2 = b y.

The projection of the surface onto the OXY plane is the disc bounded by the circle with
equation x2+ y2= by. Then we can find the surface area via the first formula above as
follows:

In[1]:= Clear[x,y,z]
In[2]:= z[x_,y_]=Sqrt[(x^2+y^2)/a];
In[3]:= Integrate[Integrate[Sqrt[1+D[z[x,y],x]^2+D[z[x,y],y]^2],
{x,-Sqrt[b y-y^2],Sqrt[b y-y^2]}],{y,0,b}]
1
(1 + -) a b
3/2 a
(1 + a) b Sqrt[–––—] Pi
1+a
–––––––––––
1
4 Sqrt[1 + -] a
a

In[4]:= Simplify[%]

2
(1 + a) b Pi
–––––
1
4 Sqrt[1 + -] a
a

Exercise 4-5. Calculate the area of the paraboloid x2 + y2 = 2 z limited below the plane
z = 2.

In[1]:= Clear[x,y,z]

In[2]:= z[x_,y_]=(x^2+y^2)/2;

In[3]:= Sqrt[1+D[z[x,y],x]^2+D[z[x,y],y]^2]

2 2
Sqrt[1 + x + y ]
This expression is suitable for a transformation to polar coordinates:

In[4]:= f=% /. {x->r Cos[a],y->r Sin[a]}//Simplify

2
Sqrt[1 + r ]

The requested integral is calculated as 4 times the integral delimited by the first
quadrant of the circle r = 2 :

In[5]:= (4/2)Integrate[Integrate[r f,{r,0,2}],{a,0,Pi/2}]

(-1 + 5 Sqrt[5]) Pi
––––––-
3

The result of the integral will be 4 times the previous value, i.e.
2(5Ö5-1)p/3.

Figure 4-4 shows the graphical representation of the problem:

In[1]:= Plot3D[f[x,y]=(x^2+y^2)/2,{x,-3,3},{y,-3,3}] ;

In[2]:= Plot3D[f[x,y]=2,{x,-3,3},{y,-3,3}]

In[3]:= Show[%,%%]
Figure 4-4
4.3 VOLUME CALCULATION BY DOUBLE INTEGRALS

The volume of a cylindroid limited in its upper part by the surface with equation
, its lower part by the OXY plane and laterally by the straight cylindrical
surface which cuts the OXY plane bordering a region , is:

The volume of a cylindroid limited in its upper part by the surface with equation
, its lower part by the OYZ plane and laterally by the straight cylindrical
surface which cuts the OYZ plane bordering a region , is:

The volume of a cylindroid limited in its upper part by the surface with equation
, its lower part by the OXZ plane and laterally by the straight cylindrical surface
which cuts the OXZ plane bordering a region , is:

Exercise 4-6. Calculate the volume in the first octant bounded between the OXY plane,
the plane z = x + y + 2 and the cylinder x2 + y2 = 16.

We begin by graphically representing the problem (see Figure 4-5) with the the plane in
cartesian coordinates and parameterizing the cylinder:

In[1]:= ParametricPlot3D[{4Cos[t],4Sin[t], z},{t,0,2Pi},{z,0,10}];

In[2]:= Plot3D[f[x,y]=x+y+2,{x,-4,4},{y,-4,4}];
Now we represent the two surfaces on the same graph:
Figure 4-5

The required volume is then given by the integral:

In[1]:= Integrate[Integrate[x+y+2,{y,0,Sqrt[16-x^2]}],{x,0,4}]

128
– + 8 Pi
3

Exercise 4-7. Calculate the volume bounded by the paraboloid x2 + 4 y2 = z and


laterally by the cylinders with equations y2 = x and x2 = y.

First, we graphically represent the problem (see Figure 4-6):

In[1]:= ParametricPlot3D[{t^2,t, z},{t,-1/2,1/2},{z,-1/2,1/2}]

In[2]:= Plot3D[f[x,y]=x^2+4y^2,{x,-1/2,1/2},{y,-1/4,1/4}]

In[3]:= Show[%,%%,%%%]
Figure 4-6

The volume is calculated via the following integral:

In[4]:= Integrate[Integrate[x^2+4y^2,{y,x^2,Sqrt[x]}],{x,0,1}]

3
-
7
4.4 VOLUME CALCULATION AND TRIPLE INTEGRALS

The volume of a three-dimensional region whose boundary surface equations are


expressed in cartesian coordinates is given by the triple integral:

The volume of a three-dimensional region whose boundary surface equations are


expressed in cylindrical coordinates is given by the triple integral:

The volume of a three-dimensional region whose boundary surfaces equations are


expressed in spherical coordinates is given by the triple integral:

Exercise 4-8. Calculate the volume bounded by the paraboloid x2 + y2 = z and the
cylinder with equation z = a2 - y2.

The volume will be four times the following integral:

In[1]:=4Integrate[Integrate[Integrate[1,{z,ax^2+y^2,a^2-y^2}],
{y,0,Sqrt[(a^2-a x^2)/2]}],{x,0,Sqrt[a]}]

17/4
a Pi
––––––—
3/2
2 Sqrt[2] Sqrt[a ]
In[2]:=PowerExpand[%]

7/2
a Pi
–––
2 Sqrt[2]

Exercise 4-9. Calculate the volume bounded by the cylinders z = x2 and 4 - y2 = z.

First, we graphically represent the problem (see Figure 4-7):

In[1]:= Plot3D[f[x,y]=x^2,{x,-2,2},{y,-2,2}]

In[2]:= Plot3D[f[x,y]=4 - y^2,{x,-2,2},{y,-2,2}]

In[3]:= Show[%,%%]

Figure 4-7

The volume will be four times the following integral:

In[1]:=4Integrate[Integrate[Integrate[1,{z,x^2,4-y^2}],
{y,0,Sqrt[4-x^2]}], {x,0,2}]

8 Pi

The final result for the volme is therefore 8p.

Exercise 4-10. Calculate the volume enclosed by the cylinder r = 4cos(a), the plane z =
0 and the sphere with equation r2 + z2 = 16.

The volume of the enclosure, given in cylindrical coordinates, is:

In[1]:= Integrate[Integrate[r*Integrate[1,{z,0,Sqrt[16-r^2]}],
{r,0,4Cos[a]}],{a,0,Pi}]
128 64 (-2 + 3 Pi)
-(–) + ––––—
9 9

In[2]:= Simplify[%]

64 (-4 + 3 Pi)
––––—
9

Exercise 4-11. Calculate the volume enclosed by the cone b = π/4 and the sphere with
equation r = 2 k cos (b).

The volume of the enclosure, given in spherical coordinates, will be four times the
result of the following integral:

In[1]:= 4Integrate[ Integrate[Integrate[r^2 Sin[b],


{r,0,2k Cos[b]}], {b,0,Pi/4}],{a,0,Pi/2}]
3
k Pi

The final result is therefore k3p.


4.5 GREEN’S THEOREM

Let C be a simple closed planar curve, and R the region consisting of C and its interior.
If f and g are continuous functions with continuous first partial derivatives in an open set
D containing R, then:

Exercise 4-12. Calculate the following integral using Green’s theorem:

where C is the boundary of the region enclosed by the parabolas y = x2 , x = y2.

The two parabolas intersect at the points (0,0) and (1,1). We graphically represent
the problem (see Figure 4-8) and calculate the integral:

In[1]:= Plot[{x^2,Sqrt[x]},{x,0,1.2}]

Figura 7-8

In[2]:= m[x_,y_]=x+E^Sqrt[y];

In[3]:= n[x_,y_]=2y+Cos[x];
In[4]:=Integrate[Integrate[D[n[x,y],x]-D[m[x,y],y],{y,x^2,Sqrt[x]}],
{x,0,1}]

Pi 2
-26 + 8 E + 2 Cos[1] - Sqrt[—] FresnelC[Sqrt[—]] +
2 Pi

2
Sqrt[x ]
Integrate[E , {x, 0, 1}] + 2 Sin[1]

Using the command Nintegrate the approximate solution is obtained

» numeric(int(int(‘diff(n(x,y),x)-diff(m(x,y),y)’,‘y’,‘x^2’,‘sqrt(x)’),‘x’,0,1))

In[4]:=NIntegrate[NIntegrate[D[n[x,y],x]-D[m[x,y],y],{y,x^2,Sqrt[x]}],
{x,0,1}]

-0.6764
4.6 THE DIVERGENCE THEOREM

Let Q be a domain with the property that each straight line passing through a point
inside a domain cuts its border at exactly two points. In addition, suppose the boundary S
of the domain Q is a closed oriented surface with exterior normal vector n. If f is a vector
field that has continuous partial derivatives on Q, then:

The left-hand side of this equality is called the outflow of the vector field f across the
surface S.

Exercise 4-13. Use the divergence theorem to find the outflow of the vector field f =
(xy+x2 , yz+xy2 , z z, xz+xyz2 ) across the surface of the cube in the first octant bounded
by the planes x = 2, y = 2 and z = 2.

In[1]:=<<Calculus`VectorAnalysis`

In[2]:= f[x_,y_,z_]={x y+x^2 z y, y z+x y^2 z, x z+x y z^2}


2 2 2
{x y + x y z, y z + x y z, x z + x y z }

In[3]:= divf[x_,y_,z_]=Div[f[x,y,z],Cartesian]

x+y+z+6xyz

In[4]:=Integrate[divf[x,y,z],{x,0,2},{y,0,2},{z,0,2}]

72
4.7 STOKES’ THEOREM

Let S be an oriented surface of finite area defined by a function f(x,y), having boundary
C with unit normal n. Suppose F is a continuous vector field defined on S such that the
component functions of F have continuous partial derivatives at each non-boundary point
of S. Then:

Exercise 4-14. Use Stokes’ theorem to evaluate the line integral:

where C is the intersection of the cylinder x2 + y2 = 1 and the plane x + y + z = 1, and the
orientation of C corresponds to counterclockwise rotation of the OXY plane.

The curve C bounds the surface S defined by z = 1-x-y = f(x,y) for (x, y) in the domain
D = {(x,y) / x2 + y2= 1}.

We put F= - y 3 i + x 3 j - z 3 k.

Now, we calculate the curl of F and integrate over the surface S:

In[1]:= F={-y^3,x^3,z^3}

3 3 3
{-y , x , z }

In[2]:= Curl[F]

2 2
{0, 0, 3 x + 3 y }
Therefore, we have to calculate the integral òD (3 x2+ 3y2 ) dx dy. Changing to polar
coordinates, we obtain:

In[2]:= 3Integrate[Integrate[r^3, {a,0,2Pi}],{r,0,1}]

3 Pi
–-
2
Chapter 5.

FIRST ORDER DIFFERENTIAL EQUATIONS.


SEPARATES VARIABLES, EXACT EQUATIONS,
LINEAR AND HOMOGENEOUS EQUATIONS.
NUMERIACAL METHODS
Although it implements only a relatively small number of commands related to this
topic, Mathematica treatment of differential equations is nevertheless very efficient. We
shall see how we can use these commands to solve each type of differential equation
algebraically. Numerical methods for the approximate solution of equations and systems
of equations are also implemented.

Solving differential equations in partial derivatives is also possible with the program.
The packages are Calculus`PDSolve` and Calculus`PDSolve1`. The first increases the
number of equations to be solved directly with the DSolve function, and the second
implemeta functions to solve partial differential equations..

The most important Mathematica commands that solve differential equations are the
following:

DSsolve(equation, y[x], x) Solves the given differential equation for y[x]. This
returns only explicit solutions.

DSolve({equ1, equ2,…}, {y1, y2,…}, x)

Solve de list of differential equations


DSsolve(equation, initial conditions, y[x], x)

Solves the given differential equation subject to the specified


initial condition

Examples are given below.

In[1]:= DSolve[2y’[x]+2y[x]==1,y[x],x]
1 C[1]
{{y[x] -> - + –-}}
2 x
E

In[2]:= DSolve[{y[x]==-z’[x],z[x]==-y’[x]},{y,z},x]//Simplify

{{y -> Function[x,

2x 2x
C[1] + E C[1] + C[2] - E C[2]
–––––––––––—],
x
2E

z -> Function[x,

2x 2x
C[1] - E C[1] + C[2] + E C[2]
–––––––––––—]}}
x
2E

In[3]:= DSolve[{3y’[x]==2y[x],y[0]==1},y[x],x]

(2 x)/3
{{y[x] -> E }}
5.1 SEPARATION OF VARIABLES

A differential equation is said to have separable variables if it can be written in the form f(x)
dx = g(y) dy.

This type of equation can be solved immediately by putting ò f(x) dx = ò g(y) dy + C.

If Mathematica cannot directly solve a differential equation with the function DSolve, then
we can try to express it in the above form and solve the given integrals algebraically, which
does not present particular difficulties for the program, given its versatility in symbolic
computation.

Exercise 5-1. Solve the differential equation:

y cos(x) dx -(1 + y2 ) dy = 0, y(0) = 1.

First of all we try to solve it directly. The equation can be written in the form:

In[1]:= ecuacion=y’[x]==y[x] Cos[x]/(1+y[x]^2)


In[2]:= DSolve[ecuacion,y[x],x]

Solve::tdep:
The equations appear to involve transcendental
functions of the variables in an essentially
non-algebraic way.
Solve::tdep:
The equations appear to involve transcendental
functions of the variables in an essentially
non-algebraic way.
2
y[x]
Solve[Log[y[x]] - Sin[x] + –— == C[1], y[x]]
2

Thus the differential equation appears not to be solvable with DSolve. However, in this
case, the variables are separable, so we can solve the equation as follows:

In[1]:= solucion=Integrate[Cos[x],x]==Integrate[(1+y^2)/y,y]+c

2
y
Sin[x] == c + — + Log[y]
2

In[2]:= constante=solucion /. {x->0,y->1}

1
0 == - + c
2

In[3]:= Solve[constante]

1
{{c -> -(-)}}
2

In[4]:= Soluciongeneral=solucion /. c->1/2

2
1 y
Sin[x] == - + — + Log[y]
2 2
5.2 HOMOGENEOUS DIFFERENTIAL EQUATIONS

Consider a general differential equation of first degree and first order of the form

M(x,y) dx = N(x,y) dy.

This equation is said to be homogeneous of degree n if the functions M and N satisfy:

M(tx, ty) = t n M(x,y),

N(tx, ty) = t n N(x,y).

For this type of equation, we can transform the initial differential equation (with
variables x and y), via the change of variable x = vy, into another (separable) equation
(with variables v and y). The new equation is solved by separation of variables and then
the solution of the original equation is found by reversing the change of variable.

Exercise 5-2. Solve the differential equation:

(x 2 - y2) dx + x y dy = 0.

We are trying to solve the equation directly with DSolve.

In[1]:= ecuacion=x y y’[x]==y[x]^2-x^2;

In[2]:=DSolve[ecuacion,y[x],x]

2 2
DSolve[x y y’[x] == -x + y[x] , y[x], x]

The DSolve function not offers solution, so let’s solve the equation by ordinary
algebraic method.
First we check if the equation is homogeneous:
In[3]:= m[x_,y_]=x^2-y^2;

n[x_,y_]=x y;

In[4]:= m[t x,t y]//Factor

2
t (x - y) (x + y)

In[5]:= n[t x,t y]//Factor

2
t xy

Thus the equation is homogeneous of degree 2. To solve it we apply the change of


variable x = vy.

In[6]:= expresion1=m[x,y]Dt[x]+n[x,y]Dt[y]

2 2 2 2
v y Dt[y] + (-y + v y ) (y Dt[v] + v Dt[y])

In[7]:= x=v y;

In[8]:= expresion2=expresion1//ExpandAll

3 2 3 3 2
-(y Dt[v]) + v y Dt[v] + v y Dt[y]

In[9]:= expresion3=Collect[expresion2,{Dt[v],Dt[y]}]
3 2 3 3 2
(-y + v y ) Dt[v] + v y Dt[y]

If we divide the previous expression by v3y3, and group the terms in d(v) and d(y), we
already have an equation in separated variables.

In[10]:= expresion4=Cancel[Apart[expresion3/(y^3 v^3)]]

2
(-1 + v ) Dt[v] Dt[y]
––––– + –—
3 y
v

Now, we solve the equation:

In[11]:=expresion5=Integrate[(v^2-1)/v^3,v]+Integrate[1/y,y]

1
–- + Log[v] + Log[y]
2
2v

Finally we reverse the change of variable:

In[12]:= Clear[x,v,y]

In[13]:= expresion6=expresion5 /. v->x/y //PowerExpand

2
y
–- + Log[x]
2
2x

In[14]:= solucion=expresion6==c

2
y
–- + Log[x] == c
2
2x

Thus the general solution of the original differential equation is:

Now we can represent the solutions of this differential equation graphically. To do this
we graph the solutions with parameter C, which is equivalent to the following contour plot
of the function defined by the left-hand side of the above general solution (see Figure 5-1):

In[15]:= ContourPlot[y^2/(2 x^2) + Log[x],{x,0.1,3},{y,-5,5},


PlotRange->{-3,10},ContourShading->False,Frame->False,
Axes->Automatic,AxesOrigin->{0,0}]

Figure 5-1
5.3 EXACT DIFFERENTIAL EQUATIONS

The differential equation

M(x,y) dx+N(x,y) dy = 0

is said to be exact if ¶N/¶x = ¶M/¶y. If the equation is exact, then there exists a function F
such that its total differential dF coincides with the left-hand side of the above equation,
i.e.:

dF = M(x,y) dx+N(x,y) dy

therefore the family of solutions is given by F(x,y) = C.

The exercise below follows the usual steps of an algebraic solution to this type of
equation.

Exercise 5-3. Solve the differential equation:

(-1 + y exy + y cos(xy)) dx +(1 + x exy + x cos(xy)) dy = 0.

First, we try to solve the equation with DSolve:

In[1]:= m[x_,y_]=-1+y E^(x y)+y Cos[x y];


In[2]:= n[x_,y_]=1+x E^(x y)+x Cos[x y];
In[3]:= ecuacion=DSolve[m[x,y[x]]+n[x,y[x]]*y’[x]==0,y[x],x]

Solve::tdep:
The equations appear to involve transcendental
functions of the variables in an essentially
non-algebraic way.
Solve::tdep:
The equations appear to involve transcendental
functions of the variables in an essentially
non-algebraic way.
x y[x]
Solve[E - x + Sin[x y[x]] + y[x] == C[1], y[x]]

Thus the function DSolve does not give a solution to the proposed equation. We are
going to try to solve the equation using the classical algebraic method.

First we check that the proposed differential equation is exact.

In[4]:= D[m[x,y],y]==D[n[x,y],x]
True

Since the equation is exact, we can find the solution in the following way:

In[5]:= solucion1=Integrate[m[x,y],x]+g[y]

xy
E - x + g[y] + Sin[x y]

Now we find the function g(y) via the following condition:

diff(int(m(x,y), x) + g(y), y) = n(x,y).

In[6]:= expresion1=D[solucion1,y]

xy
E x + x Cos[x y] + g’[y]

In[7]:=Solve[expresion1==n[x,y],g’[y]]

{{g’[y] -> 1}}


The final solution is:
In[8]:= solucion=solucion1 /. g[y]->Integrate[1,y]

xy
E - x + y + Sin[x y]

To graphically represent the family of solutions, we draw the following contour plot of
the above expression (Figure 5-2):

In[9]:=ContourPlot[solucion,{x,-Pi,Pi},{y,-Pi,Pi},
PlotRange->{-10,10},ContourShading->False]

Figure 5-2

In the following section we will see how any reducible differential equation can be
transformed to an exact equation using an integrating factor.
5.4 LINEAR DIFFERENTIAL EQUATIONS

A linear first order differential equation is an equation of the form:

dy/dx + P(x) y = Q(x)

where P(x) and Q(x) are given functions of x.

Differential equations of this type can be transformed into exact equations by


multiplying both sides of the equation by the integrating factor:

and the general solution is then given by the expression:

.
Mathematica implements these solutions of linear differential equations, and offers
them whenever the integral appearing in the integrating factor can be found.

Exercise 5-4. Solve the differential equation:

x dy/dx + 3 y = x sin(x).

Make the graphs of the solutions to the following constant values: -6,-4,-2,0,2,4,6

In[1]:= solucion=DSolve[x y’[x]+3y[x]==x Sin[x], y[x],x]

C[1]
{{y[x] -> –- +
3
x

3 2
6 x Cos[x] - x Cos[x] - 6 Sin[x] + 3 x Sin[x]
–––––––––––––––—}}
3
x

In[2]=Plot[Evaluate[Table[solucion[[1,1,2]] /.C[1]->
{i,-6,6,2,-2,4,-4,0}]], {x,0.01,3Pi/2}, PlotRange->{-5,5}]

Figure 5-3
5.5 NUMERICAL SOLUTIONS TO DIFFERENTIAL
EQUATIONS OF THE FIRST ORDER

Mathematica enable the DSolve function that calculates numerical solutions of


differential equations equation approaches. This function is very useful, especially in
nonlinear equations. The function syntax is:

NDSolve[{ecuacion, condiciones iniciales}, {x, xmin, xmax}]

Exercise 5-5. Solve and graph the solution of the differential equation:

dy/dx = Sen(2x - y) y(0)=0.5 in the interval [0,15]

In[1]:= ecuation=y’[x]==Sin[2x-y[x]];

In[2]:= solution=NDSolve[{ecuation,y[0]==0.5},y[x],{x,0,15}]

{{y[x] -> InterpolatingFunction[{0., 15.}, <>][x]}}

Now we plot the function obtained as a solution (Figure 5-4)

In[3]:= Plot[y[x] /. solucion, {x,0,15}]

Figure 5-4
Chapter 6.

HIGH-ORDER DIFFERENTIAL EQUATIONS AND


SYSTEMS OF DIFFERENTIAL EQUATIONS
6.1 ORDINARY HIGH-ORDER EQUATIONS

An ordinary linear differential equation of order n has the following general form:

If the function is identically zero, the equation is called homogeneous. Otherwise,


the equation is called non-homogeneous. If the functions are constant,
the equation is said to have constant coefficients.

A concept of great importance in this context is that of a set of linearly independent


functions. A set of functions is linearly independent if, for any in
their common domain of definition, the Wronskian determinant of the functions is non-
zero. The Wronskian determinant of the given set of functions, at a point of their
common domain of definition, is defined as follows:

A set of linearly independent non-trivial solutions of a


homogeneous linear equation of order n

is called a set of fundamental solutions of the equation.

If the functions are continuous in an open interval , then the


homogeneous equation has a set of fundamental solutions in .
In addition, the general solution of the homogeneous equation will then be given by the
function:

where is a set of arbitrary constants.

The equation:

is called the characteristic equation of the homogeneous differential equation with


constant coefficients. The solutions of this characteristic equation determine the general
solutions of the corresponding differential equation.

Exercise 6-1. Show that the set of functions

is linearly independent.

In[1]:= funciones={Exp[x],x Exp[x], x^2 Exp[x]}

x x x 2
{E , E x, E x }

In[2]:= matriz={funciones,D[funciones,x],D[funciones,{x,2}]}

x x x 2 x x x x x 2
{{E , E x, E x }, {E , E + E x, 2 E x + E x },
x x x x x x 2
{E , 2 E + E x, 2 E + 4 E x + E x }}

In[3]:= Det[matriz]

3x
2E

This gives us the value of the Wronskian, which is obviously always non-zero.
Therefore the set of functions is linearly independent.

We can put the Wronskian in matrix form as follows:

In[4]:= TableForm[matriz]

x x x 2
E E x E x

x x x x x 2
E E +E x 2E x+E x

x x x x x x 2
E 2E +E x 2E +4E x+E x
6.2 HIGHER-ORDER LINEAR HOMOGENEOUS
EQUATIONS WITH CONSTANT COEFFICIENTS

The homogeneous linear differential equation of order n

is said to have constant coefficients if the functions are all constant


(i.e. they do not depend on the variable ).

The equation:

is called the characteristic equation of the above differential equation. The solutions
of this characteristic equation determine the general solution of the
associated differential equation.

If the are all different, the general solution of the homogeneous


equation with constant coefficients is:

where are arbitrary constants.

If some is a root of multiplicity k of the characteristic equation, then it determines


the following k terms of the solution:
.

If the characteristic equation has a complex root mj=a+bi , then its complex conjugate
mj+1=a-bi is also a root. These two roots determine a pair of terms in the general solution
of the homogeneous equation:

Mathematica directly applies this method to obtain the solutions of homogeneous linear
equations with constant coefficients, using the command DSolve.

Exercise 6-2. Solve the following equations:

In[1]:= solucion=DSolve[3y”[x]+2y’[x]-5y[x]==0,y[x],x]

C[1] x
{{y[x] -> ––— + E C[2]}}
(5 x)/3
E

In[2]:=solucion=DSolve[{2y”[x]+5y’[x]+5y[x]==0,y[0]==0,
y’[0]==1/2},y[x],x]

((-5 - I Sqrt[15]) x)/4


IE
{{y[x] -> ––––––––— -
Sqrt[15]
((-5 + I Sqrt[15]) x)/4
IE
––––––––—}}
Sqrt[15]
In[3]:= solucionsimplificada= solucion[[1,1,2]]//ComplexExpand

Sqrt[15] x
2 Sin[–––-]
4
–––––—
(5 x)/4
Sqrt[15] E

Exercise 6-3. Solve the differential equation

In[1]=solucion=DSolve[9D[y[x],{x,4}]-6D[y[x],{x,3}]+46y’’+37y==0,
y[x],x}

x/3
{{y[x] -> C[2] Cos[x] + E C[4] Cos[2 x] -

x/3
C[1] Sin[x] - E C[3] Sin[2 x]}}

Looking at the solution, it is evident that the characteristic equation has two pairs of
complex conjugate solutions.
In[2]:= Solve[9x^4-6x^3+46x^2-6x+37==0]

1 1
{{x -> -I}, {x -> I}, {x -> - - 2 I}, {x -> - + 2 I}}
3 3
6.3 NON-HOMOGENEOUS EQUATIONS WITH CONSTANT
COEFFICIENTS. VARIATION OF PARAMETERS

Consider the non-homogeneous linear equation with constant coefficients:

Suppose is a linearly independent set of solutions of the


corresponding homogeneous equation:

A particular solution of the non-homogeneous equation is given by:

where the functions are obtained as follows:

Here is the determinant of the matrix obtained by replacing the


i-th column of the Wronskian matrix by the transpose of the
vector (0,0,…, 0, 1).

The solution of the non-homogeneous equation is then given by combining the


general solution of the homogeneous equation with the particular solution of the non-
homogeneous equation. If the roots of the characteristic equation of the homogeneous
equation are all different, the general solution of the non-homogeneous equation is:
If some of the roots are repeated, we refer to the general form of the solution of a
homogeneous equation discussed earlier.

Exercise 6-4. Solve the following differential equations:

We will follow the algebraic method of variation of parameters to solve the first
equation. We first consider the characteristic equation of the homogeneous equation to
obtain a set of linearly independent solutions.

In[2]:= Solve[m^2+4m+13==0]

{{m -> -2 - 3 I}, {m -> -2 + 3 I}}

In[2]:= f[x_]=x Cos[3x]^2;

In[3]:= y1[x_]=Exp[-2x]Cos[3x];

In[4]:=y2[x_]=Exp[-2x]Sin[3x];

In[5]:= wronskiano=Det[{{y1[x],y2[x]},D[{y1[x],y2[x]},x]}]//Simplify

3
–-
4x
E
We see that the Wronskian is non-zero, indicating that the functions are linearly
independent. Now we calculate the functions

In[6]:= W1[x_]=Det[{{0,y2[x]},{1,D[y2[x],x]}}]//Simplify

Sin[3 x]
-(––—)
2x
E

In[7]:=W2[x_]=Det[{{y1[x],0},{D[y1[x],x],1}}]//Simplify

Cos[3 x]
––—
2x
E

Now we calculate the particular solution of the non-homogeneous equation.

In[8]:= u1[x_]=Integrate[f[x] W1[x]/wronskiano,x]//Simplify

2x
(E (-86700 Cos[3 x] + 281775 x Cos[3 x] -
6084 Cos[9 x] + 129285 x Cos[9 x] -
36125 Sin[3 x] - 187850 x Sin[3 x] -
13013 Sin[9 x] - 28730 x Sin[9 x])) / 14652300

In[9]:= u2[x_]=Integrate[f[x] W2[x]/wronskiano,x]//Simplify

2x
(E (108375 Cos[3 x] + 563550 x Cos[3 x] +
13013 Cos[9 x] + 28730 x Cos[9 x] -
260100 Sin[3 x] + 845325 x Sin[3 x] -
6084 Sin[9 x] + 129285 x Sin[9 x])) / 14652300

In[10]:= yp[x_]=y1[x] u1[x]+y2[x] u2[x]//Simplify

(-28900 + 93925 x + 13436 Cos[6 x] -


25415 x Cos[6 x] + 3852 Sin[6 x] + 26520 x Sin[6 x]
) / 2442050

Then we can write the general solution of the non-homogeneous equation:

In[11]:= y[x_]=c1 y1[x] + c2 y2[x] + yp[x] //Simplify

c1 Cos[3 x] c2 Sin[3 x]
–––— + –––— +
2x 2x
E E

(-28900 + 93925 x + 13436 Cos[6 x] -

25415 x Cos[6 x] + 3852 Sin[6 x] +

26520 x Sin[6 x]) / 2442050

Now we graphically represent a set of solutions, for certain values of c1 and c2 (see
Figure 6-1)

In[12]:= Plot[Evaluate[Table[y[x],{c1,-5,5,5},{c2,-4,4,2}]],{x,-1,1},
PlotRange->{-20,20}, PlotPoints->100]
Figure 6-1

For the second differential equation we directly apply DSolve, obtaining the solution.
First, we find the general solution of the homogeneous equation:

In[1]:= Clear [x,y]

In[2]:= DSolve[y”[x]-2y’[x]+y[x]==Exp[x] Log[x], y[x], x]

x 2
-3 E x x x
{{y[x] -> ––— + E C[1] + E x C[2] +
4
x 2
E x Log[x]
––––}}
2
6.4 NON-HOMOGENEOUS LINEAR EQUATIONS WITH
VARIABLE COEFFICIENTS. CAUCHY-EULER
EQUATIONS

A non-homogeneous linear equation with variable coefficients of the form

is called a Cauchy–Euler equation.

This equation can be reduced to a homogeneous linear equation with constant


coefficients by replacing x = et.

This leads us to solve the equation:

The roots ki of multiplicity ai correspond to the solutions:

The complex roots p ± qi of multiplicity a correspond to the solutions:

Mathematica solves this type of equation directly with the command DSolve.
Exercise 6-5. Solve the following differential equation:

In[1]:=DSolve[x^3 y”’[x]+16x^2 y”[x]+79x y’[x]+125y[x]==0,y[x],x]

C[1] C[3] Cos[3 Log[x]]


{{y[x] -> –- + –––––– -
5 4
x x
C[2] Sin[3 Log[x]]
––––––}}
4
x
6.5 THE LAPLACE TRANSFORM

Suppose is a function defined in the interval . The Laplace transform of


is the function defined by:

We say that is the inverse Laplace transform of , so that .

Mathematica has the Calculus`Laplace Transform` package that enables functions to


calculate the Laplace transform and vice versa.

The LaplaceTransform [g [t], t, s] function calculates the Laplace transform of g (t) as


a function of s.

The InverseLaplaceTransform [f [s], s, t] function calculates the inverse Laplace


transform of f (s) as a function of t.

The Laplace transform and its inverse are used to solve certain differential equations.
The method is to calculate the Laplace transform of each term of the equation to obtain a
new differential equation, which we then solve. Finally, we find the solution of the
original equation by applying the inverse Laplace transform to the solutions just found.

Exercise 6-6. Solve the differential equation

using the Laplace transform method.

In[1]:= <<Calculus`LaplaceTransform`
First, we calculate the Laplace transform of each side of the differential equation,
and we apply the initial conditions.
In[2]:=paso1=LaplaceTransform[y”[x]+2y’[x]+4y[x],x,s]

1
- + 4 LaplaceTransform[y[x], x, s] +
2

2
s LaplaceTransform[y[x], x, s] +

2 (s LaplaceTransform[y[x], x, s] - y[0]) - s y[0]

In[3]:= paso2=paso1 /. {y[0]->1,y’[0]->1}

1
- - s + 4 LaplaceTransform[y[x], x, s] +
2

2
s LaplaceTransform[y[x], x, s] +

2 (-1 + s LaplaceTransform[y[x], x, s])

We then solve the Laplace transformed differential equation:

In[4]:=paso3=Solve[paso2==Integrate[(x-E^x) E^(-s x),{x,0,Infinity}],


LaplaceTransform[y[x],x,s]]

General::intinit:
Loading integration packages — please wait.
{{LaplaceTransform[y[x], x, s] ->
2 3 4
-(2 - 2 s + 5 s - s - 2 s )
–––––––––—}}
2 2
2 (-1 + s) s (4 + 2 s + s )

This gives the solution of the Laplace transformed equation. To calculate the solution of
the original equation we calculate the inverse Laplace transform of the solution obtained
in the previous step.

In[5]:= paso4=paso3[[1,1,2]]

2 3 4
-(2 - 2 s + 5 s - s - 2 s )
–––––––––—
2 2
2 (-1 + s) s (4 + 2 s + s )

In[6]:= solucion=InverseLaplaceTransform[paso4,s,x]

x
1 E x 36 Sqrt[3] Sin[Sqrt[3] x]
-(-) - — + - + (––––––––- +
8 7 4 x
E
Cos[Sqrt[3] x] Sin[Sqrt[3] x]
71 (––––— - ––––—)) / 56
x x
E Sqrt[3] E
6.6 SYSTEMS OF LINEAR HOMOGENEOUS EQUATIONS
WITH CONSTANT COEFFICIENTS

A system of differential equations, written as , has a general solution of


the form:

where the eigenvalues corresponding to the eigenvectors of the


matrix of the system are all assumed to be different.

If an eigenvalue is a complex number , then it generates the following


component of the overall solution:

where:

Here is the eigenvector corresponding to the eigenvalue and is its conjugate.

If there is an eigenvalue of multiplicity , then it will generate a portion of the


general solution of the form:
Mathematica can solve this type of system directly, simply by using the command
dsolve or maple(‘dsolve’) with the folowing syntax:

DSolve[{ecuation1, …., ecuationn}, {vd1, ….,vdn}, vi}


Solve the differential equation system ecuation1, …., ecuationn, with
dependent variables: vd1,….,vdn and the independent variable x.

Exercise 6-7. Solve the following system of equations:

In[1]:= solucion =DSolve[{x’[t]==-5x[t]+3y[t],


y’[t]==-2x[t]-10y[t]},{x[t],y[t]},t]

-2 3 -3 3
{{x[t] -> (–- + –-) C[1] + (–- + –-) C[2],
8t 7t 8t 7t
E E E E

2 2 3 2
y[t] -> (–- - –-) C[1] + (–- - –-) C[2]}}
8t 7t 8t 7t
E E E E
6.7 SYSTEMS OF LINEAR NON-HOMOGENEOUS
EQUATIONS WITH CONSTANT COEFFICIENTS

Now let us consider systems of non-homogeneous differential equations with constant


coefficients of the form .

The general solution of the homogeneous system takes the form .


A particular solution of the non-homogeneous system is:

The general solution of the non-homogeneous system will be , which is,


using the previous expression:

This method is a generalization to systems of equations of the method of variation of


parameters for simple equations.

Mathematica can solve such systems of equations directly with the command DSolve,
provided the integrals that appear in the solution can be evaluated.

Exercise 6-8. Solve the following system of equations:

with initial conditions and .

In[1]:=DSolve[{x’[t]-y’[t]==E^(-t),y’[t]+5x[t]+2y[t]==Sin[3t],
y[0]==y0,x[0]==x0},{x[t],y[t]},t]
41 5 x0 2 y0
-(–) + –- + –-
-1 609 7 7
{{x[t] -> –- + ––––––— -
t 7t
6E E

2 (-1 - x0 + y0) 3 Cos[3 t] 7 Sin[3 t]


–––––- - –––- + –––-,
7 58 58

41 5 x0 2 y0
-(–) + –- + –-
5 609 7 7
y[t] -> –- + ––––––— +
t 7t
6E E

5 (-1 - x0 + y0) 3 Cos[3 t] 7 Sin[3 t]


–––––- - –––- + –––-}}
7 58 58
Chapter 7.

HIGHER ORDEN DIFFERENTIAL EQUATIONS


AND SYSTEMS USING APPROXIMATION
METHODS. DIFFERENTIAL EQUATIONS IN
PARTIAL DERIVATIVES
7.1 HIGHER ORDER EQUATIONS AND
APPROXIMATION METHODS
When the known algebraic methods for solving differential equations and systems of
differential equations offer no solution, we usually resort to methods of approximation.
The approximation methods can involve both symbolic and numerical work. The symbolic
approach yields approximate algebraic solutions, and its most representative technique is
the Euler series method.

The numerical approach yields a solution in the form of a finite set of solution
points, to which a curve can be fitted by various algebraic methods (interpolation,
regression,…). This curve will be an approximate solution of the differential equation.
Among the most common numerical methods is the Runge–Kutta method.

Approximation methods are most commonly employed to find the solution of equations
and systems of differential equations of order and degree greater than one, where the exact
solution cannot be obtained by other methods.
7.2 THE EULER METHOD

This method provides a set of points on the solution of the differential equation of
the type dy / dx = f (x, y), y(x0) = y0.
The set of points is defined by the recurrence relation:
x(n) = n h
y(n+1) = y(n) + f(x(n),y(n))h
for initial values: (x0, y0)
A more sophisticated variant of Euler, which defines the solution by the following
recurrence relation:
X(n) = n h
y(n+1) = y(n) +1/2 [f(x(n),y(n)) + f(x(n+1), y(n) + f(x(n),y(n))h) ]h

for initial values (x0, y0)

Exercise 7-1. Solve the following two equations by the Euler method:

dy/dx = xy, y(0)=1 h=0.1

In[1]:= Clear[f,x,y,h]

In[2]:= f[x_,y_]=x y;

In[3]:= h=0.1; y[0]=1;


In[4]:= x[n_]=n h;

In[5]:= y[n_]:=y[n]=y[n-1]+h f[x[n-1],y[n-1]];

In[6]:=puntos=Table[{x[i-1],Table[y[i],{i,0,10}][[i]]},
{i,1,Length[Table[y[i],{i,0,10}]]}]
{{0, 1}, {0.1, 1}, {0.2, 1.01}, {0.3, 1.0302},
{0.4, 1.06111}, {0.5, 1.10355}, {0.6, 1.15873},
{0.7, 1.22825}, {0.8, 1.31423}, {0.9, 1.41937},
{1., 1.54711}}

Now let’s plot the set of points of the solution


In[7]:= Grafico=ListPlot[puntos,PlotJoined->True]

.
Figure 7-1

Now we will use the advanced method of Euler:

In[1]:= Clear[x,y,h]

In[2]:= f[x_,y_]=x y;

In[2]:= h=0.1; y[0]=1;

In[4]:= x[n_]=n h;

In[5]:= y[n_]:=y[n]=y[n-1]+(h/2) (f[x[n-1],y[n-1]]+f[x[n-1],y[n-1]+


h f[x[n-1],y[n-1]]]);
In[6]:=puntos=Table[{x[i-1],Table[y[i],{i,0,10}][[i]]},
{i,1,Length[Table[y[i],{i,0,10}]]}]
{{0, 1}, {0.1, 1}, {0.2, 1.01005}, {0.3, 1.03045}, {0.4, 1.06183},
{0.5, 1.10515}, {0.6, 1.16179}, {0.7, 1.23359}, {0.8, 1.32296},
{0.9, 1.43304}, {1., 1.56781}}
Ahora vamos a graficar este conjunto de puntos de la solución (figure 7-2)
In[7]:= Grafico=ListPlot[puntos,PlotJoined->True]

Figure 7-2
7.3 THE RUNGE–KUTTA METHOD
The Runge–Kutta method gives a set of data points to which you can fit a curve,
approximating the solution of a differential equation. Initially used the method known as
order 2 used, but now often used the order 4. In this case the iterative algorithm used is as
follows:

x(n+1) = nh
y(n+1) = y(n) + h/6 (k1+2k2+2k3+k4)

were k1=f(x(n),y(n)), k2=f(x(n)+h/2,yn+hk1/2), k3=f(x(n)+h/2,y(n)+hk2/2)


k4=f(x(n+1),y(n)+hk3)

The value of h is given and the initial conditions (x0, y (x0))

maple (‘dsolve (equation, func (var), ‘numeric’))

Exercise 7-2. Solve the following two equations by the Euler method:

dy/dx = xy, y(0)=1 h=0.1

In[1]:= x[n_]:=n h

In[2]:= f[x_,y_]=x y;

In[4]:= h=0.1;

In[5]:= rk4[0]=1;

In[6]:=rk4[n_]:=Module[{k1,k2,k3,k4},
k1=f[x[n-1],rk4[n-1]];
k2=f[x[n-1]+h/2,rk4[n-1]+(h k1)/2];
k3=f[x[n-1]+h/2,rk4[n-1]+(h k2)/2];
k4=f[x[n],rk4[n-1]+h k3];
rk4[n]=rk4[n-1]+(h/6)(k1+2k2+2k3+k4)]

In[7]:= solucion=Table[{x[i-1],Table[rk4[i],{i,0,10}][[i]]},
{i,1,Length[Table[rk4[i],{i,0,10}]]}]

{{0, 1}, {0.1, 1.00501}, {0.2, 1.0202},

{0.3, 1.04603}, {0.4, 1.08329}, {0.5, 1.13315},

{0.6, 1.19722}, {0.7, 1.27762}, {0.8, 1.37713},

{0.9, 1.4993}, {1., 1.64872}}

We have a set of points of the solution can be adjusted to a curve through any known
method. This curve is an approximation to the solution of the differential equation.
7.4 DIFFERENTIAL EQUATIONS SYSTEMS BY
APPROXIMATE METHODS

The Runge-Kutta methods and Euler can be extended to solving systems of


differential equations.

To solve the system:

dx/dt=f(t,x,y)
dy/dt=g(t,x,y)
x(t0)=x0, y(t0)=y0

Euler considered the following law of recurrence for a set of points {(xn,yn)} the
approximate solution:

x(n+1)=x(n)+hf(t(n),x(n),y(n))
y(n+1)=y(n)+hg(t(n),x(n),y(n))

where t(n)=t0+nh

Runge-Kutta consider the following law of recurrence:


x(n+1) = x(n)+h/6 (k1+2k2+2k3+k4)
y(n+1) = y(n)+h/6 (m1+2m2+2m3+m4)

donde k1=f(t(n),x(n),y(n)),
k2=f(t(n)+h/2,x(n)+hk1/2,y(n)+hm1/2),
k3=f(t(n)+h/2,x(n)+hk2/2,y(n+hm2/2)
k4=f(t(n)+h,x(n)+hk3,y(n)+hm3)
m1=g(t(n),x(n),y(n)),
m2=g(t(n)+h/2,x(n)+hk1/2,y(n)+hm1/2),
m3=g(t(n)+h/2,x(n)+hk2/2,y(n)+hm2/2)
m4=g(t(n)+h,x(n)+hk3,y(n)+hm3)
the value of h is given.

Exercice 7-3. Solve the following system of differential equations by Euler method and
Runge-Kutta:

dx/dt = x-y+1, dy/dt =x+3y+ et , x(0)=0, y(0)=1 for h= 0.1

We started using the algorithm of Euler.

In[1]:=f[t_,x_,y_]:=x-y+1;
In[2]:=g[t_,x_,y_]:=x+3y+E^(-t);
In[3]:=h=0.1;
In[4]:=x[0]=0;
In[5]:=y[0]=1;
In[6]:=t[n_]=h n;
In[7]:=x[n_]:=x[n]=x[n-1]+h(f[t[n-1],x[n-1],y[n-1]])
In[8]:=y[n_]:=y[n]=y[n-1]+h(g[t[n-1],x[n-1],y[n-1]])
In[9]:=solucion=Table[{t[i],x[i],y[i]},{i,0,10}]

{{0, 0, 1}, {0.1, 0, 1.4}, {0.2, -0.04, 1.91048},

{0.3, -0.135048, 2.5615}, {0.4, -0.304703, 3.39053},

{0.5, -0.574227, 4.44425},

{0.6, -0.976074, 5.78076}, {0.7, -1.55176, 7.47226},

{0.8, -2.35416, 9.60842}, {0.9, -3.45042, 12.3005},


{1., -4.9255, 15.6862}}
We have a set of points of the system solution.

We will now apply the Runge-Kutta algorithm.

In[1]:=f[t_,x_,y_]:=x-y+1;
In[2]:=g[t_,x_,y_]:=x+3y+E^(-t);
In[3]:=h=0.1;
In[4]:=xrk[0]=0;
In[5]:=yrk[0]=1;
In[6]:=t[n_]=h n;
In[7]:=xrk[n_]:= Module[{k1,k2,k3,k4},
k1=f[t[n-1],xrk[n-1],yrk[n-1]];
m1=g[t[n-1],xrk[n-1],yrk[n-1]];
k2=f[t[n-1]+h/2,xrk[n-1]+(h k1)/2,yrk[n-1]+(h m1)/2];
m2=g[t[n-1]+h/2,xrk[n-1]+(h k1)/2,yrk[n-1]+(h m1)/2];
k3=f[t[n-1]+h/2,xrk[n-1]+(h k2)/2,yrk[n-1]+(h m2)/2];
m3=g[t[n-1]+h/2,xrk[n-1]+(h k2)/2,yrk[n-1]+(h m2)/2];
k4=f[t[n-1]+h/2,xrk[n-1]+(h k3),yrk[n-1]+(h m3)];
m4=g[t[n-1]+h/2,xrk[n-1]+(h k3),yrk[n-1]+(h m3)];
xrk[n]=xrk[n-1]+(h/6)(k1+2k2+2k3+k4)]

In[8]:=yrk[n_]:= Module[{k1,k2,k3,k4},
k1=f[t[n-1],xrk[n-1],yrk[n-1]];
m1=g[t[n-1],xrk[n-1],yrk[n-1]];
k2=f[t[n-1]+h/2,xrk[n-1]+(h k1)/2,yrk[n-1]+(h m1)/2];
m2=g[t[n-1]+h/2,xrk[n-1]+(h k1)/2,yrk[n-1]+(h m1)/2];
k3=f[t[n-1]+h/2,xrk[n-1]+(h k2)/2,yrk[n-1]+(h m2)/2];
m3=g[t[n-1]+h/2,xrk[n-1]+(h k2)/2,yrk[n-1]+(h m2)/2];
k4=f[t[n-1]+h/2,xrk[n-1]+(h k3),yrk[n-1]+(h m3)];
m4=g[t[n-1]+h/2,xrk[n-1]+(h k3),yrk[n-1]+(h m3)];
yrk[n]=yrk[n-1]+(h/6)(m1+2m2+2m3+m4)]
In[9]:=solution=Table[{t[i],xrk[i],yrk[i]},{i,0,10}]

{{0, 0, 1}, {0.1, -0.0226878, 1.46108},

{0.2, -0.103414, 2.06715},

{0.3, -0.265698, 2.86193}, {0.4, -0.54073, 3.90121},

{0.5, -0.969603, 5.25605}, {0.6, -1.60617, 7.0168},

{0.7, -2.52065, 9.29823}, {0.8, -3.80425, 12.2459},

{0.9, -5.57502, 16.0441}, {1., -7.98522, 20.926}}


7.5 DIFFERENTIAL EQUATIONS IN PARTIAL
DERIVATIVES

Mathematica directly addresses several types of differential equations in partial


derivatives. The program enables Calculus`PDSolve1 package, which solves some
differential equations in partial derivatives of the first order.

We are considering the equation of the form:

a(x,y,u) ¶u/¶x + b(x,y,z) ¶u/¶y = c(x,y,u)

called quasilinear equation, most of the time it will be possible to find a solution directly.
Otherwise it is used with Mathematica classical algebraic method of characteristics to
solve this type of equations. Likewise you can use the classic metods for other types
dieferenciales partial differential equations.

If c (x, y) = 0, the equation is called homogeneous, and if c (x, y, u) = d (x, y) u + s (x, y) is


called a linear equation.

Within the package PDSolve1 we have the following functions:

DSolve[ ecuación, u[x,y,…], {x,y,..}] solves a quasi-linear equation in u[x,y,..]

CompleteIntegral[ecuación, u[x,y,…], {x,y,..}]

builds a complete integral of the partial differential


equation for u[x,y,…]

FirsIntegrals[{ec1,ec2,…},{u[x],v[x],..},x] It gives a list of first integrals for the given


system in terms of u[x], v[x], ….. y x

FirsIntegrals[{ec1,ec2,…},{u,v,..},x]
It gives a list of first integrals for the given system
in terms of u, v, ….. y x

Exercice 7-4. Solve the following differential equations in partial derivatives:

-(-x-y+u)2 + x2ux - uy = 0

- xyz + z2uz + y2uy + x2ux = 0

In[1]:=<<Calculus`PDSolve1`

For the first equation we propose the following:

In[2]:=DSolve[-(-x-y+u[x,y])^2+x^2*(D[u[x,y],x]-D[u[x,y],y])==0,
u[x,y],{x,y}]

{{u[x, y] ->
2
2 x + y - x C[1][x + y] - x y C[1][x + y]
-(––––––––––––––)}}
-1 + x C[1][x + y]
Now we will integrate the second partial differential equation:

In[1]:= DSolve[-x y z + z^2 D[w[x,y,z],z]+y^2 D[w[x,y,z],y]+


x^2 D[w[x,y,z],x]==0,w[x,y,z],{x,y,z}]

{{w[x, y, z] ->
2 x
x y z Log[-]
y
-(–––––––—) +
2
-(x y) + y + x z - y z
2 x
x y z Log[-]
z 1 1 1 1
–––––––— + C[1][- - -, - - -]}}
2 x y x z
-(x y) + x z + y z - z

Exercice 7-5. Calculate a complete integral to the following differential equations in


partial derivatives:

(x2 ux2 )/ y + u = uy

-u + (2+y) uy + x ux + 3 ux2 = 0

-c + b uy + a y ux + ux2 = 0

For the first equation we propose the following:

In[1]:=CompleteIntegral[Derivative[0,1][u][x,y]==(u[x,y]+
x^2*Derivative[1,0][u][x,y]^2)/y,u[x,y],{x,y}]
2 2
-B[1] B[1] Log[x] Log[x]
{{u[x, y] -> –– + y B[2] - –––— - ––-}}
4 2 4

Now we will integrate the second partial differential equation:

CompleteIntegral[-u[x,y]+(2+y)*Derivative[0,1][u][x,y]+
x*Derivative[1,0][u][x,y]+3*Derivative[1,0][u][x,y]^2==0,
u[x,y],{x,y},IntegralConstants->F]

2
x F[1] F[1]
{{u[x, y] -> –– + –— + 2 F[2] + y F[2]}}
6 12
In attempting to solve the third equation with DSolve automatically it invokes the
function CompleteIntegral.

In[1]= DSolve[-c+b*Derivative[0,1][u][x,y]+
a*y*Derivative[1,0][u][x,y]+
Derivative[1,0][u][x,y]^2==0,u[x,y],{x,y}]

DSolve::nlpde:
This is a nonlinear partial differential equation.
General solution is not available. Trying to
build a complete integral instead.

{{u[x, y] ->

2 2
cy a y B[1] y B[1]
– + x B[1] - ––– - ––- + B[2] + y B[2]}}
b 2b b

Exercice 7-6. Calculating the first integral to the following system of differential
equations:

u’ = - u(u+v)
v’ = v(u+v)

In[1]:= FirstIntegrals[{u’[x]==-(u[x] (u[x]+v[x])),


v’[x]==v[x] (u[x]+v[x])},{u,v},x]

u
{-Sqrt[u v] x + ArcTan[–––], u v}

Sqrt[u v]
7.6 ORTHOGONAL POLYNOMIALS

Two different functions f (x) and g (x) are said to be orthogonal on an interval [a, b] if
their inner product is 0, ie if

¡Error! Argumento de modificador no especificado.

An example of orthogonal functions can be family

fn(x)=sen(nx) and gn(x)=cos(nx), n=1,2,3,… in the interval [-p,p].

Mathematica provides an extensive list of orthogonal polynomials, which will be very


useful in solving certain nonlinear differential equations of higher order. The functions for
working with these polynomials are:

ChebyshevT[n,x] Chebyshev polynomials of the first specie.

ChebyshevU[n,x] Chebyshev polynomials of the second specie.

LegendreP[n,x] Legendre polynomials

LegendreP[n,m,x] Legendre associates polynomials.

HermiteH[n,x] Hermite polynomials.

LaguerreL[n,x] Laguerre polynomials.

LaguerreL[n,a,x] Laguerre generalized polynomials.


JacobiP[n,a,b,x] Jacobi polynomials.

Gegenbauer[n,m,x] Gegenbauer polynomials.

SphericalHarmonicY[l,m,n,a,b]

Spherical harmonic polynomials

Let us now his relationship with the differential equations. Precisely this relationship
is what allows us to find solutions of certain nonlinear equations of higher order.

Chebyshev polynomials of first and second species

Chebyshev polynomials of the first specie are the solutions of the differential equation:

¡Error! Argumento de modificador no especificado.

Legendre polynomials

They are solutions of the Legendre differential equation:

Legendre associate polynomials

They are solutions of differential equation:

Hermite polynomials

They are solutions of the Hermite differential equation:


Laguerre generalized polynomials
They are the solutions of the Laguerre differential equation:
:
x y’’ + (a+1-x) y’ + n y = 0

Laguerre polynomials

They are the solutions of the Laguerre differential equation:

Jacobi polynomials

They are the solutions of the Jacobi differential equation:

α, β > -1

Gegenbauer polynomials

Gegenbauer polynomials are particular solutions of the Gegenbauer differential


equation:

Exercice 7-7. Finding solutions to differential equations:


In[1]:= ChebyshevT[7,x]

3 5 7
-7 x + 56 x - 112 x + 64 x

In[2]:= LegendreP[6,x]

2 4 6
-5 + 105 x - 315 x + 231 x
–––––––––—
16

In[3]:= HermiteH[5,x]

3 5
120 x - 160 x + 32 x

In[4]:= LaguerreL[5,x]

2 3 4 5
120 - 600 x + 600 x - 200 x + 25 x - x
––––––––––––––
120
7.7 AIRY AND BESSEL FUNCTIONS

Are called Airy functions linearly independent solutions of linear second-order


differential equation:

y’’ - x y = 0 (Airy equation)

Are called Bessel functions linearly independent solutions of the differential equation:

2 2 2
y’’ + y’/x + (k - n /x ) y = 0 (Bessel equation)

Are called modified Bessel functions of the linearly independent solutions of the
differential equation:

2 2 2
y’’ + y’/x - (k + n /x ) y = 0 (modified Bessel equation)

About Mathematica implements the following functions:

AiryAi[z] y AiryBi[z] obtain independent solutions of the Airy


equation.

AiryAiPrime[z] y AiryBiPrime[z]

obtain derivatives of independent solutions of the Airy


equation.

BesselJ[n,z] y BesselY[n,z]

obtain independent solutions of the Bessel


equation.
BesselI[n,z] y BesselK[n,z]

obtain independent solutions of the modified Bessel equation.

Exercice 7-8. Finding solutions to the differential equation:

x2 y’’ + x y’ + (x2 - 1/4)y = 0

This is the Bessel differential equation for n = 1/2. We obtain two linearly
independent solutions as follows:

In[1]:= BesselJ[1/2,x]

1
Sqrt[2] Sqrt[–-] Sin[x]
Pi x

In[2]:= BesselY[1/2,x]

1
-(Sqrt[2] Sqrt[–-] Cos[x])
Pi x
APPENDIX I. NUMBERS, OPERATIONS AND
MOST COMMON FUNCTIONS
8.1 ARITHMETIC OPERATIONS IN MATHEMATICA

Mathematica defines arithmetic operations as follows:

x+y sum
x-y difference
x * y or x y product
x/y division
x^y power

As examples we have:

In [1]: = 53 + 78
Out [1] = 131

In [2]: = 127 * 9721


Out [2] = 1234567

In [4]: = 34 ^ 56
Out [4] = 5791877320528712784204425412617959985284096849205
6164062843692360166371779746690236416

Exercise 1. Perform the following operations:

(a) (- 2 + 3-5) (4-3 + 2):(15+4-21)


3
b) [(2 - 3)(4-3+5)] [(3-2) + (6-8-5)]
2 2
(c) 5-[4-3 + 2 x 7 + 5] + [((3-6) (7-9)]
2
(d) 6 - 4 x 3:2-7 x 2 + 8-6:3-5 + 3
2
(e) [5 + 3 x 2:6 - 4]. [4:2-3 + 6]: [7:2 - 8-2]

We asked Mathematica previous operations in the following way:

In[1] := ((‑2 + 3 ‑ 5) (4 ‑ 3 + 2))/(15 + 4 ‑ 21)


Out[1] = 6

In[2] := ((2 ‑ 3) (4 ‑ 3 + 5))^3 (3 ‑ 2 + 6 ‑ 8 ‑ 5)


Out[2] = 1296

In[3] := 5 ‑ (4 ‑ 3 + 2 7 + 5) + (3 ‑ 6)^2 (7 ‑ 9)^2


Out[3] = 21

In[4] := 6 ‑ (4 3)/2 ‑ 7 2 + 8 ‑ 6/3 ‑ 5^2 + 3


Out[4] = ‑30

In[5] := ((5 + (3 2)/6 ‑ 4) (4/2 ‑ 3 + 6))/(7 ‑ 8/2 ‑ 2)^2


Out[5] = 10

Exercise 2. Perform the following operations:

1) -6 a b + 3 a ^ 2 + 2ab

2) 6 a ^ 2 + 2 a – b ^ 2 + 3 a-5 a ^ 2 + b ^ 2

(3) 6 a b - 2 a ^2 -4 a b + 3 a ^ 2
We asked Mathematica previous operations in the following way:
In[6] := ‑6 a b + 3 a^2 + 2 a b
2
Out[6]= - 4 a b + 3 a

In[7] := 6 a^2 + 2 a ‑ b^2 + 3 a ‑ 5 a^2 + b^2


2
Out[7]= a + 5 a

In[8] := 6 a b ‑ 2 a^2 ‑ 4 a b + 3 a^2

2
Out[8]= a + 2 a b

Exercise 3. If H = 3 a ^ 2 - 2 a + 7, F = 6 a ^ 3 - 5 a + 2 y

G = 5 a ^ 2 + 4 a - 3; Calculate:

1) H + F + G
(2) H F + G
(3) F G H

We consider the previous operations in the following way:

In[9] := H = 3 a^2 ‑ 2 a + 7; F = 6 a^3 ‑ 5 a + 2; G = 5 a^2 + 4 a ‑ 3;


H+F+G
2 3
Out[9]= 6 ‑ 3 a + 8 a + 6 a

In[10] := H ‑ F + G
2 3
Out[10]= 2 + 7 a + 8 a ‑ 6 a

In[11] := H ‑ F – G

2 3
Out [11] = 8 - a - 2 a - 6 a
8.2 PREDEFINED FUNCTIONS OF INTEGER
ARGUMENT

Mathematica incorporates the most typical functions with integer argument, among
which we mention the following:

Function meaning
––––––––––––––––––––––––––––––
FactorInteger[n] list of prime factors of n

Prime [k] returns the k-th Prime

PrimeQ [n] recognizes whether the number is


prime or not

PrimePi [n] gives the number of primes less than n

Divisors [n] gives the list of the divisors of n

Factorial [n] or n! factorial of n

Factorial2 [n] or n! double factorial of n

Binomial [n, m] combinatorial number n of m


n! / (m! (m-n)! )

Multinomial [n1, n2,…] Multinomial coefficient (n1 + n2 +…) /


(n1! n2!…)

MOD [n, m] rest of division of n m


PowerMod [a, b, n] the power a ^ b module n

Quotient [n, m] division of n m

GCD [n1, n2,…] greatest common divisor

LCM [n1, n2,…] least common multiple

Sign [X] sign of x (1 if x > 0, and - 1 if x < 0)

ABS [x] absolute value of x (|x|)

Floor [x] largest integer not greater than x

Ceiling [X] lower integer greater than x

Max [x 1, x 2,…] maximum

Min [x 1, x 2,…] minimum

IntegerQ [x] check if x is an integer

NumberQ [x] check if x is any kind of number

EvenQ [x] check if x is odd number

OddQ [x] check if x is odd number

Head [x] returns the type of number that is x

IntegerDigits [n] gives a list of digits decimal integer n


RealDigits [x] gives a list of digits decimal places of
the real number x and their number of decimal places

IntegerDigits [n, b] gives the decimal digits of number n in base b

RealDigits [x, b] gives the decimal digits places of the real x in


base b

b^^x returned in decimal the number x in base b

Base [x, b] transforms the number x to base b

MantisaExponent[x] returns a list with the mantissa and the exponent of


x

Examples are shown below:

Factorizing the number 24

In [1]: = FactorInteger [24]


Out [1] = {{2, 3}, {3, 1}}

Decomposition in number 999999999999 factortes

In [2]: = FactorInteger [999999999999]


Out [2] = {{3, 3}, {7, 1}, {11, 1}, {13, 1}, {37, 1}, {101, 1}, {9901, 1}}

Remainder of the division from 17 between 3

In [3]: = Mod [17, 3]


Out [3] = 2
Ratio whole 17 between 3 Division

In [4]: = Quotient [17.3]


Out [4]: = 5

Remainder of the division of 4.1 between 1.2

In [5]: = Mod [4.1, 1.2]


Out [5] = 0.5

Remainder of the division between - 4.1 and 1.2

In [6]: = Mod [- 4.1, 1.2]


Out [6] = 0.7

Greatest common divisor of 1,000, 500 and 625

In [7] = GCD [1000,500, 625]


Out [7] = 125

Least common multiple between 1,000, 500 and 625

In [8]: = LCM [1000, 500, 625]


Out [8] = 5000

Is the number 99.991 cousin?

In [9]: = PrimeQ [99991]


Out [9] = True
The number was indeed Prime.

Find the prime number that ranks 1,000,000

In [10]: = Prime [1000000]


Out [10] = 15485863

How many prime numbers there are smaller than 10 ^ 9?

In [11]: = PrimePi [10 ^ 9]


Out [11] = 50847534

Find all numbers that divide 24

In [14]: = splitters [24]


Out [14] = {1, 2, 3, 4, 6, 8, 12, 24}
List the digits decimal number 12.267.845

In [15]: = IntegerDigits [12267845]


Out [15] = {1, 2, 2, 6, 7, 8, 4, 5}

List the digits decimal number 13.5678743

In [16]: = RealDigits [13.5678743]


Out [16] = {{1, 3, 5, 6, 7, 8, 7, 4, 3}, 2}

Exercise 4. Find the number of combinations without repetition of 45 elements


taken from 9 in 9. The same problem for n elements taken from three in three. Also find
the value of the coefficient, multinomial (7 + 2)! / (7! 2!)
In[15]:= Binomial[45, 9]

Out[15] = 886163135

In[16]:= Binomial[n, 3]

(-2 + n) (-1 + n) n
Out[16]= –––––––––
6

In[17]:= Multinomial[7, 6]

Out [17] = 1716

Exercise 5. Find the rest of the division of 2 ^ 13451 between 3. Also find the
integer k such that k (3 ^(-1)) º 1 mod 7.

In[12]:= PowerMod[2, 13451, 3]


Out[12]= 2

In[13]:= PowerMod[3, -1, 7]


Out [13] = 5

Exercise 6. Decomposed into prime factors the number 18.900, find all your
dividers and the number of prime numbers that are smaller than he. Also find the prime
number that is 18.900 place.

In[16] := FactorInteger[18900]
Out[16] = {{2, 2}, {3, 3}, {5, 2}, {7, 1}}

In[17] := Divisors[18900]
Out[17] = {1, 2, 3, 4, 5, 6, 7, 9, 10, 12, 14, 15, 18, 20, 21, 25, 27, 28,
30, 35, 36, 42, 45, 50, 54, 60, 63, 70, 75, 84, 90, 100, 105, 108, 126,
135, 140, 150, 175, 180, 189, 210, 225, 252, 270, 300, 315, 350, 378, 420, 450, 525, 540,
630, 675, 700, 756, 900, 945, 1050, 1260, 1350, 1575, 1890, 2100, 2700, 3150, 3780, 4725,
6300, 9450, 18900}
In[20] := PrimePi[18900]
Out[20] = 2150

In[21] := Prime[18900]
Out [21] = 211093

Exercise 7. Two books have 840 and 384 pages respectively. If they are formed by
booklets of equal number of leaves, and more than 18 leaves, calculate the number of
leaves of a booklet.

In [13]: = GCD [840, 384]


Out [13] = 24

Exercise 8. To find the number N, than to divide it by 16, 24, 30 and 32 gives rest
5.

N-5 will be a multiple of 16, 24, 30 and 32, and as you are asked to calculate the lowest
number, then N-5 will be the minimum common multiple of 16, 24, 30 and 32

In[15] := LCM[16, 24, 30, 32]


Out[15] = 480
Luego N = 480 + 5 = 485
8.3 NUMBERING SYSTEMS

Mathematica work with different numbering systems have the following syntax:

b^^x returned in decimal base, the number x in base b

BaseForm [x, b] transforms the decimal number x to base b

IntegerDigits [n, b] returns the decimal digits of integer n in base b

RealDigits [x, b] returns the decimal digits places of the real number x in base b

Exercise 9. Express the decimal number 2342.424 in base-2 numbering system.


Also express the decimal number 2423453.41 in base 16.

In[1]:=BaseForm[2342424, 2]
Out[1]=1000111011111000011000
2

In[2]:= BaseForm[242345341, 16]


Out [2] = e71e57d
16

Exercise 10. Express in base-10 the number 100101 in base 2 and express in base
10 the hexadecimal number ffffaa00. Find in base 10, the result of the operation of
hexadecimal numbers fffaa2 + ff - 1

In[1]:= 2^^100101
Out[1]=37

In[2]:= 16^^ffffaa00
Out[2] = 4294945280
In [3]: = 16 ^ ^ fffaa2 + 16 ^ ^ ff - 1
Out [3] = 16776096

Exercise 11. In base 5, get the result of the operation:

125aaff6 + 6789aba + 1100221 + 35671 - 1250


16 12 8 3

In[1]:= 16^^125aaff6 + 12^^6789aba + 8^^35671 +3^^1100221-1250


Out[1]=327788960

In[2]:= BaseForm[%, 5]
Out [2] = 1132403221320
5

Exercise 12. In base 13, get the result of the operation:

(666551) (aa199800a) + (fffaaa125) / (33331 + 6)


7 11 16 4

In[1]:= (7^^666551)(11^^aa199800a)+(16^^fffaaa125)/(4^^33331 +6)

282803061001316876
Out[1]= –––––––––––-
1027
In[2]:=BaseForm[%, 13]

56a96112b7a32757
13
Out[2]=–––––––––––-
610
13

In[3]:=N[%1]

14
Out[3]=2.75368 10

In[4]:= BaseForm[%, 13]

12
Out[4]:=b.a861 13
13

Exercise 13. Put in base 3 the decimal number 125,7864 and put in base 16 the
result of next operation: 8796,43 + 0 6789-4,25

In[1]:= BaseForm[125.7864, 3]
Out[1]=11122.2100200212
3
In[2]:= BaseForm[8796.43+0.6789-4.25, 16]
Out [2] = 2258. e
16
Exercise 14. Put in base 12 the result of the operation:

(13,3 – 888,7777 ) (aaff10 – 12,3) / (aabbc01 - 1)


4 9 16 15

In[1]:= (4^^13.3-9^^888.7777)(16^^aaff10-12.3)/(15^^aabbc01-1)//N
Out[1]= -66.187

In [2] = base [%, 12]


Out [2] = - 56 22b2
12

Exercise 15. A list of the decimal digits of the numbers in base 16,
145673214567005, and 145673214567005,241

In[1]:=IntegerDigits[145673214567005, 16]
Out[1]={8, 4, 7, 13, 3, 0, 3, 5, 2, 2, 5, 13}

In[2]:=RealDigits[145673214567005.241, 16]
Out [2] = {{8, 4, 7, 13, 3, 0, 3, 5, 2, 2, 5, 13, 3, 14}, 12}
8.4 RATIONAL NUMBERS

Mathematica can normally work with rational numbers according to the rules of Algebra.
Below are exercises that illustrate the operations with rational numbers.

Exercise 16. Perform the following operations:

(a) 3/5 + 2/5 + 7/5


(b) 1/2 + 1/3 + 1/4 + 1/5 + 1/6
(c) 1/2-1/3 + 1/4 - 1/5 + 1/6
(d) (2/3-1/6)-(4/5+2+1/3) + (4-5/7)
(d) (1/5 * 4/7:(4/3-2/5)): (-(5/9-1/7) 6 * 5 + 1/4)
(e) ((-1) ^ 4:(2/5)^3)^(-2):((-3/7)^2-(2/5)^(-1)))
(g) [(2-1/5)^2:(3-2/9)^(-1)]/[(6/7*5/4-(2/7)/(1/2))]^3:(1/2-1/3)

In[1]:=3/5+2/5+7/5
Out[1]:=12/5

In[2]:=1/2+1/3+1/4+1/5+1/6

29
Out[2]:=–-
20

In[3]:=1/2-1/3+1/4-1/5+1/6
23
Out[3]:= –
60
In[4]:=(2/3-1/6)-(4/5+2+1/3)+(4-5/7)
137
Out[4]:= –-
210

In[5]:=(1/5*4/7/(4/3-2/5))/(6-(5/9-1/7)*5+1/4)
216
Out[5]:= ––
7385

In[6]:=((-1)^4/(2/5)^3)^(-2)/((-3/7)^2-(2/5)^(-1))
6272
Out[6]:= -(––––-)
3546875

In[7]:=(2-1/5)^2/(3-2/9)^(-1)/(6/7 5/4-(2/7)/(1/2))^3/(1/2-1/3)
Out[{7]:=432
8.5 IRRATIONAL NUMBERS

Mathematica can work normally with irrational numbers according to the rules of
Algebra. Below are exercises that illustrate the operations with irrational numbers.

Exercise 17. Perform the following operations with irrational numbers:

a) 3 Sqrt[a] + 2 Sqrt[a] - 5 Sqrt[a] + 7 Sqrt[a]

Sqrt[2]
b) Sqrt[2] + 3 Sqrt[2] - –––—
2

1/3 1/3 1/3 1/3 1/3


c) 4 a - 3 b - 5 a - 2 b + ma

d) Sqrt[432] + Sqrt[75] - Sqrt[363] - Sqrt[108]

(e) Sqrt [3 a] Sqrt [27 a]

1/2 1/3
(f) a a

2 5 1/3 3 2 1/4 1/6


(g) (3a b ) (9a 2 ) (3a b)

1/5
(h) Sqrt [a a ]

a)
In[1]:= 3Sqrt[a]+2Sqrt[a]-5Sqrt[a]+7Sqrt[a]
Out[1]= 7 Sqrt[a]

b)

In[2]:= Sqrt[2]+3Sqrt[2]-(1/2)Sqrt[2]
1
Out[2]= -(–––—) + 4 Sqrt[2]
Sqrt[2]
c)

In[3]:= 4a^(1/3)-3b^(1/3)-5a^(1/3)-2b^(1/3)+ma^(1/3)

1/3 1/3 1/3


Out[3] = -a - 5 b + ma

d)

In[4]:= Sqrt[432]+Sqrt[75]-Sqrt[363]-Sqrt[108]
Out[4]= 0

e)

In[5]:= Sqrt[3a] Sqrt[27a]


Out[5] = 9 a

f)

In[6]:=a^(1/2) a^(1/3)
5/6
Out[6]= a
g)

In[7]:= (3a^2 b^5)^(1/3) (9a^3 b^2)^(1/4) (3 a b)^(1/6)

1/6 3 2 1/4 2 5 1/3


Out[7]=3 (a b) (a b ) (a b )

h)
In[8]:= Sqrt[a (a^(1/5))]

6/5
Out[8] = Sqrt[a ]

Exercise 18. Perform the following operations for rationalization of denominators

2
a) ––-
Sqrt[2]

Sqrt[2]
b) ––-
1/3
2

2
c) –-
1/3
4
3
d) ––-
SQRT [3]

(e) 2 /(Sqrt[2])

a)

In[1]:= 2/Sqrt[2]
Out[1] = Sqrt[2]

b)

In[2]:= Sqrt[2]/2^(1/3)
1/6
Out[2]:=2

c)

In[3]:= 2/4^(1/3)
1/3
Out[3]= 2

d)

In[4]:= 3/Sqrt[3]
Out [4] = Sqrt [3]
8.6 COMPLEX NUMBERS. MORE COMMON
FUNCTIONS

Mathematica incorporates functions for working with complex numbers. We then see
some examples:

Re [Z] function returns the real part of Z.

In [12]: = Re [3 + 4 I]
Out [12] = 3

Im [Z] function returns the imaginary part of Z.

In [13]: = Im [3 + 4 I]
Out [13] = 4

The Conjugate [Z] function returns the conjugate of Z.

In [14]: = Conjugate [3 + 4 I]
Out [14] = 3-4 I

The Abs[Z] function returns the absolute value of Z.

In [15]: = Abs [3 + 4I]


Out [15] = 5

The Arg [Z] function returns the argument of Z

In addition to these specific functions of a complex variable, there are many other
functions that can be applied to complex numbers.

For example, the Round[Z] function rounds both the real part and the imaginary of Z.
In [17]: = Round [2.7 - 8.5 I]
Out [17] = 3-8 I

There are many more features in Mathematica working with complex numbers, including
free, Cos, Ex and Log, etc. Some of the most important are presented in the following table:

Trigonometric functions

Function Inverse
–––––––––––––––
Sin [z] ArcSin [z]
COS [z] ArcCos [z]
Tan [z] ArcTan [z]
CSC [z] ArcCsc [z]
SEC [z] ArcSec [z]
Cot [z] ArcCot [z]

Hyperbolic functions

Function Inverse
–––––––––––––––—
Sinh [z] ArcSinh [z]
Cosh [z] ArcCosh [z]
Tanh [z] ArcTanh [z]
Csch[z] ArcCsch[z]
Sech[z] ArcSech[z]
Coth [z] ArcCoth [z]

Exponential and logarithmic functions


Function
–––––––––––––––––––––––
Exp [z] exponential function
Log [z] logarithm in base e function
Log [b, z] logarithm of z in base b function

Specific functions of a complex variable.

Function
––––––––––––––-
ABS [z] module
ARG [z] argument
Conjugate [z] conjugate
Re [z] real part
IM [z] imaginary part

It should be noted that, as the real numbers are a special case of the complexes (zero
imaginary part), all functions defined above also are valid for real variable.

Exercise 19. Given the complex numbers: X = 3+2i, Y = 3-2i and Z = i^307,
calculate X+Y+Z, X * Y * Z, X/Y and Y/Z

In[1]:=3+2 I + 3-2 I - I^307


Out[1]:=6 + I

In[2]:= (3+2 I)(3-2 I)I^307


Out[2]:= -13 I

In[3]:= (3+2I)/(3-2I)

5 12 I
Out[3]:= — + –-
13 13

In [4]: =(3-2 I)/I ^ 307


Out [4]: = 2 + 3 I

Exercise 20. Given the complex numbers X = 2 + 2i e


Y=-3-3Sqrt [3] i, calculate Y ^ 3 and X ^ 2 / Y ^ 90

In[1]:=(-3-3Sqrt[3] I)^3//N

-14
Out[1]:=216. - 3.15928 10 I
In[2]:=(2+2I)^2/(-3-3Sqrt[3]I)^90//N

-84 -70
Out[2]:= -6.77367 10 + 7.40419 10 I

Exercise 21. Calculate the value of:

i ^ 8 - i ^(-8)
––––- + i
2I-1

In [1]: = (I ^ 8-I ^(-8)) /(3-4I) + 1


Out [1]: = 1
Exercise 22. Calculate the module and the argument of the complex:

i
i 3+i i 1-i
i , i , i and (1+Ö3 i)

In[1]:= Abs[I^I]
-Pi/2
Out[1] = E

In[2] = Arg[I^I]
Out[2] = 0

In[3]:= Abs[I^(3+I)]
-Pi/2
Out[3]= E

In[4]:= Arg[I^(3+I)]

-Pi
Out[4]= –
2

In[5]:= Abs[(I^I)^I]
Out[5]:=1
In[6]:= Arg[(I^I)^I]
-Pi
Out[6]=–-
2

In[7]:= Abs[(1+Sqrt[3] I)^(1-I)]


Pi/3
Out[7]= 2 E

In[8]:= Arg[(1+Sqrt[3] I)^(1-I)]


Pi Pi
Out[8]= ArcTan[Cos[— - Log[2]], Sin[— - Log[2]]]
3 3

In[31]:= Rationalize[3.1415926536, 0]
Out [31] = 3926990817 / 1250000000
8.7 ROUNDING AND APPROACH FUNCTIONS

We see a table overview of the functions of rounding and approach:

Function Description Example


–––––––––––––––––––––––––––––––––––––
Ceiling [X] the lower integer ³ x Ceiling [3.4] = > 4

Floor [x] the largest integer<=x Floor [3.4] = > 3

Round [x] the nearest integer to x Round [5.6] = > 6

Chop [x] replaces real numbers close to Chop[0.00001] = > 0


zero for the number zero

N [x] approximate numeric value to x N [Pi] = > 3.14159

Rationalize [x] converts a number with Rationalize[3.14]= >


floating point to rational 157/50

Accuracy[x] decimal places of x Accuracy [8.546] = > 4

Here are some examples:

In[32]:= Round[2.574]
Out[32] =3

In[32]:= Round[2.41]
Out [32] = 2

In[33]:= Round[Sqrt[17]]
Out[33] = Round[Sqrt[17]]

In[34]:= Round[N[Sqrt[17]]]
Out[34] = 4

In [34]: = Ceiling [4.2]


Out [34] = 5
In [34]: = Floor [4.82]
Out [34] = 4

Chop [0.00000000002]
Out [35] = 0

In [35]: = Accuracy [0.00000000002]


Out [35] = 11
8.8 COMMON CONSTANT USED IN MATHEMATICA

Mathematica allows to represent constants more used < adas in practice. We have:

· The imaginary unit “I”.

· The constant infinity ‘Infinity’.

· The number p represented in Mathematica as Pi.

· The number “E”, worth approximately 2.71828.


8.9 RANDOM NUMBERS

Mathematica has the Random function to generate pseudo-random numbers uniformly


distributed. If no arguments are specified, Random generates uniformly distributed floating-
point numbers in the interval [0,1].

Random[ ] returns a random decimal number distributed


uniformly on the interval [0,1].

Random [Integer] Returns 0 or 1 with probability 1/2


Random [Integer {imin, imax}]

Returns a random integer number distributed uniformly in the


interval [imax, imin].

Random[Complex] Returns a complex random number distributed uniformly in the


rectangle unit.
Random [Complex, {zmin, zmax}]

Returns a complex random number distributed uniformly in the rectangle


defined by zmin and zmax.

The example calls a distributed random integer uniformly in the range [0, 100] including
the ends.

In [54]: = Random [Integer, {0, 100}]

Out [54] = 50

If you want a random number of complex, a complex range is specified.

[To specify a range such as {1 + 3, 4 + 7 I}], Mathematica generates random numbers


whose real part is between 1 and 4 and whose part imaginary is between 3 and 7.
In[55]:= Random[Complex, {1 + 3 I, 4 + 7 I}]

Out [55] = 3.39728 + 3.15363 I

Random [Real, {xmin, xmax}]

Returns a real random number distributed uniformly in the interval


defined by xmin and xmax.

Random can return a real number between 0 and a specified range.

Random [Real, xmax]

Returns a real random number distributed uniformly in the interval [0,


xmax].

The following example gets a random number generated by a Normal distribution

In[56]:= Needs[“Statistics`ContinuousDistributions`”]

In[57]:= Random[NormalDistributions[5]]
Out [57] = 4.05222
8.10 NUMBER THEORY PACKAGE
Mathematica enables a specific package of expansion of the theme.

NumberTheory’Binomial’ package contains the following functions:

FastBinomial [n, k] calculates efficiently Binomial [n, k] for values of


n and k with hundreds of digits.

FastFactorial [n] calculates efficiently n! for very large n

BinomialMod [n, k, p] calculates Mod [Binomial [n, k], p] where p prime


number
9

APPENDIX II. VARIABLES AND FUNCTIONS


9.1 VARIABLES

In Mathematica, variables are declared via the following syntax:

· x = a, assigns the value “a” to the variable x.

· Set [x, a], assigns the value a the variable x.

· x = y = a, assigns the value “a” to the variables x and at the same time.

· {x, y} = {a1, a2}, assigns different values to x and y at the same time.

· {x, y} = {y, x}, exchanges the values of x and y

· Clear [x] (or x =.), deletes the value assigned to x

For example, we can define the variable x and assign it the value 6 in the following way:

In [1]: = x = 6
Out [1] = 6

Equivalent to the above syntax would be as follows:

In [2]: = Set [x, 6]


Out [2] = 6
9.2 FUNCTIONS DEFINITION

Mathematica offers the possibility to define custom functions using the following syntax:

f [x_]: = expression: defines the function f for single variable x

g [x_, y_]: = expression: define function g in the variables x and y.

The general form of a function definition is:

f [variable1_, variable2_,…]: = expression

clear[f]: clears the function f.

Let’s see how to define the function f (x) = x ^ 3.

In [1]: = f [x_]: = x ^ 3

Now we calculate the values f (a+1), f (4) and f(3x+x^2).

In[2]:= f[a+1]

3
Out[2]=(1+a)

In[3]:= f[4]

Out[3]= 64

In[4]:= f[3x+x^2]
23
Out[4]:= (3 x + x )
9.3 RECURSIVE FUNCTIONS

Recursive definitions of functions you can use in Mathematica. For example, to define
the function factorial of as follows:

In[18]:= fact[1]=1;
In[19]:= fact[n_]:=n*fact[n-1]

To calculate the factorial of 40, we will use the following syntax:

In [20]: = fact [5]


Out [20] = 120

Also is you can set recursive functions on the basis of n values above and according to n
initial conditions. For example:

In [1]: = f [x_]: = f [x] = f [x - 1] + f [x - 2]

In [2]: = f [0] = f [1] = 1


Out [2] = 1

To calculate f (5) we use:

In [3]: = f [5]
Out [3] = 8
9.4 PIECEWISE FUNCTIONS

Piecewise functions tend to be defined in different ways for different intervals of


variation in the independent variable. Mathematica enables correct work with this type of
functions, which are defined, in the majority of cases, relying on the conditional commands,
as If, Which, etc. In Mathematica functions such flooring defined cablul especially operator
condicuionla If using adopts the following syntax:

If [condition, expression1, expression2]

When the condition is true evaluates expression1, and when false expression2 is
evaluated.
As an application example we define the function:
In[12]:= Delta[x_] := If [x==0, 1, 0]

This function is set to 1 if x = 0 and in any other case, 0.

We then define the following function:

In [13]: = f [x_]: = If [x > 0, 1, 0]

This function takes the value 1 for all x greater than 0, and takes the value 0 for all x less
than or equal to 0.

To graphically represent this function, we propose:

In[14]:= Plot [f[x], {x, -1, 1}, Axes->{0, 0.5}]


Out [14] = see Figure 2.1
Figure 2.1

When it is necessary to control the function, rather than across a single condition, but of
several, is available the operator condicuional Wich with the following syntax:

Which [condition1, expression1,…, conditionn, expressionn]

If the conditioni is true the expressioni is evaluated (i=1, 2, …,n). Putting True
as the last condition, gets evaluate the last expression if none of the previous conditions
have been certain.

As an example we consider the piecewise-defined function look:

In[15]:=g[x_]:=Which[-2<=x<=2, x^2, -3<x<-2, x^3, x<=-3, 0,


2<x<3,x, 3<=x, 0, True,x^2]

The function g to pieces at intervals is defined (-¥, - 3) (- 3, - 2), (- 2.2), (2.3), (3,¥).

We can graphically represent the function g as follows:

In [16]: = Plot [g [x], {x, - 4, 4}]

Out [16] = see Figure 2.2


Figure 2.2

Also we can graphically represent the function for the function g as follows:

In[16]:= Plot[g’[x], {x, -4, 4}]

We will now define a function, called rect, which is set to 1 in the interval [-1/3, 1/3] and
which is worth $ 0 in the rest of the real line. We will use the notation /, which can be
interpreted as “such that” or “whenever”.

In[23]:= rect[x_] := 1 /. (-1/3 <= x && x <= 1/3)


In[24]:= rect[x_] := 0 /. Abs[x] > 1/3

This function can also be written in the following way:

In[22] := Clear[rect];
In[23] := rect[x_ /. (-1/3 <= x && x >= 1/3)] := 1
In[24] := rect[x_ /. Abs[x] > 1/3] := 0
9.5 OPERATIONS WITH FUNCTIONS

Utilizae Mathematica the following functional operators:

InverseFunction [f] inverse of the function f.

Composition [f, g,…] Composed of f, g,…

Identity identity function.

Identity [expr] applies the function identity to expr.

Nest [f, x, n] applies the function f on x, n times.

NestList [f, x, n] generates the list {x, f [x], f [f [x]]… n times].

Operate [f [x] p] calculates p [f] [x]

Operate [p, f [x], n] applies the operator p in f n times.

As examples we have the following:

In[1]:= InverseFunction[ArcSin]
Out[1]= Sin

In[2]:= f[x_]:= x^2+x

In[3]:= g[x]:= x^3+1

In[4]:= Composition[f,g][x]
Out[4:= 1+x^3+(1+x^3)^2
In[5]:= Composition[g,f][x-1]
Out[5]= 1+(-1+(-1+x)^2+x)^3

In[6]:= Composition[f,Sin][x]
Out [5] = [x] + Sin [x] ^ 2

In[9]:= Clear[f,g]

In[1]:=Nest[f, x, 4]
Out[1]= f[f[f[f[x]]]]

In[2]:= NestList[f, x, 4]
Out[2]= {x, f[x], f[f[x]], f[f[f[x]]], f[f[f[f[x]]]]}

In[18]:= t = ((1 + a)(1 + b))[x]


Out[18] = ((1 + a) (1 + b))[x]

In[20]:= Operate[p, t]
Out[20]= p[(1 + a) (1 + b)][x]
9.6 DATA TYPES USED IN THE DEFINITION OF THE
FUNCTIONS

We already know that in Mathematica there is no need to declare the type of the variables
or functions, as in C or FORTRAN. Mathematica manipulates data more as the APL
programming language: deducing the type of data based on how you are using. Each
expression that defines a function is composed of objects in one or more of the following
atomic types: Integer, Real, Rational, Complex, Symbol, and String. The following table
gives an example of each of these indivisible types and their descriptions

Type description example


–––––––––––––––––––––––––––––––––––-

Integer integer number 3


Real real number in the way nn.mm 3.4
Rational rational number a/b, a and b integers 3/4
Complex complex number of the form a + bI 3 + 4.2 I
Symbol value represented by a symbol Pi
String a string “red”

Exercise 1. Define the functions f (x) = x ^ 2, g (x) = x ^(1/2) and h (x) = x + Sin
(x). Calculate f(2), g(4), h(pi/2), f(a-b^2) and ((x+h) - f (x) f) / h

In[1]:= clear[f, g, h]

In[1]:= f[x_]= x^2

2
Out[1]= x
In[2]:= g[x_]= Sqrt[x]
Out[2]= Sqrt[x]

In[3]:= h[x_]= x+Sin[x]

In[4]:= f[2]
Out[4]= 4

In[5]:= g[4]
Out[5]= 2

In[6]:= h[Pi/2]
Out[6]= 1 + Pi/2

In[7]:= f[a-b^2]

22
Out[7]= (a- b )

In[8]:= (f[x+h]-f[x])/h
2 2
-x + (h + x)
Out[8]=–––––––––
h

Exercise 2. Given the function h defined by:

h(x,y) = (cos(x^2-y^2), sin(x^2-y^2))

Calculate h(1,2), h(-Pi,Pi), and h(cos(a^2), cos(1-a^2))


In [1]: = Clear [h]

In [2]: = h [x_, y_] = (Cos(x^2-y^2), Sin(x^2-y^2))

2 2 2 2
Out [2] = (Cos [x - y]-Sin [x - y])

In[3]:= h[1,2]
Out[3]= (Cos[3], Sin[3])

In[4]:= h[-Pi,Pi]
Out[4]= (1, 0)

In [5]: = h (cos(a^2), cos(1-a^2))


22 2 2 2 22
Out [5] = (Cos [Cos [a] - Cos [1 - a]], Sin (Cos [a] - Cos [1 - a]])

Exercise 3. Sean f (x) = x ^ 2 + x, g (x) = x ^ 3 + 1 and k (x) = Sinx + Cosx.


Calculate:

f (g (x)), g (f(x-1)), f (k(Pi/3)), f (Sinx) and f (Sin (x+iy)).

In[1]:= Clear[f,g,h]

In[2]:= f[x_]=x^2+x; g[x_]=x^3+1; k[x_]=Sinx+Cosx;

In[3]:= Composition[f, g][x]


3 3 2
Out[3]= 1 + x + (1 + x )

In[4]:= Composition[g, f][x-1]


2 3
Out[4]= 1 + (-1 + (-1 + x ) + x )

In[5]:= Composition[f, k][Pi/3]//Simplify


Out[5]= 3/2 + Sqrt[3]

In[6]:= Composition[f, Sin][x]


2
Out [6] = [x] + Sin [x]

In[7]:= Composition[f, Sin][x + I y]


2
Out [7] = [x + I y] + Sin [x + I y]

Exercise 4. Is the function given by f (x) = x ^ 2 + x. calculate f (f (f (x))) and Sin


(Sin (Sin (Sin (Sin (Sinx)))

In[1]:= Nest[f,x,3]
2 2 2 2 22 2
Out[1]:= x + x + (x + x ) + (x + x + (x + x ) )

In [2]: = Nest [Sin, x, 6]


Out [2] = Sin [Sin [Sin [Sin [Sin [Sinx]]]

Exercise 5. Fibonacci succession {an} is defined by the law of recurrence


following:
a1 = 1, a2 = 1, an = a (n-1) + a (n-2)

Represent this succession by a recurrent function and calculate a5.

In[1]:= Clear[f]
In[2]:= f[x_] := f[x] = f[x - 1] + f[x -2];
In [3]: = f [0] = f [1] = 1

Out [3] = 1

We can now calculate f (5).


In [3]: = f [5]
Out [3] = 8

Exercise 6. Define a function f (x), which is set to 1 in the interval [-1/2, 1/2] and
that is set to 0 if x is greater than 1/2, and that it is set to - 1 if x is less than - 1/2.
Represent it graphically.

We will use the notation /, which can be interpreted as such that, or whenever (some
versions of the program have this option obsolete).

In[1]:= Clear[f]

In[2]:= f[x_]:= -1 /. x < -1/2


In[3]:= f[x_] := 1 /. (-1/2 <= x && x <= 1/2)
In[4]:= f[x_] := 0 /. x > 1/2

Another way to express this function would be as follows:

In[3]:= f[x_]:= Wich[x<-1/2, -1, (-1/2<=x && x<1/2), 1, x>1/2, 0]


We now represent the function between - 3 and 3

In [4]: = Plot [f [x], {x, - 3, 3}]

Exercise 7. Calculating the compose function of f (x) = [x+Cox [x]] and its inverse.
Verify that the result is correct.

In[1]:= Clear[f]
In[2]:= f[x_]:= Sin[x+Cox[x]];
In[3]:= g[x_]:=InverseFunction[f][x]
In[4]:= Composition[f, g][x]
Out [4] = x

Obviously, the result is the identity function.

You might also like