# constraint optimization using penalty function

Let say you have following constraint optimization problem and you want to optimize it using penalty function method:

$$\min f(\mathbf{x}), \mathbf{x} \in R^{2} \\ s.t. \mathbf{a(x) = 0}, \\ \mathbf{b(x) \ge 0}$$

which is (all parameters $$x$$ are vectors): $$\Phi(x) = f(x) + \frac{1}{2}\mu \left(\sum_{k=1}^{n_a}a(x)^2+ \sum_{k=1}^{n_b}\hat{b}(x)^2\right) \\ \hat{b} = min(0, b(x))$$

Where $$\mu$$ is the penalty constant which we will increase at every iteration.

Let say $$n_a=1, n_b=1$$.

So we have: $$\Phi(x) = f(x) + \frac{1}{2}\mu \left(a(x)^2+ \hat{b}(x)^2\right) \tag{1}$$

$$\hat{b} = min(0, b(x)) \tag{2}$$

$$\nabla \Phi(x) = \nabla f(x) + \mu (a(x)\nabla a(x) + \hat{b}(x)\nabla \hat{b}(x)) \tag{3}$$

$$H_{\Phi}(x) = H_{f}(x) + \mu((\nabla a(x) \nabla a(x)^T + H_{a}(x)a(x)) + (\nabla \hat{b}(x) \nabla \hat{b}(x)^T + H_{\hat{b}}(x)\hat{b}(x))) \tag{4}$$
where $$H$$ is the hessian matrix and also: $$\nabla \hat{b}(x) = \begin{cases} \nabla b(x), & \text{if b(x) \ge 0} \\ \mathbf{0}, & \text{if b(x) < 0} \end{cases} \tag{5}$$

$$H_\hat{b}(x) = \begin{cases} H_{b}(x), & \text{if b(x) \ge 0} \\ \mathbf{0}, & \text{if b(x) < 0} \end{cases} \tag{6}$$

1) I would like to know, if i did the above math (specially eq3, eq4, eq5, eq6) correctly or is there any mistake?

Particularly i would like to if you can really take the derivatives of the $$min$$-function like this?