CHAPTER 8

image

Symbolic Differential and Integral Calculus

Symbolic Computation with MATLAB. Symbolic Variables

MATLAB’s Symbolic Math Toolbox module allows you to easily manipulate and operate on formulae and expressions symbolically. It is possible to expand, factor and simplify polynomials and rational and trigonometric expressions; find algebraic solutions of polynomial equations and systems of equations; evaluate derivatives and integrals symbolically; find symbolic solutions of differential equations; manipulate powers, limits and many other facets of algebraic series. To do this, MATLAB first requires that all variables (or algebraic expressions) are declared as symbolic with the command syms (or sym). For example, if we want to treat  6 *a*b + 3 *a2 + 2 *a*b as a symbolic expression and simplify it, we first need to declare the two variables a and b as symbolic as follows:

>> syms a b
>> simplify(6*a*b + 3*a^2 + 2*a*b)

ans =
8 * a * b + 3 * a ^ 2

Alternatively, we could have used the following expression:

>> simplify(sym('6*a*b + 3*a^2 + 2*a*b'))

ans =

8 * a * b + 3 * a ^2

The MATLAB symbolic mathtoolbox provides several commands which can be used to define and manipulate symbolic variables. These are described below:

syms x y z… t

Creates symbolic variables x, y, z,…, t.

syms x y z… t real

Creates symbolic variables x, y, z,…, t and assumes they are real.

syms x y z… t unreal

Creates symbolic variables  x, y, z,…, t and assumes that they are not real.

syms

Lists the symbolic variables in the workspace.

x = sym (‘x’)

The variable x becomes symbolic (equivalent to syms x).

x = sym (‘x’, real)

The variable x becomes a real symbolic variable.

x = sym(‘x’,unreal)

The variable x becomes a non-real symbolic variable.

s = sym (A)

Creates a symbolic object from  A, where A may be a string, a scalar, an array, a numeric expression, etc.

s = sym (A, ‘option’)

Converts an array, scalar or numeric expression  A  to a symbolic object according to the specified option. The option can be ‘f’ for floating point, ‘r’ for rational, ‘e’ for an error format or ‘d’ for decimal.

double(x)

Converts the variable or expression x to numeric double-precision.

sym2poly (poly)

Returns a vector whose components are the coefficients the symbolic polynomial poly.

poly2sym (vector)

Returns a symbolic polynomial whose coefficients are the components of the vector vector.

poly2sym(vector, ‘v’)

Returns  a symbolic polynomial in the variable v whose coefficients are the components of the vector vector.

char (X)

Converts the array X of non-negative integers (interpreted as ASCII values) into a character string.

latex (S)

Convers the symbolic expression S into Latex code.

ccode (S)

Converts a symbolic expression S into C code.

fortran (s)

Converts a symbolic expression S into Fortran code.

pretty (expr)

Converts a symbolic expression into typeset mathematics.

digits (d)

Returns symbolic variables with a precision of d significant decimal digits.

digits

Returns the current accuracy for symbolic variables.

vpa (expr)

Returns the numerical result of the expression to the number of significant digits specified by digits.

vpa (expr, n)

Returns the numerical result of the expression to n significant decimal digits.

vpa(‘expr’, n)

Numerical result of the expression to n significant decimal digits.

findsym (S)

Returns all the symbolic variables in the symbolic expression or symbolic matrix S.

isvarname (S)

Returns TRUE if S is a valid symbolic variable.

vectorize (S)

Inserts a point in the string S before any symbol ^, * or / .

As a first example we consider H = 3a2 − 2a + 7, F = 6a3 − 5a + 2 and G = 5a2 + 4a − 3, and calculate: H + F + G, HF + G  and HFG.

>> syms a
>> H = 3*a^2 - 2*a + 7; F = 6*a^3 - 5*a + 2; G = 5*a^2 + 4*a - 3;
>> pretty(H+F+G)
   2                3
8 a  - 3 a + 6 + 6 a
>> pretty(H-F+G)

   2                3
8 a  + 7 a + 2 - 6 a
>> pretty(H-F-G)

    2              3
-2 a  - a + 8 - 6 a

In the following example, we carry out the following symbolic rational operations:

image

We will begin by defining the variables a, b and c as symbolic and subsequently perform the specified operations.

>> syms a b c
>> pretty(1/(2*a)+1/(3*b)+1/(4*a)+1/(5*b)+1/(6*c))

3/4 1/a + 8/15 1/b + 1/6 1/c

>> pretty((1-a)^9/(1-a)^3)

       6
(1 - a)

>> pretty(1/(1+a)+1/(1+a)^2+1/(1+a)^3)

   1        1          1
----- + -------- + --------
1 + a           2          3
         (1 + a)    (1 + a)

>> pretty (simplify (1 /(1+a) + 1 /(1+a) ^ 2 + 1 /(1+a) ^ 3))
           2
3 + 3 a + a
------------
       3
(1 + a)

Next we calculate image and image symbolically.

>> pretty(sym(sqrt(2)+3*sqrt(2)-sqrt(2)/2))

     1/2
7/2 2

>> pretty (sym (1 / (1 + sqrt (2)) + 1 / (1-sqrt (2))))

-2

In the following example, we calculate image symbolically and pass the result to numerical form.

>> r=sym(1/(2+sqrt(5)))

r =

8505245244017276*2^(-55)

>> numeric(r)

ans =
0.24

We then solve the equation x4+ 1 = 0 and present the result in typeset mathematical form.

>> solve('x^4+1=0')

ans =

[  1/2*2^(1/2)+1/2*i*2^(1/2)]
[ -1/2*2^(1/2)-1/2*i*2^(1/2)]
[  1/2*2^(1/2)-1/2*i*2^(1/2)]
[ -1/2*2^(1/2)+1/2*i*2^(1/2)]

>> pretty(solve('x^4+1=0'))

[      1/2          1/2 ]
[1/2/2 + 1/2 i 2]
[                       ]
[       1/2          1/2]
[-1/2 2 - 1/2 i 2]
[                       ]
[      1/2          1/2 ]
[1/2 2 - 1/2 i 2]
[                       ]
[       1/2          1/2]
[-1/2 2 + 1/2 i 2]

Next we transform a vector to a polynomial and vice versa.

>> pretty(poly2sym([1 0 9 6 2]))

 4      2
x  + 9 x  + 6 x + 2

>> sym2poly(x^4+9*x^2+6*x+2)

ans =

1.00 0 9.00 6.00 2.00

Below is a Hilbert matrix of order 2 whose entries have been evaluated to five significant decimal digits.

>> vpa (hilb (2), 5)

ans =

[1.,. 50000]
[. 50000,. 33333]

In the following example we define a symbolic matrix and calculate its determinant.

>> syms x
A = [cos(a*x), sin(a*x);-sin(a*x), cos(a*x)]

A =

[cos(a*x), sin(a*x)]
[-sin(a*x), cos(a*x)]

>> det (A)
ans =

cos(a*x) ^ 2 + sin(a*x) ^ 2

Next we define the previous symbolic matrix in an alternative form and calculate its inverse.

>> A = sym ([cos(a*x), sin(a*x);-sin(a*x), cos(a*x)])

A =

[cos(a*x), sin(a*x)]
[-sin(a*x), cos(a*x)]

