Quantcast
Channel: PTC Community: Message List
Viewing all articles
Browse latest Browse all 11979

Re: Vector less or bigger than

$
0
0

Fredrik Jacobsen wrote:

 

Thank you, Alan!

 

That's perfect!

 

Some questions. Sorry if this should be obvious.

 

Can you explain the program step by step?

 

The things I'm wondering about are these:

 

1. Why start the program defining p as zero?

 

p is an index to positions in the vector d3 which will contain the items of d when d>a.  Mathcad starts counting at zero, so I set it to zero to start.  After it has been used it is incremented by 1.  (You could start it at -1 and then, when you need to use it, increment it before assigning a value to that position in d3 etc.).

 

 

2. I'm not getting the grip with what is happening after the if statement with d3[p

Within the if statement there are two assignments.  The first assigns the k'th value of d (corresponding to a non-zero value in d>a ) to the p'th position in d3.  The second assignment then increments p by 1, ready for the next non-zero assignment to the next position in d3.  p only increments when a non-zero value has been observed in d>a.

 

The final statement of the program simply returns the whole vector of values that have been stored in d3.

 

Alan


Viewing all articles
Browse latest Browse all 11979

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>