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!

Homework Help: 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


    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 :)


    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.
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook

Have something to add?
Draft saved Draft deleted