>> pretty (inv (A))

                           [cos(a x)      sin(a x)]
                           [--------    - --------]
                           [   %1            %1   ]
                           [                      ]
                           [sin(a x)     cos (a x)]
                           [--------     -------- ]
                           [   %1           %1    ]

                                     2           2
                            %1: = cos(a x) + sin(a x)

In the following example, we calculate 1/2 + 1/3 symbolically, set the numerical precision to 25 digits and calculate the numerical value of the same expression. We finish by checking the current level of numerical accuracy.

>> sym(1/2+1/3)

ans =

5/6

>> digits(25)
vpa('1/2+1/3')

ans =

.8333333333333333333333333

>> digits

digits = 25

In the following example the ASCII characters whose numeric codes are 93, 126 and 115 are obtained.

>> char (93,126,115)

ans =

]
~
s

The following example transforms the series expansion of ln(1 +x) into Latex code, C code and FORTRAN code

>> syms x
>> f = taylor(log(1+x));
>> latex(f)

ans =

x-1/2,{x}^{2}+1/3,{x}^{3}-1/4,{x}^{4}+1/5,{x}^{5}

>> ccode(f)

ans =

A = x-x*x/2.0+x*x*x/3.0-x*x*x*x/4.0+x*x*x*x*x/5.0;

>> fortran(f)

ans =

A = x-x**2/2+x**3/3-x**4/4+x**5/5

Symbolic Functions. Substitution and Functional Operations

MATLAB’s symbolic mathematics module allows you to define symbolic functions directly using the syntax f = ‘function’ (or f = function) provided the variables have previously been defined as symbolic with syms.

Once a symbolic function has been explicitly defined, it is possible to substitute values for the variables in the function, i.e., calculate the value of the function at a given point, using the commands shown below:

subs(f, a)

Applies the function f at the point a.

subs(f,a,b)

Substitutes b in place of a in the function f.

subs (f, variable, value)

Replaces the variable variable by the value value in the function f.

subs(f, {x,y,…}, {a,b,…})

Replaces the variables {x, y,…} respectively by the values {a, b,…} in the function f.

As a first example we define the function f(x) = x3 and calculate f(2) and f(b+ 2).

>> f='x^3'

f =

x^3

>> A=subs(f,2)

A =

8

>> syms b
>> B=subs(f,b+2)

B =

(b+2) ^ 3

In the following example we consider the two-variable function f(a, b) = a+b and first replace a by 4, and then a and b respectively by 3 and 5 (i.e., we find f(3,5)).

>> syms a b
>> subs(a+b,a,4)

ans =

4+b

>> subs(a+b,{a,b},{3,5})

ans =

8

Here are three additional examples of substitutions.

>> subs (cos (a) + (b), {a, b}, {sym ('alpha'), 2})

ans =

cos (alpha) + sin (2)

>> subs('exp(a*t)','a',-magic(2))

ans =

[exp (t), exp(-3*t)]
[exp(-4*t), exp(-2*t)]

>> syms x y
>> subs(x*y,{x,y},{[0 1;-1 0],[1-1;-2 1]})

ans =

0-1
2 0

In addition to replacement, MATLAB also provides commands that allow functional operations, such as summation, subtraction, multiplication and division of functions, as well as composition and inversion. The following list summarizes the syntax of these commands:

symadd (f, g)

Adds the functions f and g (f + g)

symop(f, ‘+’, g, ‘+’, h, ‘+’,.....)

Returns the sum f+g+h +.... Note that symop is obsolete in more recent versions of   MATLAB.

symsub (f, g)

Returns the difference of f and g (f-g)

symop(f, ‘-’, g, ‘-’, h, ‘-’,.....)

Returns the difference f-g-h-…

symmul (f, g)

Returns the product of f and g (f * g)

symop(f, ‘ * ’,g, ‘ *’ , h, ‘ * ’,.....)

Returns the product f * g * h *…

symdiv (f, g)

Returns the quotient of f and g (f/g)

symop(f, ‘/’, g, ‘/’, h, ‘/’,.....)

Returns the successive quotient((f /g)/h)/…

sympow (f, k)

Raises f to the power k (k a scalar)

symop(f, ‘^’, g)

Raises a function to the power of another function (f g)

compose (f, g)

Composes f and g (f ∞ g (x) = f (g (x)))

compose(f, g, u)

Composes f and g, taking the

expression u as the domain of f and g

g = finverse (f)

Returns the inverse of the function f

g = finverse(f, v)

Returns the inverse of the function f using the symbolic variable v as an independent variable

In the following example, given the functions f(x)=x2, g(x)=x3+1 and h(x) = sin(x)+cos(x), we calculate (f+g)(x), (f-g+h)(x), (f/g)(x), f(g(x)), f(h(π/3)) and f(g(h(sin(x)))).

>> syms x
>> f = x ^ 2; g = x ^ 3 + 1; h = sin (x) + cos (x);
>> sum = symadd(f,g)

sum =

x^2+x^3+1

>> combination = symadd(symsub(f,g),h)

combination =

x ^ 2-x ^ 3-1 + sin (x) + cos (x)

>> combination = symop(f,'-',g,'+',h)

combination =

x ^ 2-x ^ 3-1 + sin (x) + cos (x)

>> quotient = symdiv (f, g)

quotient =

x ^ 2-/(x^3+1)

>> composite = subs (compose (g, f), x-1)

composite =

(x-1) ^ 6 + 1

>> composite1 = subs (compose (f, h), pi/3)

composite1 =

    1.8660

>> composite1 = subs (compose (f, h), ' pi/3')

composite1 =

(sin ((pi/3)) + cos ((pi/3))) ^ 2

>> composite2 = subs (compose (f , compose (g, h)), 'sin (x)')

composite2 =

((sin (sin (x)) + cos (sin (x))) ^ 3 + 1) ^ 2

In the following example we find the inverse of the function f(x) = sin(x2) and check that the result is correct.

>> syms x
>> f = sin(x^2)

f =

sin(x^2)

>> g = finverse(f)

g =

asin(x)^(1/2)

>> compose(f,g)

ans =

x

MATLAB also provides a group of predefined symbolic special functions, whose syntax is presented in the following table:

cosint (x)

The cosine integral, image
where γ  is the Euler–Mascheroni constant 0.5772156649…

sinint(x)

The sine integral, image.

hypergeom(n,d,z)

The generalized hypergeometric function.

lambertw(x)

The Lambert function λ(x), which is defined by the equation λ(x)eλ(x) = x.

zeta(x)

The Riemann zeta function ζ(x), defined as image.

zeta (n, x)

The Nth derivative of zeta (x).

As a first example we find the sum of the series image, whose value is ζ(4).

>> zeta (4)

ans =

1.0823

Next we find the integral image. We use the sine integral function.

>> sinint (2)

ans =

    1.6054

Mathematical Analysis Functions. Limits, Continuity, and Series

MATLAB’s symbolic mathematics module allows you to work on mathematical analysis with ease. It is possible to calculate limits, obtain derivatives, sum series, find the Taylor series of functions, calculate integrals and work with equations.

When working with limits, the same functions are applied to calculate limits of sequences, functions and  sequences of functions, and of course, to analyze the continuity of functions and convergence of numerical series and power series. The analysis for one and several variables is similar. The following functions are available.

limit (sequence, inf)

Calculates the limit of the sequence, indicated by its general term, as n tends to infinity.

