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
23
Embed
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
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
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/.
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].
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
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.
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.
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.
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.
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.
(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
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.
Notice that because we use absolute values (realized with a combination of square and square root) insteadof squared values, the equipotential lines are equidistant.
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
If you like you can multiply this out and bring it into a different form, namely
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
Next we find the value of b by setting the constant term to zero,
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 ′
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
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/
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.
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.
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.
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.
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.
(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
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.
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.
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.
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.