Community Tip - Need to share some code when posting a question or reply? Make sure to use the "Insert code sample" menu option. Learn more! X
Hello experts,
I hope the question is in the right category. I haven't been able to find an answer in the community yet.
A function should be passed as an element in a program [e.g. p(f):=II…]. This function can have a different number of its own elements [e.g. f(x1, x2, …)]. How can I pass the function to the program and how can I find out within the program how many elements the function has?
Thanks for your help.
SW: PTC Mathcad Prime 7.0.0.0
Solved! Go to Solution.
In Prime you cannot create a function with a variable number of parameters. However, you can create a function that accepts a vector, or a matrix, as parameter. Within the function you can determine the size of the vector or the matrix.
Below some illustrations of what you can do in Prime:
Note that when you pass a function (name) as a parameter, you cannot inspect the parameters of that function.
You can pass a complete function call as a parameter to a function, e.g.
The inner fun(1) results in a string that is passed as the argument to the outer fun, resulting in the response that it's got a string.
Success!
Luc
In Prime you cannot create a function with a variable number of parameters. However, you can create a function that accepts a vector, or a matrix, as parameter. Within the function you can determine the size of the vector or the matrix.
Below some illustrations of what you can do in Prime:
Note that when you pass a function (name) as a parameter, you cannot inspect the parameters of that function.
You can pass a complete function call as a parameter to a function, e.g.
The inner fun(1) results in a string that is passed as the argument to the outer fun, resulting in the response that it's got a string.
Success!
Luc
May by so
Thanks for your answers.
I was worried that there was no real solution for this.
Maybe it will be possible in the next update.
The number of elements in a function is fixed as the definition of the function. When you change the number of elements, a new function is defined.
As Luc shows, you can use vectors or matrices on elements to change the number of elements and get the result you want.