limit (sequence, inf)

Calculates the limit of the sequence, indicated by its general term, as n tends to infinity.

limit (function, x, a)

Calculates the limit of the function of the variable x, indicated by its analytical expression, as the variable x tends towards the value a.

limit (function, a)

Calculates the limit of the function of the variable x, indicated by its analytical expression, as the variable x tends towards the value a.

limit (function, x, a, ‘right’)

Calculates the limit of the function of the variable x, indicated by its analytical expression, as the variable x tends to the value a from the right.

limit (function, x, a, ‘left’)

Calculates the limit of the function of the variable x, indicated by its analytical expression, as the variable x tends to the value a from the left.

symsum (S,v, a,b)

Finds the sum of the series with general term S where the variable v runs from a to b.

symsum (S, v)

Finds the sum of the series with general term S where the value of the variable v ranges from 0 to v-1.

r = symsum (S)

Returns the sum of the series with general term S in terms of the symbolic variable k (as determined by findsym) where the value of k ranges from 0 to k-1.

symsum (S, a, b)

Finds the sum of the series with general term S in terms of the symbolic variable k (as determined by findsym) where the value of k ranges from a to b.

As a first example we calculate the following sequential limits:

image

We have:

>> syms n
>> limit (((2*n-3) /(3*n-7)) ^ 4, inf)

ans =

16/81

>> limit ((3*n^3+7*n^2+1) /(4*n^3-8*n+5), n, inf)

ans =

3/4

>> limit (((n+1)/2) * ((n^4+1)/n ^ 5), inf)

ans =

1/2

>> limit (((n+1)/n ^ 2) ^(1/n), inf)

ans =

1

Next we calculate the following function limits:

image

We have:

>> syms x a
>> limit((x-1)/(x^(1/2)-1),x,1)

ans =

2

>> limit((x-(x+2)^(1/2))/((4*x+1)^(1/2)-3),2)

ans =

9/8

>> limit((1+x)^(1/x))

ans =

exp (1)

>> limit(sin(a*x)^2/x^2,x,0)

ans =

a^2

In the following example we calculate the limit of the sequence of functions gn(x) = (x2+nx) /n with x ∈ R.

>> limit((x^2+n*x)/n,n,inf)

ans =

x

We see that the graph of the limit function is given by the diagonal passing through the first and third quadrants. We can demonstrate this as follows (see Figure 8-1):

>> fplot('[(x^2+x),(x^2+2*x)/2,(x^2+3*x)/3,(x^2+4*x)/4,
(x^2+5*x)/5,(x^2+5*x)/5,(x^2+6*x)/6,(x^2+7*x)/7,(x^2+8*x)/8,
(x^2+9*x)/9]',[-2,2,-2,2])

The following example verifies the continuity of the function f(x) in R-{0} where f(x) = sin(x) /x . The following command checks that image.

>> syms x a
>> limit (sin (x) / x, x, a)

ans =

sin (a) /a

Next we show that the function image is not continuous at the point x = 0 by showing that the lateral limits do not match (one is zero and the other is infinite).

>> syms x
>> limit((exp(1/x)),x,0,'right')

ans =

inf

>> limit((exp(1/x)),x,0, 'left')

ans =

0

In the following example we determine whether the series image is convergent by applying the ratio test (image) and if it is, we calculate its sum.

>> syms n
>> f = n/2 ^ n

f =

n/(2^n)

>> limit (subs(f,n,n+1)/f, n, inf)

ans =

1/2

We see that the limit of the ratio of successive terms is less than 1, which means the series converges. We calculate its sum using the following:

>> symsum(f,n,1,inf)

ans =

2

Derivatives, Integrals and Differential Equations

We describe below the MATLAB functions which are used in mathematical analysis when dealing with derivatives, integrals and differential equations. We will begin with the differentiation-related functions.

diff(‘f’, ‘x’)

Returns the derivative of f with respect to x.

syms x, diff(f, x)

Returns the derivative of f with respect to x.

diff(‘f’, ‘x’, n)

Returns the nth derivative of f with respect to x.

syms x, diff(f, x, n)

Returns the nth derivative of f with respect to x.

r = taylor(f, n, v)

Returns the MacLaurin series of order n-1 for the

function f in the variable v.

r = taylor(f)

Returns the MacLaurin series of order 5 for the function f in the default variable.

r = taylor(f, n, v, a)

Returns the Taylor series of order n-1 for the

function f in the variable v in a neighborhood of the point a.

R = jacobian(w, v)

Returns the Jacobian matrix of w with respect to v.

Below are the integration-related functions:

syms x, int(f(x), x) or int(‘f(x)’, ‘x’)

Computes the indefinite integral image

int (int (‘f(x, y)’, ‘x’), ‘y’))

Calculates the double integral image

(syms x y int (int (f(x, y), x), y))

Calculates the double integral image

int (int (int (… int (‘f (x, y…, z)’, ‘x’), ‘y’)…), ‘z’)

Calculates image

syms x y z
int (int (int (… int (f (x, y…z), x), y)…), z)

Calculates image

syms x a b, int(f(x), x, a, b)

Calculates the definite integral image

int(‘f(x)’, ‘x’, ‘a’, ‘b’)

Calculates the definite integral image

int (int (‘f(x,y)’, ‘x’, ‘a’, ‘b’), ‘y’, ‘c’, ‘d’))

Calculates the integral image

syms x y a b c d,
(int (int (f(x,y), x, a, b), y, c, d))

Calculates the integral image

int (int (int (… int (‘f(x, y,…,z)’, ‘x’, ‘a’, ‘b’), ‘y’, ‘c’, ‘d’),…), ‘z’, ‘e’, ‘f’)

Calculates the integral image

syms x y z a b c d e f,
int (int (int (… int (f(x, y,…,z), x, a, b),)))
y, c, d),…), z, e, f)

Calculates the integral image

The following table summarizes the functions related to differential equations:

dsolve(‘e’, ‘v’)

Solves the differential equation e where v is the independent variable (if you don’t specify ‘v’, the independent variable is by default x). It returns only explicit solutions.

dsolve(‘e’, ‘c’, ‘v’)

Solves the differential equation e subject to the initial condition specified by c and where v is the independent variable.

dsolve(‘e’,‘c1’,‘c2’,…,‘cn’,‘v’)

Solves the equation differential e subject to the initial conditions specified by c1,…,cn, where v is the independent variable.

dsolve(‘e’,‘c1,c2,…,cn’,‘v’)

Solves the differential equation e subject to the specified initial conditions c1,..,cn, where v is the independent variable.

dsolve(‘e1’, ‘e2’,…, ‘en’,‘c1’, ‘c2’,…, ‘cn’, ‘v’)

Solves the system of differential equations e1,…,en, subject to the specified initial conditions c1,…,cn, where v is the independent variable.

dsolve(‘e1, e2,…, en’,‘c1, c2,…, cn’, ‘v’)

Solves the system of differential equations e1,…,en subject to the specified initial conditions c1,…,cn where v is the independent variable.

As a first example, we calculate the derivative of the function ln(sin(2x)).

>> pretty(diff('log(sin(2*x))','x'))

2 cos (2 x)
---------
sin (2 x)

This derivative can be simplified:

>> pretty(simple(diff('log(sin(2*x))','x')))

2
--------
tan(2 x)

