23
Functions — Exercises with Solutions — Laurenz Wiskott Institut f¨ ur Neuroinformatik Ruhr-Universit¨ at Bochum, Germany, EU 2 February 2017 Contents 1 Scalar functions in one variable 2 1.1 Elementary transformations ..................................... 2 1.1.1 Exercise: Stepwise transformation of an elementary function .............. 2 1.1.2 Exercise: Stepwise construction of a given function .................... 4 1.1.3 Exercise: Stepwise construction of a given function .................... 5 1.2 Combination of functions ...................................... 6 1.2.1 Exercise: Combinations of functions ............................ 6 1.3 Composition of functions ...................................... 7 1.3.1 Exercise: Composite functions ............................... 7 1.3.2 Exercise: Composite functions ............................... 9 1.3.3 Exercise: Analytical expressions for given function graphs ................ 9 1.4 Logarithmic plots ........................................... 11 2 Scalar functions in two variables 11 2.1 Visualization ............................................. 11 2.1.1 Set of curves ......................................... 11 2.1.2 Contour graphics ....................................... 11 2.1.3 3D-graphics / surface plot .................................. 11 2.2 Elementary transformations ..................................... 11 2.3 Linear coordinate transformations ................................. 11 2.3.1 Exercise: Stepwise transformation of a simple function .................. 11 2.3.2 Exercise: Stepwise transformation of a simple function .................. 12 2.3.3 Exercise: Simplify a function with stepwise transformations ............... 13 2017 Laurenz Wiskott (ORCID http://orcid.org/0000-0001-6237-740X, homepage https://www.ini.rub.de/PEOPLE/ wiskott/). This work (except for all figures from other sources, if present) is licensed under the Creative Commons Attribution- ShareAlike 4.0 International License, see http://creativecommons.org/licenses/by-sa/4.0/. These exercises complement my corresponding lecture notes, and there is a version with and one without solutions. The table of contents of the lecture notes is reproduced here to give an orientation when the exercises can be reasonably solved. For best learning effect I recommend to first seriously try to solve the exercises yourself before looking into the solutions. More teaching material is available at https://www.ini.rub.de/PEOPLE/wiskott/Teaching/Material/. 1

Functions - Ruhr University Bochum · parabula by 21 at the extrema of the cosine function. One can therefore rst draw the parabula x=20 and mark the zero crossings of the cosine

  • Upload
    others

  • View
    3

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Functions - Ruhr University Bochum · parabula by 21 at the extrema of the cosine function. One can therefore rst draw the parabula x=20 and mark the zero crossings of the cosine

Functions

— Exercises with Solutions —

Laurenz WiskottInstitut fur Neuroinformatik

Ruhr-Universitat Bochum, Germany, EU

2 February 2017

Contents

1 Scalar functions in one variable 2

1.1 Elementary transformations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2

1.1.1 Exercise: Stepwise transformation of an elementary function . . . . . . . . . . . . . . 2

1.1.2 Exercise: Stepwise construction of a given function . . . . . . . . . . . . . . . . . . . . 4

1.1.3 Exercise: Stepwise construction of a given function . . . . . . . . . . . . . . . . . . . . 5

1.2 Combination of functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6

1.2.1 Exercise: Combinations of functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6

1.3 Composition of functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7

1.3.1 Exercise: Composite functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7

1.3.2 Exercise: Composite functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9

1.3.3 Exercise: Analytical expressions for given function graphs . . . . . . . . . . . . . . . . 9

1.4 Logarithmic plots . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11

2 Scalar functions in two variables 11

2.1 Visualization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11

2.1.1 Set of curves . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11

2.1.2 Contour graphics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11

2.1.3 3D-graphics / surface plot . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11

2.2 Elementary transformations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11

2.3 Linear coordinate transformations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11

2.3.1 Exercise: Stepwise transformation of a simple function . . . . . . . . . . . . . . . . . . 11

2.3.2 Exercise: Stepwise transformation of a simple function . . . . . . . . . . . . . . . . . . 12

2.3.3 Exercise: Simplify a function with stepwise transformations . . . . . . . . . . . . . . . 13

© 2017 Laurenz Wiskott (ORCID http://orcid.org/0000-0001-6237-740X, homepage https://www.ini.rub.de/PEOPLE/

wiskott/). This work (except for all figures from other sources, if present) is licensed under the Creative Commons Attribution-ShareAlike 4.0 International License, see http://creativecommons.org/licenses/by-sa/4.0/.These exercises complement my corresponding lecture notes, and there is a version with and one without solutions. The tableof contents of the lecture notes is reproduced here to give an orientation when the exercises can be reasonably solved. For bestlearning effect I recommend to first seriously try to solve the exercises yourself before looking into the solutions.More teaching material is available at https://www.ini.rub.de/PEOPLE/wiskott/Teaching/Material/.

1

Page 2: Functions - Ruhr University Bochum · parabula by 21 at the extrema of the cosine function. One can therefore rst draw the parabula x=20 and mark the zero crossings of the cosine

3 Vectorial functions in one variable 17

3.1 Visualization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17

3.1.1 Set of curves . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17

3.1.2 Sequence of a vector . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17

3.1.3 Trajectory in phase space . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17

3.1.4 Exercise: Trajectories in phase space . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17

3.1.5 Exercise: Trajectories in phase space . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18

3.1.6 Exercise: Analytical expressions for given trajectories . . . . . . . . . . . . . . . . . . 19

4 Vectorial functions in two variables 20

4.1 Visualization as a vector field . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20

4.1.1 Exercise: Vector field . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20

4.1.2 Exercise: Analytic expression for a given vector field . . . . . . . . . . . . . . . . . . . 21

4.1.3 Exercise: Analytic expression for a given vector field . . . . . . . . . . . . . . . . . . . 21

5 Differential operators 22

5.1 Partial derivatives and the Nabla operator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22

5.2 Gradient . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22

5.2.1 Exercise: Contour plot and gradient field . . . . . . . . . . . . . . . . . . . . . . . . . 22

5.2.2 Exercise: Gradient field . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23

5.3 Divergence . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23

1 Scalar functions in one variable

1.1 Elementary transformations

1.1.1 Exercise: Stepwise transformation of an elementary function

Construct the following functions step by step, for each intermediate step write down an equation and sketchthe graph.

(a) Begin with y = x3,

i) Shift the function 7 units to the left,

