Skip to main content
1-Visitor
April 17, 2022
Solved

Program to perform summation on an array

  • April 17, 2022
  • 3 replies
  • 2223 views

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. 

Best answer by Werner_E

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

 

 

3 replies

23-Emerald V
April 17, 2022

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

23-Emerald V
April 17, 2022

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

23-Emerald IV
April 17, 2022

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

 

Success!
Luc

Werner_E25-Diamond IAnswer
25-Diamond I
April 17, 2022

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

 

 

1-Visitor
April 18, 2022

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