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

Community Tip - Need help navigating or using the PTC Community? Contact the community team. X

Program to perform summation on an array

AS_10137793
2-Explorer

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. 

ACCEPTED SOLUTION

Accepted Solutions
Werner_E
25-Diamond I
(To:AS_10137793)

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

 

 

View solution in original post

5 REPLIES 5
StuartBruff
23-Emerald III
(To:AS_10137793)

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

StuartBruff
23-Emerald III
(To:StuartBruff)

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

LucMeekes
23-Emerald III
(To:AS_10137793)

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

 

Success!
Luc

Werner_E
25-Diamond I
(To:AS_10137793)

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

 

 

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

Announcements

Top Tags