ii) Stretch the function vertically by a factor of 8,

iii) Flip the function at the y-axis.

Solution:

i) y = (x+ 7)3,

ii) y = 8(x+ 7)3,

iii) y = 8(−x+ 7)3,

2

Page 3: Functions - Ruhr University Bochum · parabula by 21 at the extrema of the cosine function. One can therefore rst draw the parabula x=20 and mark the zero crossings of the cosine

−1000

0

−10 −7 0 7

0

1000

−1000

0

−10 −7 0 7

0

1000

−1000

0

−10 −7 0 7

0

1000

−1000

0

−10 −7 0 7

0

1000

−1000

0

−10 −7 0 7

0

1000

−1000

0

−10 −7 0 7

0

1000

−1000

0

−10 −7 0 7

0

1000

0 10

© CC BY-SA 4.0

(b) Begin with y = cos(x),

i) Stretch the function horizontally by a factor of 2;

ii) Shift the function 3 units up;

iii) Flip the function at the x-axis.

Solution:

i) y = cos(x/2),

ii) y = cos(x/2) + 3,

iii) y = −(cos(x/2) + 3).

−4

−2

−1

0

1

2

4

−6π −5π −4π −3π −2π −π 0 π 2π 3π 4π 5π 6π

−4

−2

−1

1

2

4

−4

−2

−1

0

1

2

4

−6π −5π −4π −3π −2π −π 0 π 2π 3π 4π 5π 6π

−4

−2

−1

1

2

4

−4

−2

−1

0

1

2

4

−6π −5π −4π −3π −2π −π 0 π 2π 3π 4π 5π 6π

−4

−2

−1

1

2

4

−4

−2

−1

0

1

2

4

−6π −5π −4π −3π −2π −π 0 π 2π 3π 4π 5π 6π

−4

−2

−1

1

2

4

−4

−2

−1

0

1

2

4

−6π −5π −4π −3π −2π −π 0 π 2π 3π 4π 5π 6π

−4

−2

−1

1

2

4

−4

−2

−1

0

1

2

4

−6π −5π −4π −3π −2π −π 0 π 2π 3π 4π 5π 6π

−4

−2

−1

1

2

4

−4

−2

−1

0

1

2

4

−6π −5π −4π −3π −2π −π 0 π 2π 3π 4π 5π 6π

−4

−2

−1

1

2

4

−4

−2

−1

0

1

2

4

−6π −5π −4π −3π −2π −π 0 π 2π 3π 4π 5π 6π

−4

−2

−1

1

2

4

−4

−2

−1

0

1

2

4

−6π −5π −4π −3π −2π −π 0 π 2π 3π 4π 5π 6π

−4

−2

−1

1

2

4

−4

−2

−1

0

1

2

4

−6π −5π −4π −3π −2π −π 0 π 2π 3π 4π 5π 6π

−4

−2

−1

1

2

4

−4

−2

−1

0

1

2

4

−6π −5π −4π −3π −2π −π 0 π 2π 3π 4π 5π 6π

−4

−2

−1

1

2

4

−4

−2

−1

0

1

2

4

−6π −5π −4π −3π −2π −π 0 π 2π 3π 4π 5π 6π

−4

−2

−1

1

2

4

© CC BY-SA 4.0

(c) Begin with y = ex,

i) Flip the function at the x-axis,

ii) Shift the function 5 units to the right and 12 units down,

iii) Flip the function at the diagonal y = x.

Solution:

i) y = −ex,

3

Page 4: Functions - Ruhr University Bochum · parabula by 21 at the extrema of the cosine function. One can therefore rst draw the parabula x=20 and mark the zero crossings of the cosine

ii) y = −e(x−5) − 12,

iii) A flip at the diagonal corresponds formally to a swap of the variables. But then we have to solvethe new equation for x.

x = −e(y−5) − 12 (1)

⇐⇒ x+ 12 = −e(y−5) (2)

⇐⇒ −(x+ 12) = e(y−5) (3)

⇐⇒ ln(−(x+ 12)) = y − 5 (4)

⇐⇒ ln(−(x+ 12)) + 5 = y . (5)

−12

0

5

−12 5

−13

−11

5

−12

0

5

−12 5

−13

