1. Not finding help here? Sign up for a free 30min 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!

Mathematica indices as variables

  1. Feb 24, 2014 #1
    1. I'll post here a simplified version of my problem

    Say you have a matrix A, and you want all its components to be functions, for example:

    A11 = Sin(a_n)
    A12 = Cos(a_n)
    A21 = Sin(b_n)
    A22 = Cos(b_n)

    And I want to be able to do this in mathematica so as to have the matrix A a function of n.


    2. Relevant equations

    How can I do this, such that when I ask

    MatrixForm[A[4]] for example, it would give me the matrix with all components in terms of a_4 and b_4 ?

    3. The attempt at a solution

    Rather long and wrong, so better not post it here.
     
  2. jcsd
  3. Feb 24, 2014 #2

    DrClaude

    User Avatar

    Staff: Mentor

    Code (Text):
    A[n_] := {{Sin[a[n]], Cos[a[n]]}, {Sin[b[n]], Cos[b[n]]}}
     
  4. Feb 25, 2014 #3
    Thanks for that DrClaude, it worked :)

    PS:

    Why won't Mathematica allow me to write:

    (R[p_] := {{p/2, 0, 0, p/2}, {0, 1 - p, 0, 0}, {0, 0, 0, 0}, {p/2, 0, 0, p/2}}) // MatrixForm

    It gives the error:

     
    Last edited: Feb 25, 2014
  5. Feb 25, 2014 #4
    It looks like you have already assigned that list to R. Try clearing the value of R and then try this again.
     
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: Mathematica indices as variables
  1. Material Indices (Replies: 0)

Loading...