Defining a piecewise function in Mathematica

Click For Summary
SUMMARY

The discussion centers on defining a piecewise function in Mathematica for 2D Shannon interpolation. The user created a custom sinc function, named sincC, to avoid compatibility issues with optimization software. The error encountered was due to incorrect formatting of the Piecewise function, specifically the need for an additional pair of braces to enclose all pieces. The solution was to correctly format the Piecewise function to resolve the error.

PREREQUISITES
  • Understanding of Piecewise functions in Mathematica
  • Familiarity with 2D Shannon interpolation techniques
  • Basic knowledge of custom function definitions in Mathematica
  • Experience with error handling in Mathematica code
NEXT STEPS
  • Learn about advanced Piecewise function usage in Mathematica
  • Explore 2D interpolation methods in Mathematica
  • Investigate optimization software compatibility with Mathematica functions
  • Study error debugging techniques in Mathematica programming
USEFUL FOR

Mathematica users, data scientists, and researchers involved in numerical methods and interpolation techniques who require precise function definitions for optimization tasks.

confused_engineer
Messages
34
Reaction score
1
TL;DR
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
    16.3 KB · Views: 439
Physics news on Phys.org
You need an extra pair of {...} to enclose all of the pieces of your piecewise function
 
  • Like
Likes   Reactions: confused_engineer
Dale said:
You need an extra pair of {...} to enclose all of the pieces of your piecewise function

Thank you very much. That was it.
 
  • Like
Likes   Reactions: Dale

Similar threads

  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 13 ·
Replies
13
Views
3K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 4 ·
Replies
4
Views
5K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 19 ·
Replies
19
Views
3K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 1 ·
Replies
1
Views
4K
  • · Replies 1 ·
Replies
1
Views
5K