I have two vectors, $\bar{x},\bar{v}$ and I want to produce a third vector such that:$$ u_i = \int_{x_i}^{x_i+\delta} f(v_i,t)dt \ .$$ I tried (with a simple function for example):

Integrate[v*(Cos[w*n*t]), {t, x, x +D} ]

but this ends up returning a matrix$$ u_{ij} = \int_{x_i}^{x_i+\delta}f(v_j,t)dt \ .$$ How do I make it so the index of the two vectors is the same? Essentially I want the diagonal of this matrix, but calculating the entire matrix and then taking the diagonal is computationally very slow as the matrix is large. I also tried defining a function

F[i_] = Integrate[Index[v,i]*(Cos[w*n*t]), {t, Index[x,i], Index[x,i] +D} ]

(I could not access vector elements in the function definition using x[[i]]) but this does not evaluate when I enter say F[1].


1 Answer 1


Here is a simple example with a particular x and v and f:

v = {1, 2, 3}; x = {4, 5, 6}; 
f[v_, t_] := Cos[v + t]; 
Table[Integrate[f[v[[i]], t], {t, x[[i]], x[[i]] + d}], {i, Length[x]}]

This returns three components. Alternately you can bypass the use of Table:

Integrate[f[v[[#]], t], {t, x[[#]], x[[#]] + d}] & /@ Range[Length[x]]

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.