Community Tip - Did you get an answer that solved your problem? Please mark it as an Accepted Solution so others with the same problem can find the answer easily. X

Translate the entire conversation x

Missing argument of a function

EP_10906526
8-Gravel

Missing argument of a function

Hello

i have an equation. lets say

EP_10906526_1-1743017155364.png

but if i have less arguments i want to do a different operation, lets say:

EP_10906526_3-1743017398382.png

EP_10906526_4-1743017404907.png

(of course defining the expression like this will say that it was already previously defined)

I dont want to create a new equation with different name. 

 

 

how can I modify my original equation to understand that the missing argument is null 

 

the closest i have reached is using an IF operator and checking if the other arguments are 0

something like

if z = 0 and y = 0

     return x

if z = 0

     return x * y

else 

    return x * y * z

 

then I need to wrinte something like this --> F(5, 5, 0)


if the ecuation is more complex i dont want to write 0 on the argument 

i would like just to write

F(5, 5) and the equation should understand that Z is missing so just do x * y

 

hope you could help me

 

 

ACCEPTED SOLUTION

Accepted Solutions
Werner_E
25-Diamond I
(To:EP_10906526)


@EP_10906526 wrote:

thanks Werner!

what about the usage of IsNaN, could somehow be useful? 

i read somewhere that this function could be used, but looking at the MAthcad tutoreal dont really understand  how is it used. 


NaN is a special numerical data type.

You may assign a variable the "value" NaN and any calculation using this variable would again yield NaN. You cannot ask something like "if x=NaN ..." but rather use "if IsNaN(x) ..."

 

If you define a function with n formal arguments in Prime you must use the exact number n of current arguments when you call the function. Of course you could use zeros or NaN as arguments when you call the function and the function that way can decide to use them or a default value. But you can't omit an argument.

 

As far as I am aware using a vector argument similar to the way shown above seems to be the only workaround which enables you to provide less arguments without having to fill the missing arguments with zeros, NaNs, special strings, etc. when calling the function,
The vector is just one argument and the program can determine how many elements it contains.

View solution in original post

3 REPLIES 3
Werner_E
25-Diamond I
(To:EP_10906526)

Its not an equation what you are talking about but rather a function!

Unfortunately user-defined functions in Prime are not allowed to have a variable number of arguments/optional arguments.

Usual way around this restriction is to write a function with just one argument which is a vector. The function can then determine the number of elements in this vector and can act accordingly.

In your example y and z default both to 1 if no argument is given, so you could use

Werner_E_0-1743019062007.png

It would be slightly more work if the default values for y and would not be the same.

You can use this function now that way:

Werner_E_1-1743019156494.png

 

Of course your specific example could also be written using the product operator

Werner_E_2-1743019255026.png

 

 

thanks Werner!

what about the usage of IsNaN, could somehow be useful? 

i read somewhere that this function could be used, but looking at the MAthcad tutoreal dont really understand  how is it used. 

Werner_E
25-Diamond I
(To:EP_10906526)


@EP_10906526 wrote:

thanks Werner!

what about the usage of IsNaN, could somehow be useful? 

i read somewhere that this function could be used, but looking at the MAthcad tutoreal dont really understand  how is it used. 


NaN is a special numerical data type.

You may assign a variable the "value" NaN and any calculation using this variable would again yield NaN. You cannot ask something like "if x=NaN ..." but rather use "if IsNaN(x) ..."

 

If you define a function with n formal arguments in Prime you must use the exact number n of current arguments when you call the function. Of course you could use zeros or NaN as arguments when you call the function and the function that way can decide to use them or a default value. But you can't omit an argument.

 

As far as I am aware using a vector argument similar to the way shown above seems to be the only workaround which enables you to provide less arguments without having to fill the missing arguments with zeros, NaNs, special strings, etc. when calling the function,
The vector is just one argument and the program can determine how many elements it contains.

Announcements

Top Tags