# Exercise 2
* Due: 20.1. at 14:00
* Max points: 8

## General rules
* **Submit your answers by using Moodle.** The link is <a href="https://moodle.jyu.fi/mod/assign/view.php?id=673612&forceview=1">https://moodle.jyu.fi/mod/assign/view.php?id=673612&forceview=1</a>.
* Name your file as *lastname_ex2.xxx*. If you have multiple files, use *lastname_ex2_1.xxx, lastname_ex2_2.xxx* etc.
* **Remember to add comments to your answers and include also some testing part!**
* You will get feedback about your answers about a week from the due date
* The exercises will be given on the previous Wednesday's lecture

## Exercises

1. **(2 points)** Assume that you are buying and selling electricity. The more electricity you buy, the better price you get **per kwH** and the **buying prize** of electricity follows function $f(x) = 1-0.01x$, where $0\leq x\leq50$ is the amount of electricity you buy. On the other hand, the **price** that you get from selling electricity **follows** function $g(x) = 2-0.01x^2$ with $x$ again the amount of electricity that you sell. Formulate an optimization problem that maximizes the profit.
2. **(2 points)** Use bisection search to optimize problem
$$
\begin{align}
\min & (1-x)^2+x\\
\text{s.t. }&x\in [0,2].
\end{align}
$$
Code the search algorithm by yourself, not use the one shown in the lecture material.
3. **(2 points)** Use golden section search to optimize the problem from above exercise. Code the search algorithm by yourself, not use the one shown in the lecture material.
4. **(2 points)** Use differentiation/derivation to optimize the optimization problem of task 1 (above) and to verify the answer of optimization problem in task 2 (above).

