Skip to main content
4-Participant
October 19, 2023
Solved

Question about passing a function to a program

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

 

LucMeekesAnswer
23-Emerald IV
October 19, 2023

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:

LucMeekes_0-1697736163041.png

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.

LucMeekes_1-1697736398567.png

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

4 replies

LucMeekes23-Emerald IVAnswer
23-Emerald IV
October 19, 2023

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:

LucMeekes_0-1697736163041.png

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.

LucMeekes_1-1697736398567.png

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

Translate
24-Ruby IV
October 19, 2023

May by so

x.png

Translate
4-Participant
October 20, 2023

Thanks for your answers.

I was worried that there was no real solution for this.

Maybe it will be possible in the next update.

Translate
ttokoro
21-Topaz I
October 20, 2023

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.

image.pngimage.png

As Luc shows, you can use vectors or matrices on elements to change the number of elements and get the result you want.

image.pngimage.pngimage.pngimage.png

Translate
t.t.