1
$\begingroup$

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}],
 Method -> {"NelderMead", "Tolerance" -> Sqrt[$MachineEpsilon]},
 WorkingPrecision -> 15,
 AccuracyGoal -> 9,
 MaxIterations -> 10000
 ];
  Return [sol]
  ];

Sorry for the formatting, I was not able to format it correctly here...

If I now call hanningParam[10,3,-0.4] the output is (Let us assume tg=10,nm=3,\[CapitalDelta}=-0.4,B=20):

{2.99134738620154, {Subscript[a, 1] -> -9.99201*10^-15,Subscript[a, 2] -> 0, Subscript[a, 3] -> 0.314159265358989}}

where $a_1$ is definitely not positive (even if it is only "slightly" negative). How can that be? My impression is that I messed up with Tolerance,Accuracy and WorkingPrecision. Or is there another mistake?

Questions in summary

  1. Is it possible (if so, how?) to simultaneously minimize two functions, in my case spp and spm where both in the end have the same set of parameters $a_n$?
  2. Where did I make a mistake with NMinimize so that the constraints are (slightly) violated?
  3. Is there anything else that is wrong or might cause problems at some point?

Thanks in advance for your effort!

$\endgroup$
  • $\begingroup$ Hi, welcome to Mathematica.SE, please consider taking the tour so you learn the basics of the site. Once you gain enough reputation by making good questions you will be able to vote up and down both questions and answers. When you see good ones, please vote them up by clicking the gray triangles, because the credibility of the system is based on the reputation gained by users sharing their knowledge. As you receive help, try to give it too, by answering questions in your area of expertise. $\endgroup$ – rhermans Oct 22 '14 at 7:59
  • $\begingroup$ Not clear what you're trying to do. If nm=10 you have 10 unknowns and only 3 conditions. Suppose you can solve the system, how do you determine the remaining 7 unknowns ? $\endgroup$ – b.gates.you.know.what Oct 22 '14 at 10:27
  • $\begingroup$ That is indeed a good point I was also thinking about. If it was solvable the result for e.g. $a_1$ would depend on $a_2$ etc depending on $n_m$ as you stated. Consequently I could then use further methods to find optimal values afterwards. Nevertheless it should be possible to look for a configuration of my $a_n$ that minimizes the given functions in a specific region, right? So let's maybe only focus on the minimizing problem instead of the "exact" solving (which indeed is not always possible). $\endgroup$ – Lukas Oct 22 '14 at 11:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.