1. Exercise - TU Chemnitz

Technische Universität Chemnitz
Chemnitz, 13th October 2014
Prof. Dr. R. Herzog, Andreas Günnel, Stephan Schleicher, Dmyto Shklyarov
Optimization for Non-Mathematicians
Sheet 1
Exercise 1: Introduction to Matlab – basics
Start Matlab type the following commands. Look carefully at the output and check
the meaning of , and ;.
Hint: with the cursor keys ↑
↓ you can repeat and change the previous input
lines.
23+19
3*4
3*4,
3*4;
a=3*4;
a
a;
sqrt(2)
help sqrt
pi
help pi
radius=2, durchmesser=2*radius, umfang=durchmesser*pi
radius=2, durchmesser=2*radius; umfang=durchmesser*pi
radius=2, durchmesser=2*radius umfang=durchmesser*pi
With the command
pwd
(pwd means "print working directory") you can display your current working directory.
It is advisable to create an own folder for every exercise. This can be done by the
following two commands.
mkdir Uebung01
cd Uebung01
pwd
Sums are also easy to compute.
x=[-2, 2, 3, 1, 0, 4]
sum(x)
x+2
sum(x+2)
1
For help type on of the following functions
help sqrt
doc surf
lookfor root
Calculate sin π6 ,
sin(pi/6)
help sqrt
42^(1/3)
exp(pi)
√
3
1
42 (i.e. 42 3 ) and eπ with
Exercise 2: Introduction to Matlab – functions and plots
Use the template my2Dplot.m to plot the following functions and check if there exist
minima, maxima or saddle points.
(a) Plot the quadratic function (quadFct.m)
1
f (x) = x> Bx + g > x + c
2
with
2 0
B=
,
0 1
g=
−4
,
−2
c = 6.
for x = (x1 , x2 ) ∈ [−8, 12] × [−8, 12]. Try also other matrices:
2 0
−2 0
,
, B3 =
B2 =
0 −1
0 −1
and calculate there eigenvalues with:
eig(B)
(b) Plot the Rosenbrock function
f (x1 , x2 ) = (1 − x1 )2 + 100(x2 − x21 )2
for (x1 , x2 ) ∈ [−3, 3] × [−3, 3].
(c) Plot the periodic function
f (x1 , x2 ) = sin(x1 ) cos(x2 )
for (x1 , x2 ) ∈ [−2π, 2π] × [−2π, 2π].
2