−11

5

−12

0

5

−12 5

−13

−11

5

−12

0

5

−12 5

−13

−11

5

−12

0

5

−12 5

−13

−11

5

−12

0

5

−12 5

−13

−11

5

−12

0

5

−12 5

−13

−11

5

−12

0

5

−12 5

−13

−11

5

−12

0

5

−12 5

−13

−11

5

−13 0

© CC BY-SA 4.0

1.1.2 Exercise: Stepwise construction of a given function

Construct and draw the following functions by stepwise transformation of the underlying elementary function.Illustrate each step.

(a) −3 sin(x+ π/4)

Solution: We start with sin(x).

A shift to the left by π/4 yields sin(x+ π/4).

A vertical stretch by a factor of 3 yields 3 sin(x+ π/4).

A reflection at the x-axis yields −3 sin(x+ π/4).

4

Page 5: Functions - Ruhr University Bochum · parabula by 21 at the extrema of the cosine function. One can therefore rst draw the parabula x=20 and mark the zero crossings of the cosine

−3

−1

0

1

3

−7π4

1π4

−3

−1

0

1

3

−7π4

1π4

−3

−1

0

1

3

−7π4

1π4

−3

−1

0

1

3

−7π4

1π4

−3

−1

0

1

3

−7π4

1π4

−3

−1

0

1

3

−7π4

1π4

−3

−1

0

1

3

−7π4

1π4

−3

−1

0

1

3

−7π4

1π4

−3

−1

0

1

3

−7π4

1π4

−3π4

5π4

© CC BY-SA 4.0

(b) 1/[(x− 2)3 − 1]

Solution: We start with x3.

A shift to the right by 2 yields (x− 2)3.

A shift down by 1 yields (x− 2)3 − 1.

Taking the reciprocal value corresponds to a nonlinear coordinate transformation by which the upperhalf is reflected at the horizontal line y = 1 and distorted such that the interval (0, 1) is mapped onto(1,∞) and vice versa. Something analogous holds for the lower half. This results in 1/[(x− 2)3 − 1].

−1

0

1

−1 2 3

0

−1

0

1

−1 2 3

0

−1

0

1

−1 2 3

0

−1

0

1

−1 2 3

0

−1

0

1

−1 2 3

0

−1

0

1

−1 2 3

0

−1

0

1

−1 2 3

0

−1

0

1

−1 2 3

0

−1

0

1

−1 2 3

0

1 3

© CC BY-SA 4.0

1.1.3 Exercise: Stepwise construction of a given function

Construct and draw the following functions by stepwise transformation of the underlying elementary function.Illustrate each step.

(a) e2(−x−3) + 7

Solution: We start with ex.

A flip at the ordinate yields e−x.

A horizontal compression by a factor of 1/2 yields e−2x.

A horizontal shift left by 3 yields e−2(x+3) = e2(−x−3).

A vertical shift up by 7 yields e2(−x−3) + 7.

5

Page 6: Functions - Ruhr University Bochum · parabula by 21 at the extrema of the cosine function. One can therefore rst draw the parabula x=20 and mark the zero crossings of the cosine

0

1

7

8

−3 0

0

7

0

1

7

8

−3 0

0

7

0

1

7

8

−3 0

0

7

0

1

7

8

−3 0

0

7

0

1

7

8

−3 0

0

7

0

1

7

8

−3 0

0

7

0

1

7

8

−3 0

0

7

0

1

7

8

−3 0

0

7

0

1

7

8

−3 0

0

7

−3 0

© CC BY-SA 4.0

(b) x3

x3+1

Solution: First we realize that the function vanishes for x = 0 and simplifies to x3

x3+1 = 11+1/x3

otherwise. We start with x3.

Taking the inverse yields 1/x3.

A vertical shift up by 1 yields 1 + 1/x3.

Taking the inverse again yields 11+1/x3 .

The main thing that is unclear is how the function behaves at x = 0. However, looking at the original

function x3

x3+1 , we see that the x3 in the denominator can be neglected for small x, so that the function

behaves like x3 around zero.

−1

0

1

−1 0

0

1

2

−1

0

1

−1 0

0

1

2

−1

0

1

−1 0

0

1

2

−1

0

1

−1 0

0

1

2

−1

0

1

−1 0

0

1

2

−1

0

1

−1 0

0

1

2

−1

0

1

−1 0

0

1

2

−1

0

1

−1 0

0

1

2

−1

0

1

−1 0

0

1

2

−1 1

© CC BY-SA 4.0

1.2 Combination of functions

1.2.1 Exercise: Combinations of functions

Discuss the following functions “intuitively”, like in the lecture, and sketch them.

(a) f(x) = cos (x) + x2

20 (sum of functions)

Solution: This function can be interpreted as a parbula with a superimposed oscillation. f(x) assumesexactly the value of the parabula at the zero crossings of the cosine function while it deviates from the

6

Page 7: Functions - Ruhr University Bochum · parabula by 21 at the extrema of the cosine function. One can therefore rst draw the parabula x=20 and mark the zero crossings of the cosine

parabula by ±1 at the extrema of the cosine function. One can therefore first draw the parabula x2/20and mark the zero crossings of the cosine function on it. Then one can draw two parabulas shift by ±1vertically and finally draw an oscillation between these two auxiliary parabulas through the markedzero crossings.