In the following example we calculate the first, second, third and fourth derivatives of the function f(x) = 1 /x.

>> f='1/x';
[diff(f),diff(f,2),diff(f,3),diff(f,4),diff(f,5)]

ans =

[-1/x ^ 2, 2/x ^ 3, - 6/x ^ 4, 24/x ^ 5, - 120/x ^ 6]

Then, given the function f(x, y) = sin(xy) +cos(xy2), we calculate the following partial derivatives:

∂f/∂x, ∂f/∂y, ∂2f/∂x2, ∂2f/∂y2, ∂2f/∂x∂y, ∂2f/∂y∂x  y  ∂4f/∂2x∂2y

>> syms x y
>> f = sin(x*y) + cos(x*y^2)

f =

sin(x*y) + cos(x*y^2)

>> diff(f,x)

ans =

cos(x*y) *-sin(x*y^2) * y ^ 2

>> diff(f,y)

ans =

cos(x*y) * x-2 * sin(x*y^2) * x * y

>> diff(diff(f,x),x)

ans =

-sin(x*y) * y ^ 2-cos(x*y^2) * y ^ 4

>> diff (diff(f,y), y)

ans =

-sin(x*y) * x ^ 2-4 * cos(x*y^2) * x ^ 2 * y ^ 2-2 * sin(x*y^2) * x

>> diff(diff(f,x),y)

ans =

-sin(x*y) * x * y + cos(x*y)-2 * cos(x*y^2) * x * y ^ 3-2 * sin(x*y^2) * y

>> diff(diff(f,y),x)

ans =

-sin(x*y) * x * y + cos(x*y)-2 * cos(x*y^2) * x * y ^ 3-2 * sin(x*y^2) * y

>> diff(diff(diff(diff(f,x),x),y,y))

ans =

sin(x*y) * y ^ 3 * x-3 * cos(x*y) * y ^ 2 + 2 * cos(x*y^2) * y ^ 7 * x + 6 * sin(x*y^2) * y ^ 5

Next we find the Taylor series up to order 10 of the function 1 /(2-x) in a neighborhood of the point x= 1:

>> syms x
>> f=1/(2-x)

f =

1/(2-x)

>> pretty(taylor(f,11,x,1))

           2          3          4          5          6          7
x + (x - 1)  + (x - 1)  + (x - 1)  + (x - 1)  + (x - 1)  + (x - 1)

         8          9          10
+ (x - 1)  + (x - 1)  + (x - 1)

The following example computes the integral image.

>> int('1/(x^2-1)','x')

ans =

-atanh (x)

The following example estimates the integral imagefor arbitrary parameters a and b.

>> syms x a b, pretty(simple(int(a*log(1+b*x),x)))

a (log(1 + b x) - 1) (1 + b x)
------------------------------
b

The following example computes the double integral image where a is an arbitrary parameter.

>> syms x a b, pretty(simple(int(int(a*log(1+b*x),x),b)))

a (-dilog(1 + b x) + log(1 + b x) + log(1 + b x) x b - 1 - 2 b x - log(b))

The following example computes the triple integral image.

>> syms x a b, pretty(simple(int(int(int(a*log(1+b*x),x),b),a)))

    2
1/2a(-dilog(1 + b x) + log(1 + b x) + log(1 + b x) x b - 1 - 2 b x - log(b))

We calculate image.

>> syms x a b, pretty (simple (int (a * log(1+b*x), x, 0, 1)))

ab + log(1+b)+ b log (1+b) – b
------------------------------
              b

The following example computes image, where a is an arbitrary parameter.

>> syms x a b, pretty(simple(int(int(a*log(1+b*x),x,0,1),b,2,3)))

a (8 log (2) - 2 - dilog (4) - 3 log (3) + dilog (3))

In the following example we solve the first order first degree differential equation y' (t) = ay(t) where a is an arbitrary parameter.

>> pretty(dsolve('Dy = a*y'))

C1 exp (a t)

Thus we see that the family of solutions turns out to be y(t) = c1eat.

Now we solve the above differential equation with the initial condition y(0) = b.

>> pretty(dsolve('Dy = a*y', 'y(0) = b'))

b exp (a t)

Next we solve the first order second degree differential equation y'2 (s)+ y2(s) = 1 with the initial condition y(0) = 0.

>> y = dsolve ('(Dy) ^ 2 + y ^ 2 = 1', ' (0) = 0', y 's')

y =

[-sin (s)]
[sin (s)]

Now we solve the second order first degree differential equation  y" (t)= a2y’(t) with the initial conditions y(0) = 1 and y’(π/a) = 0.

>> pretty (dsolve ('D2y = - a ^ 2 * y ', 'y(0) = 1, Dy (pi/a) = 0'))

cos (a t)

Therefore, the solution is the function y(t) = cos(at).

In the following example we solve the system of equations: x'(t) = y(t),  y' (t) = -x(t).

>> [x, y] = dsolve('Dx = y', 'Dy =-x')

x =

cos (t) * C1 + sin (t) * C2

y =

-sin (t) * C1 + cos (t) * C2

Next we calculate the solution of the previous system of differential equations for the initial conditions x(0) = 0 and y(0) = 1.

>> [x, y] = dsolve ('Dx = y, Dy = - x', 'x (0) = 0, y (0) = 1')

x =

sin (t)

y =

cos (t)

Linear Algebra: Simplifying and Solving Equations

Calculations with simple, rational and complex algebraic expressions are specially treated in MATLAB. The Symbolic Match toolbox functions efficiently implement the operations of simplification, factorization, grouping and expansion of algebraic expressions, and includes trigonometric expressions and expressions in a complex variable. The syntax of these functions is as follows.

r = collect(S)

r = collect(S, v)

Each polynomial in the array of polynomials S is grouped in terms of the variable v (or x if v is not specified).

r = expand (S)

Expands each polynomial or trigonometric, exponential or logarithmic function contained in S.

factor(x)

Factors x (symbolic or numerical).

r = horner (p)

Converts the polynomial p into its Horner, or nested, polynomial representation.

[n, d] = numden (A)

Converts each element of the symbolic or numerical matrix A to a simplified rational form.

r = simple(s)

[r,how] = simple(s)

Simplifies the symbolic expression s looking for the shortest possible output. The second option presents only the final result and a string describing the particular simplification.

r = simplify (S)

Simplifies each element of the symbolic matrix S.

[y, sigma] = subexpr (x, sigma)

[y, sigma] = subexpr (x, ‘sigma’)

Rewrites the symbolic expression x in terms of a common subexpression, substituting this subexpression with the symbolic variable sigma.

As a first example we group the expression y(sin(x) + 1) +sin(x) in terms of sin(x).

>> syms x and
>> pretty (collect (y * (sin (x) + 1) + sin (x), sin (x)))

(y + 1) sin (x) + y

Next we group, firstly in terms of x, and then ln(x), the function f(x) = aln(x)-xln(x)-x.

>> syms a x
>> f=a*log(x)-log(x)*x-x

f =

a*log(x)-log(x)*x-x

>> pretty(collect(f,x))

(- log (x) - 1) x + log (x)

>> pretty(collect(f,log(x)))

(a - x) log (x) - x

In the following example we expand various algebraic expressions.

>> syms a b x y t
>> expand([sin(2*t), cos(2*t)])

ans =

