How to define functions with integer index in mathematica

Click For Summary
SUMMARY

This discussion focuses on defining functions with integer indices in Mathematica, specifically for vector and tensor equations. Users can create vectors using lists, such as v = {a,b,c}, and define functional vectors like v[t_] := {Sin[t], 2t}. Matrix operations are performed using dot products, and tensor manipulations can be achieved through the Table function to generate higher-dimensional arrays. The discussion also touches on solving differential equations with explicit indices, exemplified by the equation v_i'(t) + b_i ∇ · v(t) = s_i.

PREREQUISITES
  • Familiarity with Mathematica syntax and functions
  • Understanding of vector and tensor algebra
  • Knowledge of differential equations and their representations
  • Basic experience with matrix operations in programming
NEXT STEPS
  • Explore Mathematica's tensor manipulation packages for advanced operations
  • Learn about defining and solving differential equations in Mathematica
  • Research the use of the Table function for generating multi-dimensional arrays
  • Investigate the implementation of numerical solutions for tensor equations in Mathematica
USEFUL FOR

Mathematics students, physicists, and engineers who are working with vector and tensor equations in Mathematica, as well as anyone interested in numerical and analytical solutions within this software environment.

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
5K
  • · Replies 1 ·
Replies
1
Views
4K
  • · Replies 1 ·
Replies
1
Views
2K