Community Tip - Did you get called away in the middle of writing a post? Don't worry you can find your unfinished post later in the Drafts section of your profile page. X
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
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
Thanks for the reply!
When I do that, I do not get values back, I get [1,5] for each value in the vector
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).
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.
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 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
You beat me by 3 minutes
You still have X[i,j though
Richard Jackson wrote:
You beat me by 3 minutes
You still have X[i,j though
I have a policy of leaving a few scraps to others so that they may share in my glory. (what I really want is an emoticon for Aloof Patronizing Indulging of the Lower Classes ... why is there never an emoticon that says what I want?)
Actually, I only had a couple of minutes to spare and was somewhat surprised to pick up on the k-loop immediately. I had to go and have a stiff drink to recover from the shock. Now, where wazh eye ... ?
I have a policy of leaving a few scraps to others so that they may share in my glory. (what I really want is an emoticon for Aloof Patronizing Indulging of the Lower Classes ... why is there never an emoticon that says what I want?)
Best I can come up with:
My response:
(I had an alternative to that, but it might have got me banned)
This is it, wow, I shouldve seen that, it didnt take any of you long, haha.
Amazing you guys were able to figure that out so quickly, thanks a ton!
It's not 100% clear to me what you are trying to do, but I think this is it. A couple of things:
1) You calculate X[i,j, but you only ever use the current element. You can just calculate X, a scalar.
2) Your inner loop, with k as the loop variable, contains everything. Therefore for each value of i and j the inner loop executes 5 times, for each k, but each time round it just overwrites the previous results. For example, take i=1, j=1. For each k it calculates a new q[1,1, but the result for k=4, being the last one calculated, just overwrites all the others. You don't even want that inner loop. The row vector returned by the function should be indexed using i.