Mathematica indices as variables

AI Thread Summary
The discussion focuses on creating a matrix in Mathematica where its components are functions of an index n. The user successfully defines a matrix A with elements as sine and cosine functions of a_n and b_n, allowing for dynamic indexing. They seek to display this matrix in a specific format using MatrixForm for a particular index, such as A[4]. Additionally, they encounter an error when trying to define another matrix R, which is attributed to a conflict with Mathematica's variable assignment rules. The conversation highlights the importance of proper syntax and understanding variable protection in Mathematica.
Qubix
Messages
82
Reaction score
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.


Homework 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 ?

The Attempt at a Solution



Rather long and wrong, so better not post it here.
 
Physics news on Phys.org
Code:
A[n_] := {{Sin[a[n]], Cos[a[n]]}, {Sin[b[n]], Cos[b[n]]}}
 
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:

SetDelayed::write: "Tag List in {{p/2,0,0,p/2},{0,1-p,0,0},{0,0,0,0},{p/2,0,0,p/2}}[p_] is Protected.
 
Last edited:
It looks like you have already assigned that list to R. Try clearing the value of R and then try this again.
 

Similar threads

Back
Top