I'm doing a presentation and I have to include this in it:

for j in 1..j_max
    b_offset = copy(b)
    b_offset[j] = b_offset[j] + 1

I can't do b_offset = b + 1, but I don't know how else to describe that just the jth index should increase by one.

  • $\begingroup$ Just keep in mind that if you are too concise you risk confusing your audience. $\endgroup$ – chazisop Apr 13 '11 at 3:51
  • $\begingroup$ I'll explain what it means too. $\endgroup$ – user9525 Apr 13 '11 at 4:10
  • $\begingroup$ Can you give a small example? Even though at this point you've accepted an answer, it is unclear what it is you want. The code you give doesn't seem to match the words '...just the $j$th index should increase by 1.". Why wouldn't you just say b[j] = b[j]+1, without all the looping? $\endgroup$ – Mitch Apr 13 '11 at 13:58

Treating them as vectors, you could say

$$\mathbf{b\_offset} = \mathbf{b} + \mathbf{e_j}$$

where $\displaystyle \mathbf{e_j}$ is the unit vector with all zeroes except the $j^{th}$ co-ordinate.

  • $\begingroup$ That's not what I'm doing. It isn't a vector of ones. Only the kth element is one, so it would be something like [0, 0, 0, 0, 0, 1, 0, 0, 0], for example. $\endgroup$ – user9525 Apr 13 '11 at 3:49
  • $\begingroup$ @mr banana : See edit. I believe $e_j$ is standard notation. $\endgroup$ – Aryabhata Apr 13 '11 at 4:01
  • $\begingroup$ Not that I don't believe you, but could you tell me why is it e_j? I thought it would be something like 1_j. But thanks anyway. $\endgroup$ – user9525 Apr 13 '11 at 4:05
  • $\begingroup$ @mr banana: I am not sure. Perhaps for Euclidean. See this: jeff560.tripod.com/matrices.html under section for Symbols for Vectors. The wiki pages en.wikipedia.org/wiki/Euclidean_vector and en.wikipedia.org/wiki/Unit_vector seem to be using it too. $\endgroup$ – Aryabhata Apr 13 '11 at 4:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy