Mathematica indices as variables

Click For Summary

Discussion Overview

The discussion revolves around using Mathematica to define matrices with components as functions of an index variable, specifically focusing on how to properly format these definitions and resolve errors encountered during implementation.

Discussion Character

  • Homework-related, Technical explanation

Main Points Raised

  • One participant presents a problem involving defining a matrix A with components as functions of an index n, seeking a method to display the matrix in terms of specific indexed variables.
  • Another participant provides a solution by suggesting a function definition for A[n_] that correctly formats the matrix with sine and cosine functions of a[n] and b[n].
  • A participant expresses gratitude for the solution and raises a new issue regarding an error encountered when trying to define another matrix R with a parameter p, questioning why Mathematica does not allow the definition as intended.
  • A later reply suggests that the error may be due to a previous assignment to R, recommending that the participant clear the value of R before attempting the definition again.

Areas of Agreement / Disagreement

Participants appear to agree on the solution for defining matrix A, but there is an unresolved issue regarding the error with matrix R, with differing views on the cause of the problem.

Contextual Notes

The discussion includes assumptions about the behavior of Mathematica functions and the implications of variable assignments, which may not be fully explored or clarified.

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

  • · Replies 1 ·
Replies
1
Views
2K
Replies
1
Views
1K
  • · Replies 13 ·
Replies
13
Views
2K
  • · Replies 6 ·
Replies
6
Views
4K
  • · Replies 6 ·
Replies
6
Views
2K
  • · Replies 4 ·
Replies
4
Views
3K
  • · Replies 2 ·
Replies
2
Views
1K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 37 ·
2
Replies
37
Views
6K