How to define functions with integer index in mathematica

In summary: The answer is yes, you can keep the index explicitly. For example, to solve the differential equationv_i'(t)+b_i \nabla \cdot \vec{v}(t)=s_iyou can dosolve[v_i'(t)+b_i \nabla \cdot \vec{v}(t)==s_i,{a,b}]
  • #1
karlzr
131
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
  • #2
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.
 
  • #3
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.
 

1. What is the syntax for defining a function with an integer index in Mathematica?

The syntax for defining a function with an integer index in Mathematica is: functionName[i_Integer]:= function definition. This creates a function called functionName that takes an integer index i as an argument and defines the function's behavior.

2. Can a function with an integer index in Mathematica be defined using a loop?

Yes, a function with an integer index in Mathematica can be defined using a loop. The loop can be used to iterate through the integer indices and define the function's behavior for each index.

3. How can I specify the range of the integer index in a function definition in Mathematica?

The range of the integer index in a function definition can be specified using the Table command. For example, functionName[i_Integer]:= Table[function definition, {i, 1, 10}] will define the function for integer indices from 1 to 10.

4. Can a function with an integer index in Mathematica return multiple values?

Yes, a function with an integer index in Mathematica can return multiple values. This can be achieved by using the Return command within the function definition. For example, functionName[i_Integer]:= Return[{value1, value2, value3}, {i, 1, 10}] will return three values for each integer index from 1 to 10.

5. How can I use a function with an integer index in a Mathematica plot?

To use a function with an integer index in a Mathematica plot, you can use the Table command to create a list of values for the function and then use the ListPlot command to plot the values. For example, ListPlot[Table[functionName[i], {i, 1, 10}]] will plot the values of the function for integer indices from 1 to 10.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
407
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
6
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
3K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
26K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
3K
Back
Top