Mathematica How to define functions with integer index in mathematica

Click For Summary
In Mathematica, vectors and tensors can be defined as lists or tables, allowing for flexible manipulation. For a vector, you can define it as v[t_] := {Sin[t], 2t}, and access its components using indexing. Matrix operations, such as dot products, can be performed using the dot operator, enabling solutions to equations like mat.v[t] == {x, y}. Tensor manipulations can be managed with the Table function to create higher-dimensional arrays, and specific entries can be accessed with indexing. The discussion also highlights the possibility of keeping indices in differential equations, such as solving for v_i(t) in the context of a differential equation involving gradients.
karlzr
Messages
129
Reaction score
2
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.
 
Physics news on Phys.org
I apologize for formatting, I am 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.
 

Similar threads

  • · Replies 4 ·
Replies
4
Views
3K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 4 ·
Replies
4
Views
3K
  • · Replies 3 ·
Replies
3
Views
28K
  • · Replies 6 ·
Replies
6
Views
4K
  • · Replies 1 ·
Replies
1
Views
4K
  • · Replies 1 ·
Replies
1
Views
2K