−1

0

1

−4π −3π −2π −π 0 π 2π 3π 4π

−1

0

1

−4π −3π −2π −π 0 π 2π 3π 4π

−1

0

1

−4π −3π −2π −π 0 π 2π 3π 4π

−1

0

1

−4π −3π −2π −π 0 π 2π 3π 4π

−1

0

1

−4π −3π −2π −π 0 π 2π 3π 4π

© CC BY-SA 4.0

(b) g(x) = x2 sin(x) (product of functions)

Solution: This function can be interpreted as a sine function that is modulated in its amplitude bya quadratic function. One has to take care though that one does not move the zero crossings closertogether at small amplitudes. One can therefore first draw the envelop functions ±x2, then mark thezero crossings of the sine function on the x-axis, and finally draw the oscillation between the envelopefunctions through the marked zero crossings.

0

−9π2

−5π2

−π2 0 3π

27π2

11π2

−11π2

−7π2

−3π2

π2

5π2

9π2

0

−9π2

−5π2

−π2 0 3π

27π2

11π2

−11π2

−7π2

−3π2

π2

5π2

9π2

0

−9π2

−5π2

−π2 0 3π

27π2

11π2

−11π2

−7π2

−3π2

π2

5π2

9π2

0

−9π2

−5π2

−π2 0 3π

27π2

11π2

−11π2

−7π2

−3π2

π2

5π2

9π2

© CC BY-SA 4.0

1.3 Composition of functions

1.3.1 Exercise: Composite functions

Discuss the following functions “intuitively”, like in the lecture, and sketch them.

(a) ln(x2)

Solution: Here it helps to see that ln(x2) = 2 ln(|x|). This implies that this function is actually simplythe logarithm vertically stretched by a factor of 2. In addition, negative arguments are permittedresulting in a flipped copy of the logarithm on the left side.

7

Page 8: Functions - Ruhr University Bochum · parabula by 21 at the extrema of the cosine function. One can therefore rst draw the parabula x=20 and mark the zero crossings of the cosine

0

−1 0 1

0

−1 0 1

0

−1 0 1

© CC BY-SA 4.0

(b) esin x

Solution: This function can be interpreted as a sine function that is transformed by an exponentialfunction such that (i) it is shifted up by one since e0 = 1 and (ii) distorted in a way that the curvebecomes steeper at larger values and shallower at smaller values. For instance, there are no negativevalues, whatever the argument of the exponential function might be.

0

1e

1

e

−5π2

−π2 0 3π

2

−3π2

π2

5π2

0

1e

1

e

−5π2

−π2 0 3π

2

0

1e

1

e

−5π2

−π2 0 3π

2

0

1e

1

e

−5π2

−π2 0 3π

2

−3π2

π2

5π2

0

1e

1

e

−5π2

−π2 0 3π

2

−3π2

π2

5π2

© CC BY-SA 4.0

(c) sin(1/x)

Solution: One possible way to interpret this function is to imagine a sine function with a nonlinearcoordinate transformation. If we consider only positive x, the transformation is a flip at x = 1 and acompression of the interval x ∈ (1,∞) onto the interval x ∈ (0, 1) and a stretch in the other direction.Thus, 5 swaps with 1/5, 100 with 1/100, etc. One therefore has to draw infinitely many oscillationstowards zero while there is no full oscillation at all between one and infinity. The function then looksas follows.

8

Page 9: Functions - Ruhr University Bochum · parabula by 21 at the extrema of the cosine function. One can therefore rst draw the parabula x=20 and mark the zero crossings of the cosine

−1

0

1

−2π−1π 0 2

−23π

−1

0

1

−2π−1π 0 2

−1

0

1

−2π−1π 0 2

−1

0

1

−2π−1π 0 2

−23π

© CC BY-SA 4.0

1.3.2 Exercise: Composite functions

Discuss the following functions “intuitively”, like in the lecture, and sketch them.

(a) e−(−x2+2)2

Solution: Not available!

(b) ln(x)2

Solution: Not available!

1.3.3 Exercise: Analytical expressions for given function graphs

Find a formula for each of the following sketched functions:

(a)

4

3 (b) (c)

2

3

(d) c (e)

1

c

(f)

1

−1

Hint: You can use AnalyticalExpressionsForGivenGraphs-Exercise.ipynb and add the missing code toverify your guesses.

Solution:

9

Page 10: Functions - Ruhr University Bochum · parabula by 21 at the extrema of the cosine function. One can therefore rst draw the parabula x=20 and mark the zero crossings of the cosine

(a) This is obviously a linear function that has the value 4 at x = 0 and a slope of −4/3, i.e.

f(x) = 4− 4/3x . (1)

(b) This is a parabula open to the top. Viewed from its minimum it reaches the value 1 only at ±2, i.e.the central term is x2/4. This function is shifted down by 1 and left by 2, i.e.

f(x) = −1 + (x+ 2)2/4 . (2)

(c) This is essentially the absolute value function but vertically compressed by 2/3 and shifted right by 3,i.e.

f(x) = 2/3|x− 3| . (3)

(d) This function goes to infinity at 0 and c. This can easily be achieved by adding 1/x und −1/x shiftedto the right by c, i.e.

f(x) = 1/x− 1/(x− c) . (4)

