cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - You can change your system assigned username to something more personal in your community settings. X

Question about passing a function to a program

KS_10826266
4-Participant

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

 

1 ACCEPTED SOLUTION

Accepted Solutions
LucMeekes
23-Emerald III
(To:KS_10826266)

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

View solution in original post

4 REPLIES 4
LucMeekes
23-Emerald III
(To:KS_10826266)

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

May by so

x.png

Thanks for your answers.

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

Maybe it will be possible in the next update.

ttokoro
20-Turquoise
(To:KS_10826266)

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

Top Tags