[2 * sin (t) * cos (t), 2 * cos (t) ^ 2-1]

>> expand(exp((a+b)^2))

ans =

exp(a^2) * exp(a*b) ^ 2 * exp(b^2)

>> expand (cos (x + y))

ans =

cos (x) * cos (y) - sin (x) * sin(y)

>> expand((x-2)*(x-4))

ans =

x^2-6*x+8

Next we factorize various expressions.

>> factor(x^3-y^3)

ans =

(x - y) *(x^2+x*y+y^2)

>> factor([a^2-b^2, a^3+b^3])

ans =

[(a-b)*(a+b), (a+b)*(a^2-a*b+b^2)]

>> factor(sym('12345678901234567890'))

ans =

(2) * (3) ^ 2 * (5) * (101) * (3803) * (3607) * (27961) * (3541)

Below we simplify various expressions.

>> syms x y z a b c
>> simplify(exp(c*log(sqrt(a+b))))

ans =

(a + b) ^(1/2*c)
>> simplify (sin (x) ^ 2 + cos (x) ^ 2)

ans =

1

>> S = [(x^2+5*x+6)/(x+2),sqrt(16)];
R = simplify(S)

R =

[ x+3,   4]

The following functions can be used to solve symbolic equations and systems of equations:

solve(‘equation’, ‘x’)

Solves the equation in terms of the variable x.

syms x; solve(equation,x)

Solve the equation in terms of the variable x.

solve(‘e1,e2,…,en’, ‘x1,x2,…,xn’)

Solves the system of equations e1,…,en in terms of the variables x1,…, xn.

syms x1 x2… xn;

solve(e1,e2,…,en, x1,x2,…,xn)

Solves the system of equations e1,…,en in terms of the variables x1,…, xn.

As a first example we solve the equation 3ax- 7x2+x3= 0 in terms of x, where a is a parameter.

>> solve('3*a*x-7*x^2+x^3=0','x')

ans =

[                       0]
[7/2 + 1/2 *(49-12*a) ^(1/2)]
[7/2-1/2 *(49-12*a) ^(1/2)]

Next we solve the above equation where a is the variable and x is the parameter.

>> pretty(solve('3*a*x-7*x^2+x^3=0','a'))

-1/3 x (- 7 + x)

In the following example, we calculate the fourth roots of - 1 and 1.

>> S=solve('x^4+1=0')

S =

[  1/2*2^(1/2)+1/2*i*2^(1/2)]
[ -1/2*2^(1/2)-1/2*i*2^(1/2)]
[  1/2*2^(1/2)-1/2*i*2^(1/2)]
[ -1/2*2^(1/2)+1/2*i*2^(1/2)]

>> numeric(S)

ans =

0.70710678118655 + 0.70710678118655i
-0.70710678118655 - 0.70710678118655i
0.70710678118655 - 0.70710678118655i
-0.70710678118655 + 0.70710678118655i

>> S1=solve('x^4-1=0')

S1 =

[  1]
[ -1]
[  i]
[ -i]

Next we calculate the fifth roots of the complex number 2 + 2i.

>> numeric(solve('x^5-(2+2*i)=0'))

ans =

1.21598698264961 + 0. 19259341768888i
0.19259341768888 + 1. 21598698264961i
-1.09695770450838 + 0. 55892786746601i
-0.87055056329612 - 0. 87055056329612i
0.55892786746601 1. 09695770450838i

In the following example we solve the equation sin(x)cos(x)=a in the variable x:

>> simple (solve ('sin (x) * cos (x) = a', 'x'))

ans =

 pi/2 - asin(2*a)/2
        asin(2*a)/2

>> pretty(ans)

  +-                -+
  |  pi   asin(2 a)  |
  |  -- - ---------  |
  |  2        2      |
  |                  |
  |     asin(2 a)    |
  |     ---------    |
  |         2        |
  +-                -+

If we solve the above equation for the particular case a= 0 we get:

>> solve ('sin (x) * cos (x) = 0', 'x')

ans =

[       0]
[1/2 * pi]
[-1/2 * pi]

In the following example we solve the system u + v + w = a, 3u + v = b, u -2v - w = 0, where u, v and w are variables and a, b and c parameters.

>> syms u v w a b c
>> [u, v, w] = solve('u+v+w=a,3*u+v=b,u-2*v-w=c',u,v,w)

u =

1/5 * b + 1/5 * + 1/5 * c

v =

2/5 * b-3/5 * a-3/5 * c

w =

-3/5 * b + 7/5 * + 2/5 * c

EXERCISE 8-1

Consider the symbolic matrix A below:

image

Calculate A’, A-1, determinant (A), trace (A), range (A).

We start by defining the symbolic matrix of our problem as follows:

>> A=sym('[a,b,c; 3*c,a-3*c,b; 3*b,-3*b+3*c,a-3*c]')

A =

[   a,       b,    c]
[ 3*c,   a-3*c,    b]
[ 3*b,-3*b+3*c,a-3*c]

Alternatively, the same symbolic matrix can be defined by previously declaring all the variables as symbolic as follows:

>> syms a b c
>> A=sym([a,b,c; 3*c,a-3*c,b; 3*b,-3*b+3*c,a-3*c])

A =

[        a,        b,        c]
[      3*c,    a-3*c,        b]
[      3*b, -3*b+3*c,    a-3*c]

>> transpose (A)

ans =

[a, 3 * c, * 3B]
[b, a-3*c, -3*b+3*c]
[c,     b,    a-3*c]

>> pretty(inv(A))

   2            2      2                      2         2           2
[ a  - 6 a c + 9 c  + 3 b  - 3 b c        a b - 3 c       - b  + a c - 3 c ]
[ -------------------------------    ------------    -------------- ]
[               %1                        %1                 %1     ]
[                                                                   ]
[           2           2       2                               2   ]
[        - b  + a c - 3 c        a  - 3 a c - 3 b c         a b - 3 c    ]
[      - 3 ---------------    ------------------     - ----------   ]
[                %1                  %1                     %1      ]
[                                                                   ]
[                   2                     2       2                 ]
[          a b - 3 c         a b - a c + b       a  - 3 a c - 3 b c ]
[      - 3 ----------      3 ---------------     ------------------ ]
[               %1                   %1                    %1       ]

        3        2      2          2                3      3        2
%1 :=  a  - 6 c a  + 9 c  a + 3 a b  - 9 a b c + 9 c  + 3 b  + 9 b c

>> pretty(det(A))

 3        2      2          2                3      3        2
a  - 6 c a  + 9 c  a + 3 a b  - 9 a b c + 9 c  + 3 b  + 9 b c

>> pretty(trace (A))

3 a - 6 c

>> rank(A)

ans =

3

>> A^2

ans =

[ a^2+6*b*c,         a*b+b*(a-3*c)+c*(-3*b+3*c), a*c+b^2+c*(a-3*c)]
[3*a*c+3*c*(a-3*c)+3*b^2, 3*b*c+(a-3*c)^2+b*(-3*b+3*c), 3*c^2+2*b*(a-3*c)]
[3*a*b+3*c*(-3*b+3*c)+3*b*(a-3*c), 3*b^2+2*(-3*b+3*c)*(a-3*c), 3*b*c+(a-3*c)^2+b*(-3*b+3*c)]

EXERCISE 8-2

