Missing argument of a function
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
Missing argument of a function
Hello
i have an equation. lets say
but if i have less arguments i want to do a different operation, lets say:
(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
Solved! Go to Solution.
- Labels:
-
Mathcad Usage
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
@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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
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
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:
Of course your specific example could also be written using the product operator
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
@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.