Alternatively one can multiply the two functions, resulting in a fraction with two poles,

f(x) =1

x(c− x). (5)

The two functions are slightly different but both produce a graph of the given form.

(e) This function could be based on 1/x. However, one has to switch the sign, shift the function up by c,and before all that stretch or compress it such that the function assumes the value 0 at 1, i.e.

f(x) = c− b/x , (6)

with b chosen such that f(1) = 0. It is easy to see that b = c.

(f) Such a function can be generated by inverting the tangent function and stretching it such that therange lies between −1 and +1, i.e.

f(x) = arctan(x)/(π/2) . (7)

Alternatively one can simply use the tanh,

f(x) = tanh(x) :=exp(x)− exp(−x)

exp(x) + exp(−x). (8)

See also AnalyticalExpressionsForGivenGraphs-Solution.ipynb.

10

Page 11: Functions - Ruhr University Bochum · parabula by 21 at the extrema of the cosine function. One can therefore rst draw the parabula x=20 and mark the zero crossings of the cosine

1.4 Logarithmic plots

2 Scalar functions in two variables

2.1 Visualization

2.1.1 Set of curves

2.1.2 Contour graphics

2.1.3 3D-graphics / surface plot

2.2 Elementary transformations

2.3 Linear coordinate transformations

2.3.1 Exercise: Stepwise transformation of a simple function

Transform the function z =√x2 + y2 step by step as follows:

1. Compress the function by a factor 1/2 in the x-direction and stretch it by a factor 3 in the y-direction.

2. Shift the function horizontally 3 units to the left in x-direction and 1 unit up in y-direction.

3. Shift the function vertically 2 units down in z-direction.

For each step write a corresponding equation and sketch the final result if you combine all three steps.

Solution:

1. z =√

(2x)2 + (y/3)2

2. z =√

(2(x+ 3))2 + ((y − 1)/3)2

3. z =√

(2(x+ 3))2 + ((y − 1)/3)2 − 2

−10

−5

0

5

10

−10 −5 0 5 10

© CC BY-SA 4.0

Notice that because we use absolute values (realized with a combination of square and square root) insteadof squared values, the equipotential lines are equidistant.

11

Page 12: Functions - Ruhr University Bochum · parabula by 21 at the extrema of the cosine function. One can therefore rst draw the parabula x=20 and mark the zero crossings of the cosine

2.3.2 Exercise: Stepwise transformation of a simple function

Transform the function

f(x) = xT(

2 00 1

)x, x =

(xy

)(1)

as follows:

1. Rotate the function clockwise by 30 degrees.

Hint: sin(π/6) = 1/2, cos(π/6) =√

3/2.

2. Shift the function horizontally by a = (1, 2)T .

Write a corresponding equation for each step and sketch the final result. Use matrix notation as far aspossible.

Solution:

1. A rotation matrix can be written as

R :=

(cos(φ) − sin(φ)sin(φ) cos(φ)

). (2)

It realizes a counterclockwise rotation by the angle φ.

In order to rotate the function clockwise by 30 degrees (π/6) the coordinates must be rotated counter-clockwise by 30 degrees. With sin(π/6) = 1/2 and cos(π/6) =

√3/2 we have

R30 =1

2

( √3 −1

1√

3

). (3)

Thus, the rotated function is

f(x) = xTRT30

(2 00 1

)R30x (4)

(3)=

1

4xT( √

3 1

−1√

3

)(2 00 1

)( √3 −1

1√

3

)x (5)

=1

4xT( √

3 1

−1√

3

)(2√

3 −2

1√

3

)x (6)

=1

4xT(

6 + 1 −√

3

−√

3 2 + 3

)x (7)

=1

4xT(

7 −√

3

−√

3 5

)x . (8)

2. In order to shift the function horizontally by a = (1, 2)T the coordinates must be shifted by −a, i.e.

f(x) = (x− a)T(

7/4 −√

3/4

−√

3/4 5/4

)︸ ︷︷ ︸

=:A

(x− a) (9)

=((x− a)TA(x− a)

). (10)

12

Page 13: Functions - Ruhr University Bochum · parabula by 21 at the extrema of the cosine function. One can therefore rst draw the parabula x=20 and mark the zero crossings of the cosine

If you like you can multiply this out and bring it into a different form, namely

f(x) =((x− a)TA(x− a)

)(11)

= xTAx− xTAa− aTAx + aTAa (12)

= xTAx−2aTA︸ ︷︷ ︸=:fT

x + aTAa︸ ︷︷ ︸=:c

(since A is symmetric) (13)

= c+ fTx + xTAx (14)

with c = aTAa (15)

= (1 2)

(7/4 −

√3/4

−√

3/4 5/4

)(12

)(16)

= (1 2)

((7− 2

√3)/4

(−√

3 + 10)/4

)(17)

= (7− 2√

3)/4 + 2(−√

3 + 10)/4 (18)

= 27/4−√

3 (19)

und f = −2Aa (20)

= −2

(7/4 −

√3/4

−√

3/4 5/4

)(12

)(21)

= −2

((7− 2

√3)/4

(10−√

3)/4

)(22)

=

((2√

3− 7)/2

(√

3− 10)/2

). (23)

The function then looks as follows.

−10

−5

0

5

10

−10 −5 0 5 10

© CC BY-SA 4.0