Find the intersection of the hyperbolas with equations x2 - y2= 1 and y2x2 - b2y2= 16 with the parabola z2 = 2 x.

We solve the system of three equations as follows:

>> [x, y, z] = solve('a^2*x^2-b^2*y^2=16','x^2-y^2=1','z^2=2*x', 'x,y,z')

x =

[  1/2*(((b^2-16)/(a^2-b^2))^(1/4)+i*((b^2-16)/(a^2-b^2))^(1/4))^2]
[  1/2*(((b^2-16)/(a^2-b^2))^(1/4)+i*((b^2-16)/(a^2-b^2))^(1/4))^2]
[ 1/2*(-((b^2-16)/(a^2-b^2))^(1/4)+i*((b^2-16)/(a^2-b^2))^(1/4))^2]
[ 1/2*(-((b^2-16)/(a^2-b^2))^(1/4)+i*((b^2-16)/(a^2-b^2))^(1/4))^2]
[  1/2*(((b^2-16)/(a^2-b^2))^(1/4)-i*((b^2-16)/(a^2-b^2))^(1/4))^2]
[  1/2*(((b^2-16)/(a^2-b^2))^(1/4)-i*((b^2-16)/(a^2-b^2))^(1/4))^2]
[ 1/2*(-((b^2-16)/(a^2-b^2))^(1/4)-i*((b^2-16)/(a^2-b^2))^(1/4))^2]
[ 1/2*(-((b^2-16)/(a^2-b^2))^(1/4)-i*((b^2-16)/(a^2-b^2))^(1/4))^2]

y =

[  1/(a^2-b^2)*(-(a^2-b^2)*(a^2-16))^(1/2)]
[ -1/(a^2-b^2)*(-(a^2-b^2)*(a^2-16))^(1/2)]
[  1/(a^2-b^2)*(-(a^2-b^2)*(a^2-16))^(1/2)]
[ -1/(a^2-b^2)*(-(a^2-b^2)*(a^2-16))^(1/2)]
[  1/(a^2-b^2)*(-(a^2-b^2)*(a^2-16))^(1/2)]
[ -1/(a^2-b^2)*(-(a^2-b^2)*(a^2-16))^(1/2)]
[  1/(a^2-b^2)*(-(a^2-b^2)*(a^2-16))^(1/2)]
[ -1/(a^2-b^2)*(-(a^2-b^2)*(a^2-16))^(1/2)]

z =

[  ((b^2-16)/(a^2-b^2))^(1/4)+i*((b^2-16)/(a^2-b^2))^(1/4)]
[  ((b^2-16)/(a^2-b^2))^(1/4)+i*((b^2-16)/(a^2-b^2))^(1/4)]
[ -((b^2-16)/(a^2-b^2))^(1/4)+i*((b^2-16)/(a^2-b^2))^(1/4)]
[ -((b^2-16)/(a^2-b^2))^(1/4)+i*((b^2-16)/(a^2-b^2))^(1/4)]
[  ((b^2-16)/(a^2-b^2))^(1/4)-i*((b^2-16)/(a^2-b^2))^(1/4)]
[  ((b^2-16)/(a^2-b^2))^(1/4)-i*((b^2-16)/(a^2-b^2))^(1/4)]
[ -((b^2-16)/(a^2-b^2))^(1/4)-i*((b^2-16)/(a^2-b^2))^(1/4)]
[ -((b^2-16)/(a^2-b^2))^(1/4)-i*((b^2-16)/(a^2-b^2))^(1/4)]

EXERCISE 8-3

Evaluate the following integrals:

image

For the first integral the integrand is an even function, so our integral between -3 and 3 will be twice the integral between 0 and 3. Then we make the change of variable 2t = v, and arrive at the integral:

image

whose solution by MATLAB is as follows:

>> (2/3) * (sinint (6))

ans =

    0.9498

To calculate the second integral we have in mind the following:

image

which can be calculated in MATLAB as follows:

>> cosint(5) - 0.577215664-log(5)

ans =

   -2.3767

EXERCISE 8-4

Given the function h defined by h(x,y) = (cos(x2-y2), sin(x2-y2)), calculate h(1,2), h(-π,π) and h(cos (a2), cos (1-a2)).

We create a vector of two functions as follows:

>> syms x y a.
>> h = [cos(x^2-y^2), sin(x^2-y^2)]

h =

[cos(x^2-y^2), sin(x^2-y^2)]

Now we calculate the requested values:

>> subs(h,{x,y},{1,2})

ans =

-0.9900-0.1411

>> subs(h,{x,y},{-pi,pi})

ans =

     1 0

>> subs (h, {x, y}, {cos(a^2), cos(1-a^2)})

ans =

[cos (cos(a^2) ^ 2-cos(-1+a^2) ^ 2), sin (cos(a^2) ^ 2-cos(-1+a^2) ^ 2)]

EXERCISE 8-5

Given the function f defined by:

image

find f (0,0) and represent f graphically.

In this case, since it is necessary to represent the function graphically, we define it in the M-file shown in Figure 8-2.

Now we calculate the value of f at (0,0):

>> func2 (0,0)

ans =

0.9810

To create the graph of the function (in a neighborhood of the origin), we use the command meshgrid to define the surface characteristics, and the command surf to draw the surface:

>> [x, y] = meshgrid(-0.5:.05:0.5,-0.5:.05:0.5);
>> z = func2(x,y);
>> surf (x, y, z)

This yields the graph shown in Figure 8-3:

EXERCISE 8-6

Given the functions f (x) = sin (cos (x1/2)) and g (x) = sqrt (tan(x 2)) calculate the composite of f and g and the composite of g and f. Also calculate the inverses of f and g.

>> syms x, f = sin (cos (x ^(1/2)));
>> g=sqrt(tan(x^2));
>> simple(compose(f,g))

ans =

sin (cos (tan(x^2) ^(1/4)))

>> simple (compose(g,f))

ans =

tan (sin (cos (x ^(1/2))) ^ 2) ^(1/2)

>> F = finverse (f)

F =

acos (asin (x)) ^ 2

>> G = finverse (g)

G =

atan(x^2) ^(1/2)

EXERCISE 8-7

Define the function f(x) as:

image

and study its continuity on the real line.

Except at the point  x = 0 the continuity is clear. To analyze the behavior of the function at the point x = 0 we calculate the lateral limits as x0:

>> syms x
limit(1/(1+exp(1/x)),x,0,'right')

ans =

0

>> limit(1/(1+exp(1/x)),x,0,'left')

ans =

1

The limit of the function as x0 does not exist because the lateral limits are different. But, since the lateral limits are finite, the discontinuity at x = 0 is a finite jump (also known as a discontinuity of the first kind). We illustrate this result in the graph shown in Figure 8-4.

>> fplot('1/(1+exp(1/x))',[-5,5])

EXERCISE 8-8

Study the continuity of the function f: R2→R defined by:

image

Since the function is clearly continuous elsewhere, we only need to check the continuity of the function at (1,0). We need to show that.

image

» syms x y m a r
» limit (limit (y ^ 2 *(x-1) ^ 2 / (y ^ 2 +(x-1) ^ 2), x, 0), y, 0)

ans =

0

» limit (limit (y ^ 2 *(x-1) ^ 2 / (y ^ 2 + (x-1) ^ 2), y, 0), x, 0)

ans =

0

» limit((m*x)^2*(x-1)^2/((m*x)^2+(x-1)^2),x,0)

