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
Hi,
I am working with Mathcad and want to create a function to calculate the parallel resistance of n resistors. Therefore I would need a function that would accept n arguments.
Currently I have separate functions defined for 2 elements, 3 elements, and 4 elements:
Is there any way to define a function that would evaluate this expression for n elements?
Thanks
Solved! Go to Solution.
Sorry, but it is not possible to create user defined functions that take a variable number of arguments (even though there are built-in functions that take a variable number of arguments). It's one of a long list of long-standing requests. The best (perhaps even only!) thing you can do is what Vladmir shows. That can be simplified a little too:
Hello!
Please attach your Mathcad worksheet.
I'd rather not upload the entire worksheet, so I've posted an image of the relevant formulas.
Functions for 2, 3, and 4 elements:
Sorry, but it is not possible to create user defined functions that take a variable number of arguments (even though there are built-in functions that take a variable number of arguments). It's one of a long list of long-standing requests. The best (perhaps even only!) thing you can do is what Vladmir shows. That can be simplified a little too:
May be so:
Yes, including ORIGIN is a very good idea! Necessary, in fact, because I always use ORIGIN=0, and my version of the function would in fact not work correctly in any of my own worksheets
Thanks everyone for the quick replies! I think Vladimir's method will allow me to clean things up and make my calculations easier to visualize.
You're welcome.
Richard Jackson wrote:
Yes, including ORIGIN is a very good idea! Necessary, in fact, because I always use ORIGIN=0, and my version of the function would in fact not work correctly in any of my own worksheets
I know that in Europe and in Russia we have in vectors 1-st, 2-d etc elements (ORIGIN=1)
But I heard that in USA - 0-?, 1-st, 2-d etc elements (ORIGIN=0).
Is it true?
Most people here would not call the first element the 0-th, they would call it the 1-st, just as in Europe or Russia.
Richard Jackson wrote:
Most people here would not call the first element the 0-th, they would call it the 1-st, just as in Europe or Russia.
Thanks!
And why is the default that ORIGIN=0
Valery Ochkov wrote:
And why is the default that ORIGIN=0
VladimirN. wrote:
Valery Ochkov wrote:
And why is the default that ORIGIN=0
Sorry, it is not answer.
And why is the default that ORIGIN=0
We have discussed this before, but I can't find the thread (I can almost never find the thread I want in these forums!). Here's the best answer I have seen though: http://developeronline.blogspot.com/2008/04/why-array-index-should-start-from-0.html
We can have in some built-in function of Mathcad 15 (find, min, max, stack etc) n-arguments.
One example max(1, 2, 3, 4, 5, 6...) = ...
The max n is 50 (n = 1-50)
Do you know how much max arguments can we have in same functions in Mathcad Prime? I know more than 50 or 256.
Do you have a full list of this functions with var n of arguments?