2.3.3 Exercise: Simplify a function with stepwise transformations

Consider the functionf0(x, y) := 1/2− x+ 5y + 3/2x2 + xy + 3/2y2 . (1)

13

Page 14: Functions - Ruhr University Bochum · parabula by 21 at the extrema of the cosine function. One can therefore rst draw the parabula x=20 and mark the zero crossings of the cosine

1. Write the function in matrix notation like

f0(x) = c+ fTx + xTHx , (2)

with a scalar c, vectors f and x = (x, y), and a symmetric 2× 2-matrix H.

Solution: Expanding (2) yields

f0(x) = c+ fTx + xTHx (3)

= c+ f1x+ f2y +H11x2 + (H12 +H21)xy +H22y

2 . (4)

By comparison of coefficients with (1) we find

c = 1/2 (5)

f =

(−1

5

)(6)

H =1

2

(3 11 3

). (7)

We have chosen H12 and H21 such that the matrix is symmetric. That is important further below.However, H12 = 1 and H21 = 0 and many other combinations would correctly reproduce the functionas well.

The function can then be written in matrix notation like

f0(x) = 1/2 +

(−1

5

)Tx +

1

2xT(

3 11 3

)x . (8)

2. Find a horizontal shift a and a vertical shift b such that

f1(x) := xTV x := b+ f0(x− a) (9)

for a symmetric matrix V .

Solution: We take the ansatz b+ f0(x− a) and chose b and a such that the constant and the linearterm vanish.

b+ f0(x− a)(2)= b+ c+ fT (x− a) + (x− a)TH(x− a) (10)

= b+ c+ fTx− fTa + xTHx− xTHa︸ ︷︷ ︸=aTHx

−aTHx + aTHa (11)

=(b+ c− fTa + aTHa

)+(fT − 2aTH

)x + xTHx . (12)

First we set the linear term to zero for all x and get

0!=(fT − 2aTH

)x ∀x (13)

⇐⇒ fT = 2aTH (14)(6,7)⇐⇒ −1 = 3a1 + a2 (15)

∧ 5 = a1 + 3a2 (16)

⇐⇒ a2 = −3a1 − 1 (17)

∧ 5 = a1 + 3(−3a1 − 1) (18)

= −3− 8a1 (19)

⇔ a1 = −1 (20)

⇐⇒ a2 = 2 (21)

∧ a1 = −1 . (22)

14

Page 15: Functions - Ruhr University Bochum · parabula by 21 at the extrema of the cosine function. One can therefore rst draw the parabula x=20 and mark the zero crossings of the cosine

Next we find the value of b by setting the constant term to zero,

0!= b+ c− fTa + aTHa (23)

(5,6,7,21,22)= b+ 1/2− (1 + 10) + (3/2− 1− 1 + 6) (24)

= b− 5 (25)

⇐⇒ b = 5 . (26)

If we now consider equation (12) again, we find that

V = H . (27)

This is generally true. One can always shift a quadratic function horizontally and vertically such thatfinally only the quadratic term remains, and the matrix H does not change.

3. Find a rotation

R :=

(cos(φ) − sin(φ)sin(φ) cos(φ)

)(28)

of the coordinates such that matrix V ′ of the function

f2(x) := xTV ′x := f1(Rx) (29)

becomes diagonal.

Solution: If we insert the rotation of the coordinates in f1, we get

f1(Rx) = xTRTV Rx , (30)

and we must chose the angle φ such that the new matrix V ′ becomes diagonal. To keep the equationtidy we set s := sin(φ) und c := cos(φ). We then find for V ′

V ′ = RTV R (31)

(28,27,28)=

(c s−s c

)(3/2 1/21/2 3/2

)(c −ss c

)(32)

=1

2

(c s−s c

)(3c+ s c− 3sc+ 3s 3c− s

)(33)

=1

2

(c(3c+ s) + s(c+ 3s) c(c− 3s) + s(3c− s)−s(3c+ s) + c(c+ 3s) −s(c− 3s) + c(3c− s)

)(34)

=1

2

(3c2 + sc+ sc+ 3s2 c2 − 3sc+ 3sc− s2−3sc− s2 + c2 + 3sc −sc+ 3s2 + 3c2 − sc

)(35)

=1

2

(3(c2 + s2) + 2sc c2 − s2

c2 − s2 3(c2 + s2)− 2sc

)(36)

=1

2

(3 + 2sc c2 − s2c2 − s2 3− 2sc

). (37)

This matrix becomes diagonal if (c2 − s2) = 0, which is obviously the case if c = ±s, which in turncorresponds to a rotation by π/4 plus an integer mutliple of π/2. One could have guessed that alreadyfrom the symmetry of V . Setting φ = π/4 results in

c = s = 1/√

2 (38)

15

Page 16: Functions - Ruhr University Bochum · parabula by 21 at the extrema of the cosine function. One can therefore rst draw the parabula x=20 and mark the zero crossings of the cosine

and

V ′(37,38)

=1

2

(3 + 1 0

0 3− 1

)(39)

=

(2 00 1

). (40)

Thus

f2(x)(29)= xTV ′x (41)

(40)= xT

(2 00 1

)x (42)

= 2x2 + y2 (43)

= (√

2x)2 + y2 . (44)

This function is really easy to understand. It is simply a parabula that is compressed in the x-directionby a factor of 1/

