Skip to main content
1-Visitor
Solved

Program to perform summation on an array

I wrote and attached a basic worksheet to demonstrate what I am trying to achieve. I can get the solution by defining each part one-by-one like you will see on the attached sheet, but that is going to be too tedious on my main worksheet. A program or other built in function would be ideal. 

 

Thanks in advance for the help. 

Werner_E
Werner_EAnswer
25-Diamond I

Here are a few suggestions for functions to do the job.

On contrary to Stuart recursive function, none of them will deal with a scalar as argument and the last two fail if the argument vector has just one element. Would need to throw in an "if" to deal with that situation if necessary.

Werner_E_0-1650224279971.png

 

 

5 replies

23-Emerald V

My trial period for Mathcad Prime 8 has just run out, so I can't demonstrate a programmed version, but here's a version that should run in most versions of Mathcad (this was written in Mathcad Express 7).   It uses range variables.

 

2022 04 17 b.png

 

Stuart

Translate
23-Emerald V

And here's one possible (recursive) functional solution ...

 

2022 04 17 c.png

 

This function will return a vector even if its argument is a scalar.

 

Stuart

Translate
23-Emerald V

Here's one approach. Should work for any length vector >0  and with any value of ORIGIN.

 

Success!
Luc

Translate
Werner_E
Werner_E25-Diamond IAnswer
25-Diamond I

Here are a few suggestions for functions to do the job.

On contrary to Stuart recursive function, none of them will deal with a scalar as argument and the last two fail if the argument vector has just one element. Would need to throw in an "if" to deal with that situation if necessary.

Werner_E_0-1650224279971.png

 

 

Translate
1-Visitor

Thank you everyone for the help! I tried lots of different things on my end and I did not know to use the "last(v)" in there as part of the sum. That's new to me, so thank you for that as well. A couple of these solutions will work for me, and I will be able to use some of this new info on other things I will have to code later. 

 

Andrew

Translate