Defining a piecewise function in Mathematica

  • #1
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
    24 KB · Views: 143

Answers and Replies

  • #2
Dale
Mentor
Insights Author
2020 Award
31,299
8,069
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.
 

Related Threads on Defining a piecewise function in Mathematica

Replies
1
Views
9K
Replies
1
Views
2K
Replies
3
Views
2K
Replies
2
Views
6K
Replies
1
Views
7K
Replies
4
Views
5K
Replies
4
Views
661
Top