# How to define functions with integer index in mathematica

• Mathematica
There is a vector ##v_i(t)## (i=1,2,3). How to define the three functions in Mathematica? What about ##t_{ij}(t,\vec{x})##?
I am trying to solve my vector and tensor equtions with Mathematica. Analytical solution would be perfect but numerical solution would also be fine. Actually I am not even sure whether Mathematica can deal with tensor equtions. Any help would be appreciated.

Hepth
Gold Member
I apologize for formatting, im on a horrible netbook.

In mathematica arrays vectors etc are all just lists/tables. This means you can have a vector :

v = {a,b,c}

or a functional vector

v[t_]:= {Sin[t],2t} for a two component vector

to access a single object you would do something like

v[t][[2]] for 2t

this can be extended to matrices and higher rank tensors.

mat = {{0,a},{-b,0}}

mat[[i,j]] will give you the i,j 'th positions

you can then do matrix algebra:

mat.v[t]

using "." as a dot product meaning Sum over j, mat[[i,j]] v[[j]]

same with squaring things v[t].v[t]

You can also use vectors with Solve.

Solve[mat.v[t] == {x, y}, {a, b}]

gives {{a -> x/(2 t), b -> -y Csc[t]}}

There are also tensor manipulation packages, but if your equations are well behaved and known you can probably just use Table to generate it.

TENS = Table[a+b+c,{a,0,2},{b,0,2},{c,0,2}]

Will give a rank 3 tensor of 3x3x3 dimension with entries that are just the sum of the indices.

So you could pull an entry: TENS[[1,1,2]]
Or pull a vector TENS[[1,1]]
or a matrix TENS[[1]]

You can take the first two matrices in it : TENS[[1;;2]]

And so forth. TENS[[1;;2]] means from entry 1 to entry 2.

Thanks a lot for your help!
Can we keep the index explicitly in the differential equations. For instance, how to solve ##v_i(t)## in ##v_i'(t)+b_i \nabla \cdot \vec{v}(t)= s_i## where ##b## and ##s_i## are constants.