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

Community Tip - You can subscribe to a forum, label or individual post and receive email notifications when someone posts a new topic or reply. Learn more! X

Own functions

MikeArmstrong
12-Amethyst

Own functions

I am trying to write my own summation function.

When summating matrixes using the Mathcad built-in vector sum function, it really drives me nuts the way a matrix has to be inserted for each of the inputs.

So I have changed the function (see attached sheet) so a comma can be used to separate the inputs so there is no need for a matrix.

Right, in the sheet attached I have used 2 inputs, a & b. If I want to include a third input say c, could the defined function be programmed so it automatically accepts the number of inputs?

See attached sheet.


Regards

Mike
18 REPLIES 18

Frankly, there is nothing to understand in your sheet.

jmG

I have tried to write my own summation so the insertion of a matrix is not required.

The first sheet was a simplified version of what I was trying to achieve, I have now attached the working sheet.

Regards

Mike

User defined functions with a variable number of arguments are not allowed.

Why are you using the function anyway? You are just adding two scalars, so your function acts the same as +. Why not just write a[i<-a[i+b[i, or a[i<-a[i+b[i+c[i in the programs?

Richard

You just have a dead link instead of a data table. Nothing to do with your work sheet. Always try to convey your idea via manual demo

jmG

... Select the rows/cols you want from your data table and apply the module below. It should do something in the taste you want. If not, do a demo in manual mode, as best as you can. If you can do in Excel, no problem in Mathcad.

jmG

You work too hard. There is no need for the for loop, nor for a user defined summation function. Normal vector operations (scalar multiplication and addition) do the job just fine. If yu have a third column, you just add another +.
__________________
� � � � Tom Gutman

Cheers Tom.

I was just having a bad day. Your right no need complicate matters just keep it simple cheers for the help.

Regards

Mike

On 10/24/2009 3:00:45 AM, Armo wrote:
>I was just having a bad day.
>Your right no need complicate
>matters just keep it simple
>cheers for the help.

Depends on your point of view, of course, but you could simplify and generalize the problem (provided I've understood it), by using aggregating functions.

Stuart

Stuart that is class.

Will take a little time to understand how I will utilize those new functions, but will definitely help in the future.

Cheers for your time


Cheers for your time

Regards

Mike

>...(provided I've understood it)...< [Stuart]
________________________

On my side, I understood nothing by reading !
Quite a monkey business XX(1538) ! My module works Excel style, much simpler. Could you not have demonstrated in manual mode ?

jmG

jmG

I couldn't understand the worksheet you posted with the additional functions.

I tried to explain the best I could, the only reason I could understand what Stuart posted was because of the example he posted with the annotation.

I'm not to sure what you mean by manual mode.

Regards

Mike

>I'm not to sure what you mean by manual mode.<<br> ___________________________

You have a data table, what do you want to do or process ? You must describe in words, and by manually doing something like taking a 3 x 3 section and construct your words, like showing a diagonal, an inverse diagonal, sum the first col and the last col. Certainly what you see in your mind surely does not go as fast as the light, then capture and lay on paper.

jmG

ok. Get ya.

Regards

Mike

I don't understand your problem. Given your data, what is the problem with just writing a+b and a+b+c?
__________________
� � � � Tom Gutman

Is this a confusion between two different
summation capabilities.

The first entry asks, if I read it right, for the
summation across a whole matrix, rather than a
vector.

The rest of the tread suggests the user then got
slightly confused with his example, leading to
further misunderstanding.

I often want the sum of a whole matrix
:= mean(M)*rows(M)*cols(M)

and would just like to use the Sigma sign.
This produces the error message "This value must
be a vector" for the summand.

I'll see if I can get it added to the Cpp Array
Handling routines being developed (radair; myself;
Xavier Colonna).

Philip Oakley

Cheers guys, think i got a little lost with what i was trying to achieve, cheers for the quick responses.

Regards

Mike

>...think i got a little lost with what i was trying to achieve <.
____________________________

That's what I was trying to make you understand: you don't master Mathcad well enough to plug something that you have advanced but all scrap. Then make it simple manually so by reading any one can understand what you are after. You had two vectors to stack, I did ... you can stack +++. But if you go by stack(,,,,), that is very inefficient. Instead, use a little program but index your individual vectors (green). You can do + and make a selection with a "ForLoopSelect" (not shown).

You got lost because you don't express what you want. Is it too much saying (for instance)" I have 10 vectors of different length each, I would like to stack them in a single resulting vector".

jmG


Understand now.

Regards

Mike
Announcements

Top Tags