Skip to main content
1-Visitor
May 18, 2012
Question

Adding an integer to each value in a vector

  • May 18, 2012
  • 2 replies
  • 6243 views

I have a lengthy function that basically boils down to adding an integer to each value in a vector and for some reason I cannot figure out how to get it to work.

For example, I have the integer, X, and the vector A. A has values from 0 to 4

How do I get it to add X to each value of A to output a vector of A (X+0, X+1, X+2, X+3, X+4)?

if the range variable for A goes like: for k = 0....4

would it not be something like X + a (k,0)?

Thanks

2 replies

23-Emerald V
May 18, 2012

James Spencer wrote:

I have a lengthy function that basically boils down to adding an integer to each value in a vector and for some reason I cannot figure out how to get it to work.

For example, I have the integer, X, and the vector A. A has values from 0 to 4

How do I get it to add X to each value of A to output a vector of A (X+0, X+1, X+2, X+3, X+4)?

if the range variable for A goes like: for k = 0....4

would it not be something like X + a (k,0)?

Thanks

I suspect I might not have understood your problem, as I also suspect the answer is simply A+X.

Stuart

1-Visitor
May 18, 2012

Thanks for the reply!

When I do that, I do not get values back, I get [1,5] for each value in the vector

19-Tanzanite
May 18, 2012

Could you post a worksheet. It's hard to figure out what you are doing wrong without seeing it (because, as Stuart says, all you need is A+X).

1-Visitor
May 18, 2012

It is hard to know what exactly you want without an actual mathcad file, but from what you describe it seems like Stuart gave the correct answer. See the attached file.

1-Visitor
May 18, 2012

Attached is an edited version of what i was trying to do. If anyone is brave enough to sift through this mess, i highlighted text areas with questions and where i want to add my function to an equation. It essentially calculates the elevation at any point along a curve, then calculates elevations at calculated points along that curve and puts them in a matrix . If you took a cross section of that point, there are 5 places laterally from that point i want elevations at. they would all be the same if it was flat, but its not, the points laterally from any spot vary up or down, and thats where i cant get it to work. You can see from my first attempt, the 5 values below the location are all the same.

Im not expecting anyone to figure this out and its hard to explain, but here it is anyways.

thanks

23-Emerald V
May 18, 2012

James Spencer wrote:

Attached is an edited version of what i was trying to do. If anyone is brave enough to sift through this mess, i highlighted text areas with questions and where i want to add my function to an equation. It essentially calculates the elevation at any point along a curve, then calculates elevations at calculated points along that curve and puts them in a matrix . If you took a cross section of that point, there are 5 places laterally from that point i want elevations at. they would all be the same if it was flat, but its not, the points laterally from any spot vary up or down, and thats where i cant get it to work. You can see from my first attempt, the 5 values below the location are all the same.

Im not expecting anyone to figure this out and its hard to explain, but here it is anyways.

thanks

James,

Provided I've understood your worksheet, you don't appear to need the inner k-loop. Just get rid of it, bringing everything back out into the i- and j-loops and replace the k index in xsloc with an i. Your k-loop calculates a new q value for each iteration of k, ending up with adding the last value of xsloc.

Stuart