√2, see the figure.

−4

−2

0

2

4

−4 −2 0 2 4

y

x

© CC BY-SA 4.0

Please notice that matrix R describes a counterclockwise rotation but that the function is rotatedclockwise.

4. Sketch the function f0(x, y) without using a calculator.

Solution: It is easiest to start from function f2(x) of the last part and use the geometric transfor-mations we have used for simplifying the function in the opposite order. Thus, we first rotate f2(x)counterclockwise by π/4 = 45◦ and then move it horizontally by (1,−2)T and vertically by −5.

16

Page 17: Functions - Ruhr University Bochum · parabula by 21 at the extrema of the cosine function. One can therefore rst draw the parabula x=20 and mark the zero crossings of the cosine

−4

−2

0

2

4

−4 −2 0 2 4

y

x

© CC BY-SA 4.0

3 Vectorial functions in one variable

3.1 Visualization

3.1.1 Set of curves

3.1.2 Sequence of a vector

3.1.3 Trajectory in phase space

3.1.4 Exercise: Trajectories in phase space

Sketch the trajectories of the following functions without using a computer or pocket calculator.

(a) f(a) = (cos (a), sin (2a))

Solution: At first this may look like a simple circle, but the sine function of the y-component runstwice as fast as the cosine function of the x-component. But at least the trajectory is periodic in awith period 2π. First plot cos(a) and sin(2a) together in one graph.

−1

−0.5

0

0.5

1

0 1 2 3 4 5 6

a

cos(a)sin(2a)

© CC BY-SA 4.0

17

Page 18: Functions - Ruhr University Bochum · parabula by 21 at the extrema of the cosine function. One can therefore rst draw the parabula x=20 and mark the zero crossings of the cosine

If we go through a step by step we find that we pass the coordinates (1, 0), (1/√

2, 1), (0, 0), (−1/√

2,−1),etc. The trajectory then looks like this.

−1

−0.5

0

0.5

1

−1 −0.5 0 0.5 1

sin(2a)

cos(a)

© CC BY-SA 4.0

(b) f(t) = (sin2(6t) sin(t), sin2(6t) cos(t))

Solution: At first this trajectory looks complicated. However, we can factor out sin2(6t) and writef(t) = sin2(6t)(sin (t), cos (t)). This makes clear that we have a circular trajectory with an amplitudemodulated by sin2(6t). Because of the square the amplitude oscillates 12 times between 0 and 1. Thetrajectory starts at 0 · (0, 1) for t = 0 and then circles through clockwise with the twelve oscillations.

−1

−0.5

0

0.5

1

−1 −0.5 0 0.5 1

sin2(6t)

cos(t)

sin2(6t) sin(t)

© CC BY-SA 4.0

3.1.5 Exercise: Trajectories in phase space

Sketch the trajectories of the following functions without using a computer or pocket calculator.

(a) f(t) = ((1− 1/t) sin t, (1− 1/t) cos t)T , 1 ≤ tSolution: This trajectory can be written as a product of a circle (sin t, cos t) with increasing radius(1− 1/t). The circle starts for t = 1 at about 2 o’clock and runs clockwise; the radius starts at 0, firstgrows quickly, and then more and more slowly approaches 1. Taken together the trajectory describesa spiral.

18

Page 19: Functions - Ruhr University Bochum · parabula by 21 at the extrema of the cosine function. One can therefore rst draw the parabula x=20 and mark the zero crossings of the cosine

−1

−0.5

0

0.5

1

−1 −0.5 0 0.5 1

© CC BY-SA 4.0

(b) f(a) = (cos (2πa)2

+ a, cos (2πa))T

Solution: The basic element of this trajectory is (cos (2πa)2, cos (2πa)), an oscillation on a fixed

parabula of width 2 open to the right that goes through (1,1), (0,0), and (1,-1) for a = 0. Theoscillation frequency is 1 per time unit. With the additional term +a in the x-component the parabulamoves to the right at a rate of 1 per time unit.

−1

−0.5

0

0.5

1

0 0.5 1 1.5 2

© CC BY-SA 4.0

3.1.6 Exercise: Analytical expressions for given trajectories

Invent functions f(t) = (x(t), y(t)) that generate trajectory plots like those below.

(a) (b) (c)

© CC BY-SA 4.0

Hint: You can use AnalyticalExpressionsForGivenTrajectories-Exercise.ipynb and add the missingcode to verify your guesses.

Solution:

19

Page 20: Functions - Ruhr University Bochum · parabula by 21 at the extrema of the cosine function. One can therefore rst draw the parabula x=20 and mark the zero crossings of the cosine

(a) The symmetry of the trajectory indicates that x(t) is an even function and y(t) is an odd function ifone uses a symmetric interval for t. It is also clear that y(t) grows slightly faster than x(t) for large |t|.The x-component comes from +∞, moves towards zero, and returns to +∞, being slower near zero.This can be achieved by x(t) = t2. The y-component comes from −∞, shoots over zero into positivevalues, returns to negative values, and then moves to +∞. This can be achieved by something likey(t) = −t+ t3, thus

f(t) = (t2,−t+ t3) . (1)

This produces the given trajectory for t ∈ [−2,+2].

