jeudi 31 octobre 2019

Writing sum of sinc functions in ampl

I have to implement a Mathematica output as a variable in ampl which is a sum and product of sinc functions. I have defined a sinc function as

var SincA {i in N}=   if abs(x1[i]) > 1e-8 then sin(x1[i])/x1[i] else 1;
var SincB {i in N}=   if abs(x2[i]) > 1e-8 then sin(x2[i])/x2[i] else 1;

However, the Mathematica output takes the shape

    -19.99590492248535*Sinc[0.12566370614359174*(0. + t)]*
  Sinc[0.26927937030769655*(-65. + u)] - 
 4.360287189483643*Sinc[0.12566370614359174*(25. + t)]*
     Sinc[0.26927937030769655*(-65. + u)] + 
 12.314101219177246*Sinc[0.12566370614359174*(50. + t)]*
  Sinc[0.26927937030769655*(-65. + u)] 

and this is just a small part of the total output.

I can reproduce this in ampl as

var Sinc1x1A{i in N}= if abs(0.12566370614359174*(0. + x1[i])) > 1e-8 then sin(0.12566370614359174*(0. + x1[i]))/(0.12566370614359174*(0. + x1[i])) else 1;

var Sinc1x1B{i in N} = if abs(0.26927937030769655*(-65. + x2[i])) > 1e-8 then sin(0.26927937030769655*(-65. + x2[i]))/(0.26927937030769655*(-65. + x2[i])) else 1

var Resultx1{i in N} = -19.99590492248535*Sinc1x1A[i]*Sinc1x1B[i]-...;

However, this method is extremely inefficient since I have to define too many variables.

I want to construct a sinc function without a defined argument and then call it as many times as needed instead of having to define tens of variables.

I have found these slides, https://ampl.com/MEETINGS/TALKS/2018_07_Valencia_WA-57.pdf, but I cannot find any way to do what I want.

Can someone point me to some documentation where this is solved?

Aucun commentaire:

Enregistrer un commentaire