1. Limited time only! Sign up for a free 30min personal tutor trial with Chegg Tutors
    Dismiss Notice
Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Defining variables in mathematica

  1. Mar 28, 2014 #1
    I need to define some "general" variables in Mathematica 8, and I wonder if this can be done the following way.

    Say ta[n] and tb[m] are my variables, in turn depending on n and m.

    I want to define a function, for example

    E[ta[n]_ , tb[m]_ ] := Cos[ ta[n] ] + Sin [tb[m] ] (just a simple example).

    Then I want to be able to use the above expression in yet another function

    S := E[ta[1],tb[2]] + E[ta[3],tb[1]] + etc...

    First of all, does this work in Mathematica ?

    Second, is S also a function, for example, if the line would stop before etc, should i write it as

    S[ta[1]_ , tb[2]_, ta[3]_, tb[1]_ ]?

    Remember, ta[1] , ta[2] etc are different variables.

    I am asking all this because it would save me a serious amount of time in writing everything down explicitly.
  2. jcsd
  3. Mar 28, 2014 #2
    First, E is defined to be Euler's constant. Trying to use that name for something else is a path to grief.
    Second, trying to use function names, like ta[1]_ as a name of a parameter in a function definition is going to be another path to grief. But just writing x_ and y_ should work for you.
    This works

    In[1]:= e[x_, y_] := Cos[x] + Sin[y] ;
    e[ta[1], tb[2]] + e[ta[3], tb[1]]

    Out[2]= Cos[ta[1]] + Cos[ta[3]] + Sin[tb[1]] + Sin[tb[2]]

    If you could clearly explain what your real problem is then there might be a simpler way for you to get there.
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Have something to add?
Draft saved Draft deleted

Similar Discussions: Defining variables in mathematica
  1. Mathematica problem (Replies: 1)

  2. Learning Mathematica. (Replies: 7)

  3. Mathematica question (Replies: 2)