ans=

0

» limit ((m*x) *(x-1) ^ 2/((m*x) +(x-1) ^ 2), x, 0)

ans =
0

Thus we see that the iterated and directional limits (along the lines y = mx) coincide, which leads us to believe that the limit exists and that its value is zero. To corroborate these results we calculate the limit in polar coordinates:

» limit (limit ((r ^ 2 * sin (a) ^ 2) * (r * cos (a) - 1) ^ 2 / ((r ^ 2 * sin (a) ^ 2)
+ (r * cos (a) - 1) ^ 2), r, 1), a, 0)

ans =

0

We conclude that the limit is zero at the point (1,0), which ensures the continuity of the function. In Figure 8-5 we graph the surface defined by f, and in particular illustrate the continuity and the tendency to 0 of the function in a neighborhood of the point (1,0).

» [x, y] = meshgrid(0:0.05:2,-2:0.05:2);
z=y.^2.*(x-1).^2./(y.^2+(x-1).^2);
mesh(x,y,z), view ([- 23, 30])

EXERCISE 8-9

Find the sum of each of the following series:

image

image

where p is a parameter.

Before finding the sums we first need to determine whether the series do indeed converge. We apply the ratio test for the first series:

>> syms n
>> f=(3+2*n)/((1-n)*n*7^n);
>> pretty(f)

3 + 2 n
------------
           n
(1 - n) n 7

>> limit(subs(f,n,n+1)/f,n,inf)

ans =

1/7

As the limit is less than 1, the series is convergent. We will calculate its sum. The result MATLAB returns will often be complicated and depend on certain special functions. We obtain the following:

>> S1 = symsum(f,n,2,inf)

S1 =

-6 * log(6/7)-22/21 + 13/343 * hypergeom([2, 2],[3],1/7)

Now we apply the ratio test for the second series.

>> syms n p
>> g=n/p^n;
>> pretty(g)

 n
----
  n
 p

>> limit(subs(g,n,n+1)/g,n,inf)

ans =

1/p

Thus, if p > 1, the series converges, and if  p < 1, the series diverges, and if p = 1, we get the series with general term n, which diverges. When p is greater than 1,we can find the sum of the series:

>> S2=symsum(g,n,2,inf)

S2 =

2/p^2*(1/2/(-1+p)^3*p^4*(-1/p+1)-1/2*p)

>> pretty(simple(S2))

-1 + 2 p
-----------
           2
p (- 1 + p)

EXERCISE 8-10

Find the MaClaurin series of order 13 of the function sinh(x). Also find the Taylor series of order 6 of the function 1 /(1+x) in a neighborhood of the point x = 1.

>> pretty(taylor(sinh(x),13))

         3          5           7             9               11
x + 1/6 x  + 1/120 x  + 1/5040 x  + 1/362880 x  + 1/39916800 x

>> pretty(taylor(1/(1+x),6,1))

                       2              3              4              5
3/4 - 1/4 x + 1/8 (x - 1)  - 1/16 (x - 1)  + 1/32 (x - 1)  - 1/64 (x - 1)

EXERCISE 8-11

Study the function

image

calculating the asymptotes, maxima, minima, inflexion points, intervals of growth and decrease and intervals of concavity and convexity.

>> f='x ^ 3 /(x^2-1)'

f =

x ^ 3 /(x^2-1)

>> syms x, limit (x ^ 3 /(x^2-1), x, inf)

ans =

NaN

Thus, there are no horizontal asymptotes. To see if there are vertical asymptotes, we look at the values of x that make y infinite:

>> solve('x^2-1')

ans =

[1]
[-1]

The vertical asymptotes are the lines x = 1 and x =-1. Now let us see if there are any oblique asymptotes:

>> limit(x^3/(x^2-1)/x,x,inf)

ans =

1

>> limit(x^3/(x^2-1)-x,x,inf)

ans =

0

The line y = x is an oblique asymptote. Now we will analyze the maxima and minima, inflection points and intervals of concavity and growth of the function:

>> solve (diff (f))

ans =

[       0]
[       0]
[3 ^(1/2)]
[^(1/2) - 3]

The first derivative vanishes at x = 0, image and image. These include maximum and minimum candidates. To verify if they are maxima or minima, we find the value of the second derivative at those points:

>> [numeric(subs(diff(f,2),0)),numeric(subs(diff(f,2),sqrt(3))),
numeric(subs(diff(f,2),-sqrt(3)))]

ans =

0 2.5981 - 2.5981

Therefore, at the point with abscissa image there is a maximum and at the point with abscissa image there is a minimum. At x = 0 we know nothing:

>> [numeric (subs (f, sqrt (3))), numeric (subs (f, - sqrt (3)))]

ans =

2.5981 - 2.5981

Therefore, the maximum is at (-√3,-2.5981) and the minimum is at √3, 2.5981).

We will now analyze the points of inflection:

>> solve(diff(f,2))

ans =

[         0]
[ i*3^(1/2)]
[-i * 3 ^(1/2)]

The only possible turning point occurs at x = 0, and as f(0) = 0, this possible turning point is (0,0):

>> subs (diff(f,3), 0)

ans =

-6

As the third derivative at x = 0 is not zero, we see that the origin is indeed a turning point:

>> pretty(simple(diff(f)))
                              2   2
                            x  (x  - 3)
                            ------------
                               2     2
                             (x  - 1)

The curve is increasing when y’ > 0, i.e., in the intervals(-∞,-√3 ) and (√3, ∞).

The curve is decreasing when y’ < 0, i.e., in the defined intervals (-√3,-1),  (-1,0),  (0,1) and (1, √3).

>> pretty(simple(diff(f,2)))

        2
  2 x (x  + 3)
  ------------
     2     3
   (x  - 1)

The curve is concave when y "> 0, i.e., in the intervals (-1,0) and (1, ∞ ).

The curve is convex when y "< 0, i.e. in the intervals (0,1) and (- ∞ , - 1).

The curve has a horizontal tangent at the three points at which the first derivative is zero. The equations of the horizontal tangents are y = 0, y = 2.5981 and  y = -2.5981.

The curve has a vertical tangent at the points that make the first derivative infinite. These are x = 1 and x =-1. Therefore, the vertical tangents coincide with the two vertical asymptotes.

We graph the curve together with its asymptotes (see Figure 8-6):

>> fplot('[x^3/(x^2-1),x]',[-5,5,-5,5])

We can also show the curve, its asymptotes and its horizontal and vertical tangents in the same graph (Figure 8-7):

>> fplot('[x^3/(x^2-1),x,2.5981,-2.5981]',[-5,5,-5,5])

EXERCISE 8-12

Given the vector function (u(x,y), v(x,y)), where:

image

determine the conditions under which we can find the inverse vector function (x(u,v), y(u,v)) with x = x(u, v) and y = y(u,v) and find the derivative and the Jacobian of the inverse transformation. Find the value of this inverse function at the point (π/4,-π/4).

To find the conditions under which the function is invertible we appeal to the inverse function theorem. The functions are differentiable with continuous derivatives, except perhaps at x= 0. Now we consider the Jacobian of the transformation ∂ (u(x, y), v(x,y)) /(x, y):

>> syms x y
>> J=simple((jacobian([(x^4+y^4)/x,sin(x)+cos(y)],[x,y])))

