Message Boards Message Boards

Issues with ContourPlot and Sinc functions?

Posted 5 years ago

Hello everyone.

I have constructed a function using Shannon interpolation as:

sinc = Sinc[Pi #] & ;
shannonIP[v_, w_] = 
      Total[#3* sinc[(v - #1)/dDelta]*sinc[(w - #2)/dDelta] & @@@ 
        interpolatedData];

Now, I have been told to send this code to a coworker who does optimization in Pyomo. The problem is that said software doesn't understand the function Sinc. I have to construct it using at most Sin[x]. I have done some attempts:

sincB = (Sin[Pi #]/(Pi (# + 10^-90))) & ;
sincC = Piecewise[{{(Sin[Pi #]/(Pi #)), # > 
       0.00000000001}, {1 - (#^2)/6 + (#^4)/120 - (#^6)/5040, # <= 
       0.00000000001}}] & ;
sincD = 1 - ((Pi #^2)/6) + ((Pi #^4)/120) - ((Pi #^6)/
      5040) + ((Pi #^8)/362280) - ((Pi #^10)/39916800) + ((Pi #^12)/
      6227020800) - ((Pi #^14)/1307674368000) + ((Pi #^16)/
      355687428096000) & ;
sincE = Piecewise[{{(Sin[Pi #]/(Pi #)), # != 0}, {1, # = 
       0.0000000000}}] & ;

None of these provide acceptable results; the piecewise ones also have weird white lines when plotting the resulting functions and the resulting expressions aren't something that one can send to Pyomo. I will attach my code in case it is useful.

Can someone please give me advice on what to do?

Thank you very much.

Regards.

Jaime.

Attachments:
POSTED BY: Jaime de la Mota
2 Replies

Allright Neil.

I will check your code immediately.

Regards. Jaime.

POSTED BY: Jaime de la Mota

Jaime,

The problem is in the ContourPlot and not in your Sinc function. I would report this as a bug to Support.

This works fine:

jnk = Flatten[
   Table[{t, u, shannonIPB[t, u]}, {t, 1, 10, .1}, {u, 1, 10, .1}], 
   1];
ListContourPlot[jnk, GridLines -> {{1, 10}, None}, 
 PlotLegends -> Automatic]

using any of your Sinc definitions. In fact even this works:

sincI[x_] := If[x == 0, 1, Sin[Pi *x]/(Pi * x)]
shannonIPI[v_, w_] = 
  Total[#3* sincI[(v - #1)/dDelta]*sincI[(w - #2)/dDelta] & @@@ 
    interpolatedData];
jnk = Flatten[
   Table[{t, u, shannonIPI[t, u]}, {t, 1, 10, .1}, {u, 1, 10, .1}], 1];
ListContourPlot[jnk, GridLines -> {{1, 10}, None}, 
 PlotLegends -> Automatic]

I don't think you ever get close to zero in the 10th decimal place -- it either a big number or exactly zero.

I am not sure why the piecewise throws off the ContourPlot Algorithm.

Regards,

Neil

POSTED BY: Neil Singer
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract