Defining a piecewise function in Mathematica

  • #1
TL;DR Summary
I can't define a piecewise function which reads data from a table as #
Hello everyone.

I am trying to do a 2D Shannon interpolation, but I cannot use a sinc because later on this expression goes in an optimization software that doesn't recognize it. I have defined my own version of sinc as:

sincC = Piecewise[{(Sin[Pi* #]/(Pi*(#))), # >= 1}, {1 - (#^2)/6 + (#^4)/120 - (#^6)/5040, # < 1}] & ;

The problem comes when I use the aforementioned sincC to construct the Shannon interpolation function.

shannonIPC[v_, w_] = Total[#3* sincC[(v - #1)/dDelta]*sincC[(w - #2)/dDelta] & @@@interpolatedData]

interpolatedData is a matrix of three columns and dDelta is a constant equal to 10. The error can be seen in the attached image, but it reads as
Piecewise:The first argument {(0.95493 Sin[1.0472 (-1.+v)])/(-1.+v),0.333333 (-1.+v)>=1} of Piecewise is not a list of pairs. and I am clueless about what to do.

Any advice is welcome.
Thanks for reading.
Regards.
 

Attachments

  • physics_forum.png
    physics_forum.png
    20 KB · Views: 305

Answers and Replies

  • #2
You need an extra pair of {...} to enclose all of the pieces of your piecewise function
 
  • Like
Likes confused_engineer
  • #3
You need an extra pair of {...} to enclose all of the pieces of your piecewise function

Thank you very much. That was it.
 

Suggested for: Defining a piecewise function in Mathematica

Replies
1
Views
480
Replies
1
Views
158
Replies
4
Views
552
Replies
4
Views
1K
Replies
2
Views
580
Replies
7
Views
726
Replies
3
Views
1K
Mathematica Piecewise Function
Replies
1
Views
1K
Back
Top