# NMinimize: Problem with constraints + Simultaneous minimization possible?

## Introduction

Dear all,

I am fairly new to Mathematica. Recently I am trying to do the following: I have a function $$\textrm{hann}[t,t_g,n_m]=\sum\limits_{n=1}^{n_m}a_n\left[1-\cos\left(\frac{2\pi n t}{t_g}\right)\right]$$ that yields the general form of a superposition of so-called Hanning windows - $t_g$ here is just an internal upper bound for the time ($t\in [0,t_g]$). The goal is now to find values for the coefficients $a_n$.

Of course, there are some constraints that need to be taken into account:

1. $\int\limits_0^{t_g}\left(\mathrm{hann}[t,t_g,n_m]-\frac{i}{\Delta}\frac{\partial}{\partial t}\mathrm{hann}[t,t_g,n_m]\right)e^{\pm i \Delta t}\mathrm{d}t=0$
2. $\int\limits_0^{t_g}\left(\mathrm{hann}[t,t_g,n_m]-\frac{i}{\Delta}\frac{\partial}{\partial t}\mathrm{hann}[t,t_g,n_m]\right)\mathrm{d}t=\pi$
3. $a_n\in \mathbb{R}\quad\&\quad a_n\in(0,B]$ where $B$ is an upper limit that needs to be changable. But $B$ will be constant during evaluation!

Looking at the function $\mathrm{hann}$ reveils that the integral over its partial derivative will vanish, but in order to be as generic as possible I did not want to remove that part from the code.

## Problem

My problem now is that I am unable to use NSolve for solving that system - maybe it is even impossible to do so. The idea then was to do the following: Constraint number 1 actually says that the power spectral density needs to be zero for the specific parameters. But if it cannot be exactly zero it must at least be as small as possible. To do that, I want to make use of NMinimize.

As I was unable to find a hint if it is possible to simultaneously minimize two functions for the same parameters - i.e. the integrands in condition 1 (please notice the $\pm$ in the exponential) - I thought of minimizing the sum of their absolut values. Please have a look at my implementation in Mathematica:

hann[t_, tg_, nm_] :=
Sum[Subscript[a, n]*(1 - Cos[(2*\[Pi]*n*t)/tg]), {n, 0, nm}];

hanningParam[gateTime_, maxOrder_,delta_] :=
Module[{tg = gateTime, num = maxOrder, \[CapitalDelta] = delta, fx,fy, spp, spm, sol},

fx[t_, tg_, num_] = hann[t, tg, num];
fy[t_] = ((-1)/\[CapitalDelta])*D[fx[t, tg, num], t];

spp[t_, tg_, nm_] :=Integrate[(fx[t, tg, nm] + I*fy[t])*Exp[-I*\[CapitalDelta]*t], {t,0, tg}];
spm[t_, tg_, nm_] :=Integrate[(fx[t, tg, nm] + I*fy[t])*Exp[I*\[CapitalDelta]*t], {t,0, tg}];
sol = NMinimize[
{

Abs[spp[t, tg, num]] + Abs[spm[t, tg, num]]
, Integrate[fx[t, tg, num] + I*fy[t], {t, 0, tg}] == \[Pi] &&Table[Subscript[a, n], {n, 1, num}]\[Element] Reals&&
0 < Table[Subscript[a, n], {n, 1, num}] < 20
},
Table[Subscript[a, n], {n, 1, num}],