J =

[ 3*x^2-1/x^2*y^4,         4*y^3/x]
[          cos(x),         -sin(y)]

>> pretty(det(J))

                               4           4      3
                     3 sin(y) x  - sin(y) y  + 4 y  cos(x) x
                   - ---------------------------------------
                                        2
                                       x

Therefore, at the points where this expression does not vanish, we can solve for x and y in terms of u and v. In addition, we must also have x0.

We calculate the derivative of the inverse function. Its value is the inverse of the Jacobian matrix of the original function found above and the determinant of its Jacobian is the reciprocal of the determinant of the Jacobian of the original function:

>> I=simple(inv(J));
>> pretty(simple(det(I)))

                                        2
                                       x
                   - ---------------------------------------
                               4           4      3
                     3 sin(y) x  - sin(y) y  + 4 y  cos(x) x

We now find the value of this inverse function at the point (π/4,-π/4):

>> numeric(subs(subs(determ(I),pi/4,'x'),-pi/4,'y'))

ans =

0.38210611216717

>> numeric(subs(subs(symdiv(1,determ(J)),pi/4,'x'),-pi/4,'y'))

ans =

0.38210611216717

These results confirm that the determinant of the Jacobian of the inverse function is the reciprocal of the determinant of the Jacobian of the original function.

EXERCISE 8-13

Given the function image and the transformation u = u(x,y) = x + y, v = v(x,y) = x, find f(u,v).

We calculate the inverse transformation and its Jacobian to apply the change of variables theorem:

>> syms x y u v
>> [x,y]=solve('u=x+y,v=x','x','y')

x =

v

y =

u-v

>> jacobian([v,u-v],[u,v])

ans =

[  0,  1]
[  1, -1]

>> f=exp(x-y);
>> pretty(simple(subs(f,{x,y},{v,u-v})* abs(det(jacobian(
[v,u-v],[u,v])))))
exp(2 v - u)

The requested function is f(u,v)= e 2v-u.

EXERCISE 8-14

Find the following integrals:

image

>> syms x
>> pretty(simple(int(x^(-3)*(x^2+3*x-1)^(-1/2),x)))
        2           1/2         2           1/2
      (x  + 3 x - 1)          (x  + 3 x - 1)
  1/2 ----------------- + 9/4 -----------------
              2                       x
             x

                             -2 + 3 x
         + 31/8 atan(1/2 -----------------)
                           2           1/2
                         (x  + 3 x - 1)
>> pretty(simple(int(x^(-1)*(9-4*x^2)^(1/2), x)))
                            2 1/2                 3
                    (9 - 4 x )    - 3 atanh(-------------)
                                                    2 1/2
                                            (9 - 4 x )
>> pretty(simple(int(x^8*(3+5*x^3)^(1/4),x)))

                                3        6         9          3 1/4
            4/73125 (288 - 120 x  + 125 x  + 1875 x ) (3 + 5 x )

EXERCISE 8-15

Consider the following curve, given in polar coordinates, r = 3-3cos (a). Calculate the length of the arc corresponding to one complete revolution (0≤a≤2π).

>> r='3-3*cos(a)';
>> diff(r,'a')

ans =

3 * sin (a)

>> R = simple (int ('((3-3 * cos (a)) ^ 2 + (3 * sin (a)) ^ 2) ^(1/2) ',' a ', ' 0','2 * pi'))

R =

24

EXERCISE 8-16

Calculate the value of the following integral:

image

which represents the area under the normal curve between the specified limits.

>> numeric(int('exp(-x^2/2)/(2*pi)^(1/2)','x',-1.96,1.96))

ans =

0.95000420970356

EXERCISE 8-17

Find the intersection of the surfaces ax2+ y2= z and z=a2-y2 and calculate the volume enclosed in the intersection. Also find the volume enclosed in the intersection of the surfaces z = x2 and 4 - y2= z.

The first volume is calculated by means of the integral:

>> pretty(simple(int(int(int('1','z','a*x^2+y^2',
'a^2-y^2'),'y',0,'sqrt((a^2-a*x^2)/2)'),'x',0,'sqrt(a)')))
        /
       |                 2       2        2 1/2
  1/24 |    lim       3 a  x (2 a  - 2 a x )
       |       1/2
        x -> (a   )-

                            1/2  1/2                              
          7/2  1/2         2    a    x              2        2 3/2|
     + 3 a    2    atan(------------------) + x (2 a  - 2 a x )   |
                            2        2 1/2                        |
                        (2 a  - 2 a x )                           /

To calculate the second volume we first produce a graph of the requested intersection, with the aim of clarifying the limits of integration, using the following syntax:

>> [x, y] = meshgrid(-2:.1:2);
z = x ^ 2;
mesh(x,y,z)
hold on;
z = 4 - y. ^ 2;
mesh (x, y, z)

9781484203118_Fig08-08.jpg

Figure 8-8.

Now we can find the requested volume by calculating the following integral:

>> pretty(simple(int(int(int('1','z','x^2','4-y^2'),
'y',0,'sqrt(4-x^2)'),'x',0,2)))

2 pi

EXERCISE 8-18

Solve the following equation:

image

>> pretty(simple(dsolve('Dy=(x*y)/(y^2-x^2)')))

  +-                                                               -+
  |                                 0                               |
  |                                                                 |
  |                                1                                |
  | -------------------------------------------------------------   |
  |                    /            /    /  1      2(C3 + t x)   |
  |                    | wrightOmega| log| - -- | - ----------- | | |
  |                    |            |    |    2 |       2       | | |
  |    / C3 + t x     |                   x  /      x        / | |
  | exp| -------- | exp| ----------------------------------------   |
  |    |     2    |                         2                   /  |
  |        x     /                                                 |
  +-                                                               -+

EXERCISE 8-19

Solve the following equations:

9y''''-6y"' + 46y"-6y' + 37y = 0

3y"+ 2y'-5y = 0

2y"+ 5y' + 5y = 0

where y (0) = 0 and y´ (0) = ½.

>> pretty(simple(dsolve('9*D4y-6*D3y+46*D2y-6*Dy+37*y=0')))

C1 sin(t) + C2 cos(t) + C3 exp(1/3 t) sin(2 t) + C4 exp(1/3 t) cos(2 t)

>> pretty(dsolve('3*D2y+2*Dy-5*y=0'))

C1 exp(t) + C2 exp(- 5/3 t)

>> pretty(dsolve('2*D2y+5*Dy+5*y=0','y(0)=0,Dy(0)=1/2'))

                 1/2                        1/2
                   2/15 15    exp(- 5/4 t) sin(1/4 15    t)

EXERCISE 8-20

Subject to the initial conditions x(0) = 1 and y(0) = 2, solve the following system of equations:

x'  -  y = e-t

y' + 5 x + 2 y = sin (3t).

>> [x,y]=dsolve('Dx-Dy=exp(-t),Dy+5*x+2*y=sin(3+t)','x(0)=1,y(0)=2','t')

x =

(-7/50*sin(3)+1/50*cos(3)+7/6)*exp(-7*t)+7/50*sin(3+t)-1/50*cos(3+t)-1/6*exp(-t)

y =

(-7/50*sin(3)+1/50*cos(3)+7/6)*exp(-7*t)+5/6*exp(-t)+7/50*sin(3+t)-1/50*cos(3+t)

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset