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

Community Tip - Stay updated on what is happening on the PTC Community by subscribing to PTC Community Announcements. X

For Loops

MikeArmstrong
12-Amethyst

For Loops

The attached sheet calculates the cumulative length of the pipe strings correctly. I have tried to put this into function (generally for ascetic reasons) and keep getting the first element of the answer as zero.

Can someone please point out why this is occurring, has it got something to do with the defined range inside the loop?

Regards

Mike
16 REPLIES 16

On 11/23/2009 6:10:32 AM, Armo wrote:
>The attached sheet calculates
>the cumulative length of the
>pipe strings correctly. I have
>tried to put this into
>function (generally for
>ascetic reasons) and keep
>getting the first element of
>the answer as zero.

Can
>someone please point out why
>this is occurring, has it got
>something to do with the
>defined range inside the
>loop?

Regards

Mike
_____________________________

Will look later on, but yes the first element is 0. because 0*whatever = 0, you are saying "cumulative", like cumulative integral. Maybe your project is not "cumulatively cumulative" ?

jmG



... in fact, the matter is not "cumulative integral",
just "cumulative sum", then as simple as that !



jmG

On 11/23/2009 6:10:32 AM, Armo wrote:
== The attached sheet calculates the cumulative length of the pipe strings correct. I have tried to put this into function (generally for ascetic reasons) and keep getting the first element of the answer as zero.
== Can someone please point out why this is occurring, has it got something to do with the defined range inside the loop?

You get zero because you have initialized the first element of the vector to zero.

You only *appear* to get the correct result with the range variable approach because you are seeing the result of each individual evaluation of c (which runs from 1). If you display cumstring (rather than cumstringc) then you should note that the zero is still there.

Get rid of the pesky zero by either a submatrix/subvector function of alter the way the accumulation is done (start of with first length rather than zero)

Stuart

Cheers I'll give it a try now and post my results.

Regards

Mike

SUCCESS cheers Stuart.

See attahced.

Regards

Mike

On 11/23/2009 7:00:50 AM, Armo wrote:
>SUCCESS cheers Stuart.
>
>See attahced.
>
>Regards
>
>Mike
_____________________

For loop for what, for what for ?

My construct can't be shorter can't be more explicit can't be more logical. No for loop, would work as low as at least Mathcad 5.0.

jmG



... to make it clear for both end use:



jmG
StuartBruff
23-Emerald III
(To:ptc-1368288)

On 11/23/2009 7:34:47 AM, jmG wrote:
>... to make it clear for both end use:

Mike's version is more efficient in terms of execution time than your suggestion because it accumulates the sum rather then calculating the entire sum for each element. It won't make much difference for a small data set like String, but could have a signficant impact for larger vectors or more executions.

Stuart

Quite correct that the seeded version is much faster. Well known to me as it was explored at the very early beginning of the collab, and supplemented by the "Advisor". The seeded style is my basis style. One more of those little utility functions that deserve to be built-in. So many little +'s would help Mathcad.



jmG

I have just noticed that the above function cannot handle units unlike the version I wrote.

Regards

Mike

On 11/23/2009 10:19:17 AM, Armo wrote:
>I have just noticed that the above
>function cannot handle units unlike the
>version I wrote.
>
>Regards
>
>Mike
_____________________________

It does handle units for me in demo,

It does handle units in your work sheet.

What do you mean "it does not handle units" ?

jmG


Sorry it was me making the mistake.

Regards

Mike

... it handles units in your work sheet, proof.

jmG

Once again excellent explenation of functions and use.

Cheers for the help / advice

Regards

Mike

Your work sheet made work for 11 version.

jmG

jmG

Cheers for the advice, once again it can be seen that there is more than one way to skin a cat.

Regards

Mike
Announcements

Top Tags