Skip to main content
5-Regular Member
March 18, 2015
Question

Optional Parameters in custom functions

  • March 18, 2015
  • 2 replies
  • 1724 views

Is there a shortcut way of making optional parameters in a function in either M15 or Prime 3.0? I haven't come across anything regarding this issue yet.

I ask as this would be a great way to implement the same function with some options. We could use [] to define the optional parameter with the number inside defining the default value.

2 replies

19-Tanzanite
March 18, 2015

If you mean a user defined function that could be called with a variable number of parameters, that's not possible. It's another long standing request.

3-Newcomer
May 1, 2024

Sorry to resurrect an old post, but this is the first result on Google for the query "mathcad optional parameters" and I am hoping it will be helpful to someone.

 

One solution would be to pass an array/matrix as the only parameter to the function, then within the function use the try/on error statement to check if your optional parameter is defined or if you need to give it a default value.  This could get very verbose very quickly if you have a lot of optional parameters, but should work in Mathcad 15 as well as Mathcad Prime Alpha3 or newer.


OptionalParameters15.jpg

OptionalParametersPrime.jpg