(b) The basic spiral can be generated as a clockwise circle with linearly increasing radius, such as f(t) =(t sin(t), t cos(t)). The oscillation around this spiral has constant amplitude and constant spatial fre-quency. The former can be easily achieved by adding a constant oscillation to the scaling factor t, e.g.f(t) = ((t+ sin(10t)) sin(t), (t+ sin(10t)) cos(t)). However, this oscillation does not have constant spa-tial frequency, because it has a constant number (in this case 10) of oscillations per revolution. Sincethe radius increases linearly in time, the temporal frequency of the oscillation also needs to increaselinearly in time, in order to get a constant spatial frequency, thus we need to replace 10 by t and get

f(t) = ((t+ sin(t2)) sin(t), (t+ sin(t2)) cos(t)) . (2)

This produces the given trajectory for t ∈ [0, 20].

(c) An eight-shape can be produced by two oscillating functions x(t) and y(t), where the y-oscillation istwice as fast as the x-oscillation, e.g. f(t) = (sin(t), sin(2t)). Scaling can be achieved by multiplyingthis with t, and shifting upwards can be achieved by adding t to the y-component, resulting in

f(t) = (t sin(t), t+ t sin(2t)) (3)

= t(sin(t), 1 + sin(2t)) . (4)

This produces the given trajectory for t ∈ [0, 50].

See also AnalyticalExpressionsForGivenTrajectories-Solution.ipynb.

4 Vectorial functions in two variables

4.1 Visualization as a vector field

4.1.1 Exercise: Vector field

Draw the vector field (y,−x) .

Solution:

−10

−5

0

5

10

−10 −5 0 5 10

© CC BY-SA 4.0

20

Page 21: Functions - Ruhr University Bochum · parabula by 21 at the extrema of the cosine function. One can therefore rst draw the parabula x=20 and mark the zero crossings of the cosine

4.1.2 Exercise: Analytic expression for a given vector field

Find an analytic expression for the following vector field.

−10

−5

0

5

10

−10 −5 0 5 10

© CC BY-SA 4.0

Solution: Let us assume it is a simple polynomial function. The vector field vanishes in the origin, thusthere is no constant term. The x-component of the function is zero along the x-axis, i.e. for y = 0, thusthe x-component probably contains a factor y. Similarly the y-component probably has a factor x. Thatis already enough information, because if we try the vector field (y, x) we find that it generates the correctflow field.

4.1.3 Exercise: Analytic expression for a given vector field

Find an analytic expression for the following vector field.

−1

−0.5

0

0.5

1

−2 −1.5 −1 −0.5 0 0.5 1 1.5 2

y

x

© CC BY-SA 4.0

Solution: First we observe that the vector field does not depend on y and at least to a first approximationthe x-component seems to be a constant overall. Next we see that the vector field is periodic in x with aperiodicity of 2, so that terms like sin(πx) or cos(πx) might be involved. For x = 0 the y-component has itsmaximum and is equal to the x-component. This hints at cos(πx) rather than sin(πx). If we try (1, cos(πx))we find that that generates the correct field.

21

Page 22: Functions - Ruhr University Bochum · parabula by 21 at the extrema of the cosine function. One can therefore rst draw the parabula x=20 and mark the zero crossings of the cosine

5 Differential operators

5.1 Partial derivatives and the Nabla operator

5.2 Gradient

5.2.1 Exercise: Contour plot and gradient field

Consider the functionX(u, v) = u2(u− 1)2 + v2 . (1)

1. Calculate the gradient field of the function.

Solution:

∇X(u, v) =

(∂X(u,v)∂u

∂X(u,v)∂v

)(2)

(1)=

(2u(u− 1)2 + u22(u− 1)

2v

)(3)

=

(2u[(u− 1) + u](u− 1)

2v

)(4)

=

(4u(u− 1/2)(u− 1)

2v

). (5)

2. Sketch the function with a contour plot and draw the gradient field, both without the help of acalculator.

Solution: To sketch the function and its gradient field it is useful to consider the profiles of u2(u−1)2

and 4u(u− 1/2)(u− 1). It is clear that v2 is simply a parabula.

u2 and (u − 1)2 are parabulas centered at 0 and 1. The product is therefore a function with twovalleys at 0 and 1. In the direct vicinity of u = 0 one can assume that (u − 1)2 = 1 and thereforeat (u, v) = (0, 0) the function X(u, v) simplifies to u2 + v2, which is a rotation symmetric parabula.Something similar hold at (u, v) = (1, 0).

4u(u − 1/2)(u − 1) is obviously zero at 0, 1/2, and 1. For negative values of u all three factors arenegative and the function value is therefore negative as well. Above 0 the function values becomepositive, because u changes sign. Above 1/2 the function values become negative again, because(u − 1/2) changes sign. Above 1 they are positive again. This information helps in sketching thegradient field, see figure.

−0.4

−0.2

0

0.2

0.4

−0.5 0 0.5 1 1.5

v

u

© CC BY-SA 4.0

22

Page 23: Functions - Ruhr University Bochum · parabula by 21 at the extrema of the cosine function. One can therefore rst draw the parabula x=20 and mark the zero crossings of the cosine

5.2.2 Exercise: Gradient field

Calculate the gradient of the function f(x, y) = xy − 12y

2. Sketch the gradient field and the level lines.

Solution: Not available!

5.3 Divergence

23